From patchwork Fri Aug 23 17:06:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Kjellerstedt X-Patchwork-Id: 48162 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34658C5321D for ; Fri, 23 Aug 2024 17:06:48 +0000 (UTC) Received: from DU2PR03CU002.outbound.protection.outlook.com (DU2PR03CU002.outbound.protection.outlook.com [52.101.66.51]) by mx.groups.io with SMTP id smtpd.web10.1510.1724432802063356639 for ; Fri, 23 Aug 2024 10:06:42 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="dkim: body hash did not verify" header.i=@axis.com header.s=selector1 header.b=mhLju7We; spf=pass (domain: axis.com, ip: 52.101.66.51, mailfrom: peter.kjellerstedt@axis.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NYvkLtHd2EjrieqJyWS+Ab9rs7rcY/ymxznvUhHXNAqihTS+8WhjtvE0Wc2M20C8wx0TT/QneQIXKC9PKykidm/EvAMqik6IqW+F+GswcVEF31GHZLrFiPjBsFcsVsqix3eOaqADH7NChjYjPTb/le11YVjb1EHA1RA3sVeyIiERzES4X9W1CVmLFcPE8FbzsYVx4GKQD9L0pWhrDFugRJSgOZJOYWQedSGkJ2pGkAJx5SiqiFnPJCrRSJwGI33jq0x1UnCjTVRTP09pNhXiEh4zZMgmO9jKbOcJKHbYOVvvodJ6nuoCWOo5kML7/YRyNu5JKkiRjHf41d2vca/TQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LkGGObmVDHr7ZeLv2nLnXAuvst85XTTwvWRviUpO8cU=; b=rF+FM3v9NtOSDjN1x+QRtZhk2M0F8tTHbA5WfMRZSSTHZyqW0fLANI22e57YYxBFhyNO1IHDeJK63QNLorDBUoVircMNVxv9Yh1NEGiX+3icQATsPpEvHzNTHv5BO7YSfOLjcSzfSe9K/rr36Zm1vr6Hqk0KxcVQwJgGgIXtu5SQHqTSjYEezybGVZ4AUy4ZR74RGpsn/I/K6og8XRSqpr5Age5fYWTQsJk2s79TiDV2IxqzTB8YuPY6ZslzcQhY7IRzsIBuRj1ZI4YisyQUikqfsDzyeXXGxAu7B3KqYxH1RfZcjfq79ukqnBJ5co/OYWzyH3rkb+t4l3QPcxwQIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 195.60.68.100) smtp.rcpttodomain=lists.openembedded.org smtp.mailfrom=axis.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=axis.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LkGGObmVDHr7ZeLv2nLnXAuvst85XTTwvWRviUpO8cU=; b=mhLju7We5Lel4xq04Re1hfEnVQm8nfeAGMNIsFM/BbbRDAtXd2zHnh62vHXDaFOE0V1l/Q5RCEMXKR+6PbkbodDWHOUMydbNNgiEIPbZnhl5MR8mwpUKPDMyBJCtW2Kf49y6sgRAWa9P+BFbsuNDXAjG2Jj5HG30ciDhMvQN2ns= Received: from AS9PR06CA0055.eurprd06.prod.outlook.com (2603:10a6:20b:463::6) by PAWPR02MB9830.eurprd02.prod.outlook.com (2603:10a6:102:2e8::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Fri, 23 Aug 2024 17:06:37 +0000 Received: from AM3PEPF00009B9E.eurprd04.prod.outlook.com (2603:10a6:20b:463:cafe::d7) by AS9PR06CA0055.outlook.office365.com (2603:10a6:20b:463::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.19 via Frontend Transport; Fri, 23 Aug 2024 17:06:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 195.60.68.100) smtp.mailfrom=axis.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=axis.com; Received-SPF: Pass (protection.outlook.com: domain of axis.com designates 195.60.68.100 as permitted sender) receiver=protection.outlook.com; client-ip=195.60.68.100; helo=mail.axis.com; pr=C Received: from mail.axis.com (195.60.68.100) by AM3PEPF00009B9E.mail.protection.outlook.com (10.167.16.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7897.11 via Frontend Transport; Fri, 23 Aug 2024 17:06:37 +0000 Received: from se-mail02w.axis.com (10.20.40.8) by se-mail01w.axis.com (10.20.40.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 23 Aug 2024 19:06:37 +0200 Received: from se-intmail01x.se.axis.com (10.0.5.60) by se-mail02w.axis.com (10.20.40.8) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Fri, 23 Aug 2024 19:06:37 +0200 Received: from saur.se.axis.com (saur.se.axis.com [10.92.3.10]) by se-intmail01x.se.axis.com (Postfix) with ESMTP id 1FC2A351 for ; Fri, 23 Aug 2024 19:06:37 +0200 (CEST) Received: from saur.se.axis.com (localhost [127.0.0.1]) by saur.se.axis.com (8.17.1/8.15.2) with ESMTPS id 47NH6bsc2776919 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Fri, 23 Aug 2024 19:06:37 +0200 Received: (from pkj@localhost) by saur.se.axis.com (8.17.1/8.17.1/Submit) id 47NH6aZI2776918 for openembedded-core@lists.openembedded.org; Fri, 23 Aug 2024 19:06:36 +0200 From: Peter Kjellerstedt To: Subject: [PATCHv2 1/2] systemd.bbclass: Clean up empty parent directories Date: Fri, 23 Aug 2024 19:06:32 +0200 Message-ID: <20240823170633.2776886-1-pkj@axis.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM3PEPF00009B9E:EE_|PAWPR02MB9830:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d6b37b0-a5b7-47bd-6db8-08dcc395f316 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: OQGgcFqmQ18xbjHqnbYKqEtMjqxN5GTKDCE8P28Ui9pwsbOPXoMrvI/L8KS0eZrfnTVqxCMtPqNN1gim/7xHdA6ImZgOqgOjU/nQLJgMwauih9jmS2C6pfbxUTCHoVe7ygIUIaWkric1HV8oe1kvT6wk844v5CTKnhxGVyJQWGAcMfz8RK/Z9KeFOXJYFuRXs4rLajBhySPA5QU+KzXd1l4jYL6FZjba0RKxnUhcWYqXZoTwg/u/paSVJmydq9QmrQM6zOsvOxpE1RjOaoFENxNKdrNrK2kJ85VJnRG6c8yHGULn0eDCOQPTMQ9XuOXlVmJNwhJTaBnaZedpljC4QNCOU4NNIKxqH7RZ/TYM5CbRyTi2KFtoX1PIQhOh/Qp/sK+RbCsFqf0YTmjMlNt/rIUSDYZtImwuIjxIII6lNyvdQtlNLK3v6rmk8JkB3bFdtkHBQYgvvfbJnVzTuUiOvtvCtmD2RgMhrZSpiCR1AS5hxz68fjvZWljRBvw7j+8nhlGAORGUc5ZrU+aOTAOfkmAcLfcijgfMoXFxYkHlOO3tDNdSk/Ps2uamf3H8BXm3pylFOY2M3BubG8WRNS4BSs4g6BI+iSPTkvoegHzN715hgul4Y3a1VzBzC1dCfvXHtDQAf4IzGOq435ki+PX511K1Z99DrZWcFyxrCfx4emxvy804WEwdti7+u1QQa6/llGBK4OdQ6apmj8Klrpi7T4q1SuhC48cJEpY0ZAX4Cl2BpXh+dYHWiu895i6pGjsY4HtqQIp7kcr5JdxI3dK+GgsGw1w3tCE4muawIDw03vI+GE5AhrrQhacYKv5elwbtycqOIvYSfsHwV4d2H9dc5w3W9oyOJZQ8bStcM3eOls/dW9n04ixzi4ZnsbA/B8pz3HupkgroWbvkbt28aQtY+9PhovDWHhjkN2C2IioUV5pQDWKRpIZEtM20wf0HPJZxTBUiKrHMUcFKQrC8/B/xOEZ7vsyQ0YvDwOOARtcgFi3u10e+fqupOZ0k1I6NGFPWZti9Ajoc3R3UPc+6+yJl+21ShAQxbrjZ4EQovkPLJ6o2fs5REQCzagPyOOL4cZTgeG3ocCK7+w0HQ/AaO+/0JgmLOcbd5UbfjkvUfZQR57yqzyxG+nHO6BHdAdOCqgWPZYnY4ge4dG39tZXtrEkldCPmNnzDk1fmhS+mMlwotIopLg1Pz9fFeZWL54m6zUpQZFRMA3VMGvlxIF7jJA9m9XElEZxddhfK/GzAIs7zToaigBgF3jEtMYYa/7RRbiKuVDd+gbNa8BDjix3WyDCHHbkGSpspzZ3l+EWaoKG07oMBNQFF/CS52CslCj+jigZalWpktULGd3AQ1BEc8NIVZVNpgTrvTEAOUYJiL/PfuA34cRmFyH1GsC9Fzaqkg2+nPl8OzgFttH4DCTxfDqjKW/tbd3CfmSiVvf3mN8PdqmUyzro9A/WsAzvJZcqxeCk4 X-Forefront-Antispam-Report: CIP:195.60.68.100;CTRY:SE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.axis.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: axis.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 17:06:37.5332 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9d6b37b0-a5b7-47bd-6db8-08dcc395f316 X-MS-Exchange-CrossTenant-Id: 78703d3c-b907-432f-b066-88f7af9ca3af X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=78703d3c-b907-432f-b066-88f7af9ca3af;Ip=[195.60.68.100];Helo=[mail.axis.com] X-MS-Exchange-CrossTenant-AuthSource: AM3PEPF00009B9E.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR02MB9830 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Fri, 23 Aug 2024 17:06:48 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/203701 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. Signed-off-by: Peter Kjellerstedt --- PATCHv2: * Rewrote rm_systemd_unitdir() to avoid having `rmdir -p` potentially delete ${D}. * Add an argument to `read` used in rm_sysvinit_initddir() while determining if ${systemd_system_unitdir} is empty. Calling read without arguments is apparently a bashism. meta/classes-recipe/systemd.bbclass | 45 +++++++++++++---------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass index 0f7e3b5a08..fa6d3775ec 100644 --- a/meta/classes-recipe/systemd.bbclass +++ b/meta/classes-recipe/systemd.bbclass @@ -208,33 +208,28 @@ 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} + # Change into ${D} and use a relative path with rmdir -p to avoid + # having it remove ${D} if it becomes empty. + (cd ${D} && rmdir -p $(dirname ${systemd_unitdir#/}) 2>/dev/null || :) } -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 DUMMY; 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 = "" From patchwork Fri Aug 23 17:06:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Kjellerstedt X-Patchwork-Id: 48163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3461FC531DC for ; Fri, 23 Aug 2024 17:06:48 +0000 (UTC) Received: from DU2PR03CU002.outbound.protection.outlook.com (DU2PR03CU002.outbound.protection.outlook.com [52.101.66.46]) by mx.groups.io with SMTP id smtpd.web11.1511.1724432804443410549 for ; Fri, 23 Aug 2024 10:06:44 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="dkim: body hash did not verify" header.i=@axis.com header.s=selector1 header.b=Trvfy/hH; spf=pass (domain: axis.com, ip: 52.101.66.46, mailfrom: peter.kjellerstedt@axis.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jtHTZ9N4RSX4I4gy3HHvgH0NBMi6DEGwdkpDhBNPM7j8GPo5LLGKZm7ulaCKMTxfY3ni42aoyxMXAnuftCAY5BfEOMZlTjIcgewkc6dKcLkHaM4McHL/5vJ7gMPUJs6B9q5J/WSIv24836/CNxWtPT/0/njbbX41za9ILoo1JM4KxTMVFzo7+OD8qfnsaFCrl1Ydn5IsVM8C4bX0fdzfq1lhQiv4a5H/mZnQhe4wVNGY5ye4yAsr5MuZ1IXNoXuSCEP2IlTRvgO0win4YY18y2lQFt7T2/+IZMhpqKDtqLl2B85LbKOOgjNhRgRD1bfpLDou0nMuS4zeFAzMyYCSfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cp2ije/eAK9fnX+rcNiJUrGVf7ZPpTD66KFmSbwXgcU=; b=GkwaxwHrlY/8uPmo8FoLTPdzUDXZ68WcBONc/ZUup5mpySD/Gf9bzIIRWH/YbWcGa5mtYmrLtLOBCIsU4qzyo0PZqcdf9wjiOaZDdx4Tu1udEZijoQSS+34pA0dhKwzuPBpwvs1o0ZqHI9sLyC3BF9F4XgyQlnVlHNUXSoioIMBeN2FHdB6xqVPr+AZIcSufhNbL//GVtZJRUalEnNtjSw7GQmENj5zE9MjABiX5P7X/7K7VyZ1VqvJBf42Xkinl8GbkJft7SMIdvvU9ISeERZSpLCEX9S3HIh7BhoSriC3EX1DxEk+wK7vqDtd8kwMNrGC5/YjwXw50eZbYjeGt9A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 195.60.68.100) smtp.rcpttodomain=lists.openembedded.org smtp.mailfrom=axis.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=axis.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cp2ije/eAK9fnX+rcNiJUrGVf7ZPpTD66KFmSbwXgcU=; b=Trvfy/hH+j4NCduyiNcaiz6GPOeU/vMR30MhZZsmV2580TStPD2aXzhrKzK5eU0efXepL0ffUyPiuxb1cW4tPunI7oDbYAW1XsOj70fJepRw5d1P8mvhyAfLC/Wjb07EIEE2uiP/wZ/B/6n5IFHShLmBXbuAKrERaRL0MyLW26Q= Received: from AS9PR06CA0054.eurprd06.prod.outlook.com (2603:10a6:20b:463::14) by VI1PR02MB5984.eurprd02.prod.outlook.com (2603:10a6:800:18c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.25; Fri, 23 Aug 2024 17:06:38 +0000 Received: from AM3PEPF00009B9E.eurprd04.prod.outlook.com (2603:10a6:20b:463:cafe::c3) by AS9PR06CA0054.outlook.office365.com (2603:10a6:20b:463::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.19 via Frontend Transport; Fri, 23 Aug 2024 17:06:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 195.60.68.100) smtp.mailfrom=axis.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=axis.com; Received-SPF: Pass (protection.outlook.com: domain of axis.com designates 195.60.68.100 as permitted sender) receiver=protection.outlook.com; client-ip=195.60.68.100; helo=mail.axis.com; pr=C Received: from mail.axis.com (195.60.68.100) by AM3PEPF00009B9E.mail.protection.outlook.com (10.167.16.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7897.11 via Frontend Transport; Fri, 23 Aug 2024 17:06:38 +0000 Received: from se-mail02w.axis.com (10.20.40.8) by se-mail01w.axis.com (10.20.40.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 23 Aug 2024 19:06:37 +0200 Received: from se-intmail01x.se.axis.com (10.0.5.60) by se-mail02w.axis.com (10.20.40.8) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Fri, 23 Aug 2024 19:06:37 +0200 Received: from saur.se.axis.com (saur.se.axis.com [10.92.3.10]) by se-intmail01x.se.axis.com (Postfix) with ESMTP id 3F0F33CD for ; Fri, 23 Aug 2024 19:06:37 +0200 (CEST) Received: from saur.se.axis.com (localhost [127.0.0.1]) by saur.se.axis.com (8.17.1/8.15.2) with ESMTPS id 47NH6bBS2776923 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Fri, 23 Aug 2024 19:06:37 +0200 Received: (from pkj@localhost) by saur.se.axis.com (8.17.1/8.17.1/Submit) id 47NH6bsL2776922 for openembedded-core@lists.openembedded.org; Fri, 23 Aug 2024 19:06:37 +0200 From: Peter Kjellerstedt To: Subject: [PATCHv2 2/2] oeqa/selftest/bbclasses: Add tests for systemd and update-rc.d interaction Date: Fri, 23 Aug 2024 19:06:33 +0200 Message-ID: <20240823170633.2776886-2-pkj@axis.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240823170633.2776886-1-pkj@axis.com> References: <20240823170633.2776886-1-pkj@axis.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM3PEPF00009B9E:EE_|VI1PR02MB5984:EE_ X-MS-Office365-Filtering-Correlation-Id: ed3cd91b-c602-44b6-90d4-08dcc395f37a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: n/6fNa6/cUw3ANvu3PpEqQRiQMOCZlJyGS36FlB7+VixM1ueMmlvg7hkS+mi27ULaeW1fdYCFH25+3u3/MgKfQq87bYNNllKw8m+wJG4W13N6TYdmVuhtIHFX1lsOGq9fgOZWpDCFOnW0RGHJq+Zsqm6sVtx+pAIGP0sXXoEPYKjvUhO9LH9XkQTDBvyWDcfRhEojRhCBdAtwj6b3FT8jB+/4oLhODPLuh0NO/qRU8Q/BejfNse0BCM/OSugNX1b0g6L045rkXg2TomzU7PFaLhLckuOSreNhzatBZ0yUsEiN3JAwiDBBIh7/z5De2x7THkzoVzgynZEET9gw11r1muOPbGqt1sSWoO4Zba/wK5KDX+CdSV92VBwvwo6jv6gvtfzUAYXYQ2iw+IevFh/zs/AYZInXiTpu8DAWi/VmhKrztLe1ec8UXYb7YztX+6gPJR2psgsvnZZFmU1ZUhWNP1A3ujqMaCU2m2ipxVM6BAZHp7zSk2G5hh6ypLn3izzI1LFyRWKo3h/qDmfKxEiTJD525tUqYMOODtMyvZi3r8pCwJP90lLOvgZ5JSVEmt9Xwq7Watcg8hO6kudh1QY0M2uqjdfFWFVZknaIbEqrujYW95xSC4hVg+fM0c2VfxvxQL5YpTRVmb4UNxd84gzdfNln/u1IAAEdvwYInrLq4fSXeMLC9/iD51n1no082ukKZBWirlrRz0TvOjjPcVsDnJDremiXnFGVBo6fFyrTQJxCCdNZfSXN+f/NCCaFNvXOdt1wFQ8xNmz73x7vQSsge8lL1Ed6CWZsLVZqiiw7ciN+1HAWxJA5zmazFZ0LqK+SndWSkEAunrYqM7xt8+VfBG4AnF2M/m1FcZvgUoXsbmAF/FSZtBu6a2qsMjuEIoyfpiqTCATGPALBWT4BhId9zZ33vfpwGgYopUAUgkHs3vKY/T9oOXHRTJ4CJdV8AXyKZd+/hWvtvnaS2TwrmpzEAvzLtCCTflPV+cNGBrzyjnZLMXA0J2qvErsacCth4i/vSOWlrkmGHzvgIPIT6KNt8RmD3H8wnqgSKWA0tFNYxcpPCdIb8dL4b5Ov0vX9oAklZW64QMle2eGjLIC/InAX0PoKXuDLdXlafIlzCjpW8wBpXV4YU11dEvQIMFzuKuwIsaJazKuplpMDIFL93O3xETa1EvGjVxlmYRcw8p4WsSTB35GtqxlIcBuLOTJjtoRJlBdtOfHw+OxyJd3fhgdMKGkLSh+bQlw/FftnEFkZuSjTgArNlyzkC1jwb2ECBOonCCDi6THEApUe1gWCT9k8OTNuHGsHy1fgh+TvIycciBAe+dN8CcGKpQj/3OzgPGn4dLEgmDwBwJl8ajWYYsXoPv3zIEXlXny4uzzLXcCNs6aCN41vIc1j0+PcG5Zzxt4qX8WrxIQg/gpno8erEcdLLrLrsxF2bNZN518XyBDv1g1nV9FbzJxFyzIEH0nhj/r X-Forefront-Antispam-Report: CIP:195.60.68.100;CTRY:SE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.axis.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: axis.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 17:06:38.1894 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ed3cd91b-c602-44b6-90d4-08dcc395f37a X-MS-Exchange-CrossTenant-Id: 78703d3c-b907-432f-b066-88f7af9ca3af X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=78703d3c-b907-432f-b066-88f7af9ca3af;Ip=[195.60.68.100];Helo=[mail.axis.com] X-MS-Exchange-CrossTenant-AuthSource: AM3PEPF00009B9E.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR02MB5984 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Fri, 23 Aug 2024 17:06:48 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/203702 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 --- PATCHv2: * Change LICENSE to MIT for the test recipes. * Add EXCLUDE_FROM_WORLD to the test recipes. .../bbclasses/systemd-and-sysvinit.bb | 17 +++ .../recipes-test/bbclasses/systemd-only.bb | 12 ++ meta/lib/oeqa/selftest/cases/bbclasses.py | 106 ++++++++++++++++++ 3 files changed, 135 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 diff --git a/meta-selftest/recipes-test/bbclasses/systemd-and-sysvinit.bb b/meta-selftest/recipes-test/bbclasses/systemd-and-sysvinit.bb new file mode 100644 index 0000000000..f9fc59a494 --- /dev/null +++ b/meta-selftest/recipes-test/bbclasses/systemd-and-sysvinit.bb @@ -0,0 +1,17 @@ +LICENSE = "MIT" + +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" + +EXCLUDE_FROM_WORLD="1" diff --git a/meta-selftest/recipes-test/bbclasses/systemd-only.bb b/meta-selftest/recipes-test/bbclasses/systemd-only.bb new file mode 100644 index 0000000000..590a27b9cb --- /dev/null +++ b/meta-selftest/recipes-test/bbclasses/systemd-only.bb @@ -0,0 +1,12 @@ +LICENSE = "MIT" + +inherit allarch systemd + +do_install() { + install -d ${D}${systemd_system_unitdir} + touch ${D}${systemd_system_unitdir}/${BPN}.service +} + +SYSTEMD_SERVICE:${PN} = "${BPN}.service" + +EXCLUDE_FROM_WORLD="1" diff --git a/meta/lib/oeqa/selftest/cases/bbclasses.py b/meta/lib/oeqa/selftest/cases/bbclasses.py new file mode 100644 index 0000000000..10545ebe65 --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/bbclasses.py @@ -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 is not. + Expected: Systemd service file exists, but /etc does not. + Product: OE-Core + Author: Peter Kjellerstedt + """ + + 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 are installed + when both the systemd and sysvinit distro features are + enabled. + Expected: Systemd service file and sysvinit initscript exist. + Product: OE-Core + Author: Peter Kjellerstedt + """ + + 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 installed when the + sysvinit distro feature is enabled, but systemd is not. + Expected: The systemd service file does not exist, nor does /usr. + The sysvinit initscript exists. + Product: OE-Core + Author: Peter Kjellerstedt + """ + + 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}")