How to use a tool, installed on yocto build server host, from bitbake without qualifying it's full path?

412 views Asked by At

I have installed bbe, the binary block editor on my Yocto build server host. I am able to use it within my images bitbake recipe if I qualify it's full path when using it, here is a example.

BBE_BIN = "/usr/bin/bbe"

modify_foobar_file() {
    ${BBE_BIN} -e 's/Some string/New string' foobar > ${WORKDIR}/foobar.modified
}

I would like to not have to qualify the pull path everytime I use it. How can I achieve this?

Two potential solutions come to mind. In one, I imagine something similar to what I need to do to use openssl from within a recipes functions, which is to declare a build time dependency on the native openssl package, like this DEPENDS = "openssl-native". In the other, maybe I can to fiddle with bitbake environments PATH so that it can find the bbe command during the build process.

2

There are 2 answers

2
Ross Burton On BEST ANSWER

Ideally, you write a recipe to build the tool and then DEPENDS="bbe-native" where needed. This means you don't have to remember to install this tool whenever you setup a new machine, you don't need to document the tool, you get to control the upgrade cycle, and if you're making a commercial product you actually get it included in license and release manifests.

The horrible hack is to add it to HOSTTOOLS.

0
shakta On

I have implemented the accepted answer and wanted to share my work. Here is a recipe for building the latest version of bbe (0.2.2). I named it recipes-extended/bbe/bbe_0.2.2.bb.

SUMMARY = "Binary block editor"
HOMEPAGE = "https://sourceforge.net/projects/${BPN}-/"
BUGTRACKER = "https://sourceforge.net/p/${BPN}-/bugs/"
DESCRIPTION = "bbe is a sed-like editor for binary files. Instead of reading input in lines as sed, bbe reads arbitrary blocks from an input stream and performs byte-related transformations on found blocks."
LICENSE = "GPL-2.0-only"

# Calculated using md5sum command line tool and bbe's COPYING file.
LIC_FILES_CHKSUM = "file://COPYING;md5=eb723b61539feef013de476e68b5c50a"

SRC_URI = "https://sourceforge.net/projects/${BPN}-/files/${BPN}/${PV}/${BPN}-${PV}.tar.gz"

# Calculated using md5sum command line tool and the bbe archive that gets downloaded.
SRC_URI[m5d5sum] = "b056d0bfd852384aced73d4533887d4b"

# Calculated using sha256sum command line tool and the bbe archive that gets downlaoded.
SRC_URI[sha256sum] = "baaeaf5775a6d9bceb594ea100c8f45a677a0a7d07529fa573ba0842226edddb"

inherit autotools

# Enable using tool from bitbake.
BBCLASSEXTEND = "native"

And here is a demonstration using it to modify a simple hello world C application named 'chello' from a .bbappend file.

DEPENDS = "bbe-native"

APP_NAME_EDITED = "${APP_NAME}.edited"

do_edit_app() {
    bbe -e 's/Shakta/Foobar/' ${S}/${APP_NAME} > ${S}/${APP_NAME_EDITED}
}

addtask edit_app after do_compile before do_install

do_install:append() {
    install -m 0755 ${S}/${APP_NAME_EDITED} ${D}/${INSTALL_DIR}/${APP_NAME_EDITED}
}

do_deploy:append() {
    install -m 0755 ${S}/package${INSTALL_DIR}/${APP_NAME_EDITED} ${DEPLOYDIR}/${APP_NAME_EDITED}
}

FILES:${PN} += "${INSTALL_DIR}/${APP_NAME_EDITED}"

The recipe also builds bbe for the target, to use it on the target append bbe to the IMAGE_INSTALL variable.