systemd.bbclass: Clean up empty parent directories
PATCH 2/2 oeqa/selftest/bbclasses: Add tests for systemd and update-rc.d interaction
In reply to Peter KjellerstedtThese tests verify that the correct files are left behind when systemd is inherited and depending on whether the systemd and/or sysvinit distro features are enabled.
--- .../bbclasses/systemd-and-sysvinit.bb | 15 +++ .../recipes-test/bbclasses/systemd-only.bb | 10 ++ meta/lib/oeqa/selftest/cases/bbclasses.py | 106 ++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 meta-selftest/recipes-test/bbclasses/systemd-and-sysvinit.bb create mode 100644 meta-selftest/recipes-test/bbclasses/systemd-only.bb create mode 100644 meta/lib/oeqa/selftest/cases/bbclasses.py
meta-selftest/recipes-test/bbclasses/systemd-and-sysvinit.bb new file +15 -0
@@ -0,0 +1,15 @@ +LICENSE = "CLOSED" + +inherit allarch systemd update-rc.d + +do_install() { + install -d ${D}${systemd_system_unitdir} + touch ${D}${systemd_system_unitdir}/${BPN}.service + + install -d ${D}${INIT_D_DIR} + touch ${D}${INIT_D_DIR}/${BPN} +} + +INITSCRIPT_NAME = "${BPN}" + +SYSTEMD_SERVICE:${PN} = "${BPN}.service"
meta-selftest/recipes-test/bbclasses/systemd-only.bb new file +10 -0
@@ -0,0 +1,10 @@ +LICENSE = "CLOSED" + +inherit allarch systemd + +do_install() { + install -d ${D}${systemd_system_unitdir} + touch ${D}${systemd_system_unitdir}/${BPN}.service +} + +SYSTEMD_SERVICE:${PN} = "${BPN}.service"
meta/lib/oeqa/selftest/cases/bbclasses.py new file +106 -0
106 lines not on this page · raw message
PATCH 1/2 systemd.bbclass: Clean up empty parent directories
Previously, rm_systemd_unitdir() would remove one parent directory of ${systemd_unitdir} if it was empty after removing ${systemd_unitdir}. rm_sysvinit_initddir() would not remove any parent directory. Thus, if the only directory created in /etc was /etc/init.d, an empty /etc would remain after the cleanup and would be packaged.
Simplify rm_systemd_unitdir() and rm_sysvinit_initddir() by rewriting them in shell, and use rmdir -p to remove all empty parent directories.
--- meta/classes-recipe/systemd.bbclass | 46 +++++++++++++---------------- 1 file changed, 21 insertions(+), 25 deletions(-)
meta/classes-recipe/systemd.bbclass +21 -25
@@ -208,33 +208,29 @@ python systemd_populate_packages() { PACKAGESPLITFUNCS =+ "systemd_populate_packages" -python rm_systemd_unitdir (){ - import shutil - if not bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d): - systemd_unitdir = oe.path.join(d.getVar("D"), d.getVar('systemd_unitdir')) - if os.path.exists(systemd_unitdir): - shutil.rmtree(systemd_unitdir) - systemd_libdir = os.path.dirname(systemd_unitdir) - if (os.path.exists(systemd_libdir) and not os.listdir(systemd_libdir)): - os.rmdir(systemd_libdir) +rm_systemd_unitdir() { + rm -rf ${D}${systemd_unitdir} + rmdir -p $(dirname ${D}${systemd_unitdir}) 2>/dev/null || : + # Make sure ${D} still exists since rmdir -p may have removed it in + # case ${systemd_unitdir} was the only directory present. + [ -d ${D} ] || mkdir -p ${D} } -python rm_sysvinit_initddir (){ - import shutil - sysv_initddir = oe.path.join(d.getVar("D"), (d.getVar('INIT_D_DIR') or "/etc/init.d")) - - if bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d) and \ - not bb.utils.contains('DISTRO_FEATURES', 'sysvinit', True, False, d) and \ - os.path.exists(sysv_initddir): - systemd_system_unitdir = oe.path.join(d.getVar("D"), d.getVar('systemd_system_unitdir')) +rm_sysvinit_initddir() { + local sysv_initddir=${INIT_D_DIR} + : ${sysv_initddir:=${sysconfdir}/init.d} - # If systemd_system_unitdir contains anything, delete sysv_initddir - if (os.path.exists(systemd_system_unitdir) and os.listdir(systemd_system_unitdir)): - shutil.rmtree(sysv_initddir) + # If systemd_system_unitdir contains anything, delete sysv_initddir + if find ${D}${systemd_system_unitdir} -mindepth 1 -maxdepth 1 2>/dev/null | read; then + rm -rf ${D}$sysv_initddir + rmdir -p $(dirname ${D}$sysv_initddir) 2>/dev/null || : + fi } -do_install[postfuncs] += "${RMINITDIR} " -RMINITDIR:class-target = " rm_sysvinit_initddir rm_systemd_unitdir " -RMINITDIR:class-nativesdk = " rm_sysvinit_initddir rm_systemd_unitdir " -RMINITDIR = "" - +do_install[postfuncs] += "${RMINITDIR}" +RMINITDIR = " \ + ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', '', 'rm_systemd_unitdir', d)} \ + ${@'rm_sysvinit_initddir' if bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d) and \ + not bb.utils.contains('DISTRO_FEATURES', 'sysvinit', True, False, d) else ''} \ +" +RMINITDIR:class-native = ""
Re: [OE-core] [PATCH 2/2] oeqa/selftest/bbclasses: Add tests for systemd and update-rc.d interaction
In reply to Peter KjellerstedtQuoted 44 lines · Peter Kjellerstedt via lists.openembedded.org
These tests verify that the correct files are left behind when systemd is inherited and depending on whether the systemd and/or sysvinit distro features are enabled.
Signed-off-by Peter Kjellerstedt <[email protected]>--- .../bbclasses/systemd-and-sysvinit.bb | 15 +++ .../recipes-test/bbclasses/systemd-only.bb | 10 ++ meta/lib/oeqa/selftest/cases/bbclasses.py | 106 ++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 meta-selftest/recipes-test/bbclasses/ systemd-and-sysvinit.bb create mode 100644 meta-selftest/recipes-test/bbclasses/systemd-only.bb create mode 100644 meta/lib/oeqa/selftest/cases/bbclasses.pymeta-selftest/recipes-test/bbclasses/systemd-and-sysvinit.bb new file +15
-0@@ -0,0 +1,15 @@ +LICENSE = "CLOSED" + +inherit allarch systemd update-rc.d + +do_install() { + install -d ${D}${systemd_system_unitdir} + touch ${D}${systemd_system_unitdir}/${BPN}.service + + install -d ${D}${INIT_D_DIR} + touch ${D}${INIT_D_DIR}/${BPN} +} + +INITSCRIPT_NAME = "${BPN}" + +SYSTEMD_SERVICE:${PN} = "${BPN}.service"meta-selftest/recipes-test/bbclasses/systemd-only.bb new file +0
-0
meta-selftest/recipes-test/bbclasses/systemd-only.bb line 2
Quoted 2 lines
meta-selftest/recipes-test/bbclasses/systemd-only.bb new file +2
-0@@ -0,0 +1,10 @@ +LICENSE = "CLOSED" +
License is not conducive to project here so it has to change to something open
Quoted 138 lines
meta-selftest/recipes-test/bbclasses/systemd-only.bb new file +8
-0+inherit allarch systemd + +do_install() { + install -d ${D}${systemd_system_unitdir} + touch ${D}${systemd_system_unitdir}/${BPN}.service +} + +SYSTEMD_SERVICE:${PN} = "${BPN}.service"meta/lib/oeqa/selftest/cases/bbclasses.py new file +37
-0@@ -0,0 +1,106 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +from oeqa.selftest.case import OESelftestTestCase +from oeqa.utils.commands import get_bb_vars, bitbake + +class Systemd(OESelftestTestCase): + """ + Tests related to the systemd bbclass. + """ + + def getVars(self, recipe): + self.bb_vars = get_bb_vars( + [ + 'BPN', + 'D', + 'INIT_D_DIR', + 'prefix', + 'systemd_system_unitdir', + 'sysconfdir', + ], + recipe, + ) + + def fileExists(self, filename): + self.assertExists(filename.format(**self.bb_vars)) + + def fileNotExists(self, filename): + self.assertNotExists(filename.format(**self.bb_vars)) + + def test_systemd_in_distro(self): + """ + Summary: Verify that no sysvinit files are installed when the + systemd distro feature is enabled, but sysvinit isnot.
meta/lib/oeqa/selftest/cases/bbclasses.py new file +22
-0+ Expected: Systemd service file exists, but /etc does not. + Product: OE-Core + Author: Peter Kjellerstedt <[email protected]> + """ + + self.write_config(""" +DISTRO_FEATURES:append = " systemd usrmerge" +DISTRO_FEATURES:remove = "sysvinit" +VIRTUAL-RUNTIME_init_manager = "systemd" +""") + bitbake("systemd-only systemd-and-sysvinit -c install") + + self.getVars("systemd-only") + self.fileExists("{D}{systemd_system_unitdir}/{BPN}.service") + + self.getVars("systemd-and-sysvinit") + self.fileExists("{D}{systemd_system_unitdir}/{BPN}.service") + self.fileNotExists("{D}{sysconfdir}") + + def test_systemd_and_sysvinit_in_distro(self): + """ + Summary: Verify that both systemd and sysvinit files areinstalled
meta/lib/oeqa/selftest/cases/bbclasses.py new file +23
-0+ when both the systemd and sysvinit distro features are + enabled. + Expected: Systemd service file and sysvinit initscript exist. + Product: OE-Core + Author: Peter Kjellerstedt <[email protected]> + """ + + self.write_config(""" +DISTRO_FEATURES:append = " systemd sysvinit usrmerge" +VIRTUAL-RUNTIME_init_manager = "systemd" +""") + bitbake("systemd-only systemd-and-sysvinit -c install") + + self.getVars("systemd-only") + self.fileExists("{D}{systemd_system_unitdir}/{BPN}.service") + + self.getVars("systemd-and-sysvinit") + self.fileExists("{D}{systemd_system_unitdir}/{BPN}.service") + self.fileExists("{D}{INIT_D_DIR}/{BPN}") + + def test_sysvinit_in_distro(self): + """ + Summary: Verify that no systemd service files are installedwhen the
+ sysvinit distro feature is enabled, but systemd is
not.
+ Expected: The systemd service file does not exist, nor does
/usr.meta/lib/oeqa/selftest/cases/bbclasses.py new file +22
-1+ The sysvinit initscript exists. + Product: OE-Core + Author: Peter Kjellerstedt <[email protected]> + """ + + self.write_config(""" +DISTRO_FEATURES:remove = "systemd" +DISTRO_FEATURES:append = " sysvinit usrmerge" +VIRTUAL-RUNTIME_init_manager = "sysvinit" +""") + bitbake("systemd-only systemd-and-sysvinit -c install") + + self.getVars("systemd-only") + self.fileNotExists("{D}{systemd_system_unitdir}/{BPN}.service") + self.fileNotExists("{D}{prefix}") + self.fileNotExists("{D}{sysconfdir}") + self.fileExists("{D}") + + self.getVars("systemd-and-sysvinit") + self.fileNotExists("{D}{systemd_system_unitdir}/{BPN}.service") + self.fileNotExists("{D}{prefix}") + self.fileExists("{D}{INIT_D_DIR}/{BPN}") -=-=-=-=-=-=-=-=-=-=-=-Links: You receive all messages sent to this group. View/Reply Online (#203568):
https://lists.openembedded.org/g/openembedded-core/message/203568
Mute This Topic: https://lists.openembedded.org/mt/108008174/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-