Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yocto Bitbake Recipe How To Override do_install() and do_install_append()

I am trying to add the open source "procps" package to my working Yocto build. This package installs a bunch of binaries that replace those provided by BusyBox. I only want one of these binaries - pgrep.

In my layer I created a bbappend file named "procps_%bbappend". It is picked up by the build, compiles successfully, but then fails on the install. The error messages seem to indicate that the do_install() and do_install_append() hooks are not overridden completely.

How can I change my bitbake bbappend file to only install the pgrep utility and none of the other standard installs from the "procps" package?

Here is my bbappend file that fails:

do_install () {
    install -d ${D}${base_bindir}
    mv ${D}/../build/pgrep ${D}/bin/pgrep
}

do_install_append () {
    install -d ${D}${base_bindir}
    mv ${D}/../build/pgrep ${D}/bin/pgrep
}

bindir_progs = ""
base_bindir_progs = ""
base_sbindir_progs = ""

Here is the entire "procps" bitbake recipe:

SUMMARY = "System and process monitoring utilities"
DESCRIPTION = "Procps contains a set of system utilities that provide system information about processes using \
the /proc filesystem. The package includes the programs ps, top, vmstat, w, kill, and skill."
HOMEPAGE = "https://gitorious.org/procps"
SECTION = "base"
LICENSE = "GPLv2+ & LGPLv2+"
LIC_FILES_CHKSUM="file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
                  file://COPYING.LIB;md5=4cf66a4984120007c9881cc871cf49db \
                 "

DEPENDS = "ncurses"

inherit autotools gettext pkgconfig update-alternatives

SRC_URI = "http://downloads.sourceforge.net/project/procps-ng/Production/procps-ng-${PV}.tar.xz \
           file://sysctl.conf \
          "

SRC_URI[md5sum] = "6cc5b94c1c5b8cbc89ad345a7b522f74"
SRC_URI[sha256sum] = "e9493169a2d2adc0bc045538707310c8e877b385e4e296143b62607d2bb044ed"

S = "${WORKDIR}/procps-ng-${PV}"

EXTRA_OECONF = "--enable-skill --disable-modern-top"

CPPFLAGS += "-I${S}"

do_install_append () {
    install -d ${D}${base_bindir}
    [ "${bindir}" != "${base_bindir}" ] && for i in ${base_bindir_progs}; do mv ${D}${bindir}/$i ${D}${base_bindir}/$i; done
    install -d ${D}${base_sbindir}
    [ "${sbindir}" != "${base_sbindir}" ] && for i in ${base_sbindir_progs}; do mv ${D}${sbindir}/$i ${D}${base_sbindir}/$i; done
        if [ "${base_sbindir}" != "${sbindir}" ]; then
                rmdir ${D}${sbindir}
        fi

        install -d ${D}${sysconfdir}
        install -m 0644 ${WORKDIR}/sysctl.conf ${D}${sysconfdir}/sysctl.conf
        if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
                install -d ${D}${sysconfdir}/sysctl.d
                ln -sf ../sysctl.conf ${D}${sysconfdir}/sysctl.d/99-sysctl.conf
        fi
}

CONFFILES_${PN} = "${sysconfdir}/sysctl.conf"

bindir_progs = "free pkill pmap pgrep pwdx skill snice top uptime"
base_bindir_progs += "kill pidof ps watch"
base_sbindir_progs += "sysctl"

ALTERNATIVE_PRIORITY = "200"

ALTERNATIVE_${PN} = "${bindir_progs} ${base_bindir_progs} ${base_sbindir_progs}"

ALTERNATIVE_${PN}-doc = "kill.1 uptime.1"
ALTERNATIVE_LINK_NAME[kill.1] = "${mandir}/man1/kill.1"
ALTERNATIVE_LINK_NAME[uptime.1] = "${mandir}/man1/uptime.1"

python __anonymous() {
    for prog in d.getVar('base_bindir_progs', True).split():
        d.setVarFlag('ALTERNATIVE_LINK_NAME', prog, '%s/%s' % (d.getVar('base_bindir', True), prog))

    for prog in d.getVar('base_sbindir_progs', True).split():
        d.setVarFlag('ALTERNATIVE_LINK_NAME', prog, '%s/%s' % (d.getVar('base_sbindir', True), prog))
}
like image 575
PhilBot Avatar asked Oct 03 '17 16:10

PhilBot


1 Answers

do_install () {
    install -d ${D}${base_bindir}
    mv ${D}/../build/pgrep ${D}/bin/pgrep
}

do_install_append () {
    install -d ${D}${base_bindir}
    mv ${D}/../build/pgrep ${D}/bin/pgrep
}

There's a few bits of confusion here:

  • You can't "override" another _append: the one in the original recipe will still be appended
  • Even if you could, your version would try to mv the same file twice (in the install and the append): that would fail. mv in general is a bad idea here: use install that's what it's for.
  • Using ${D}/../build/ is not right, you probably want ${B} instead -- but that should also be the default directory for do_install() so you shouldn't need it at all.

You could let the original do_install() do what it wants, and then remove the bits you don't want in do_install_append()... but I think modifying the package so much is not a great idea: what if another package runtime depends on procps and expects the tools you removed?

Some alternatives for you:

  • copy the recipe under a new name and just modify it
  • Let do_install be as is and in your bbappend add a new package PACKAGES =+ ${PN}-pgrep and set FILES_${PN}-pgrep = "${bindir}/pgrep": then you could install only the new tiny procps-pgrep package instead of procps. This might need some tweaking to get right because of the alternatives system procps uses...
like image 162
Jussi Kukkonen Avatar answered Oct 31 '22 00:10

Jussi Kukkonen