From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6540948938494574592 X-Received: by 10.223.130.21 with SMTP id 21mr2400266wrb.2.1523270735336; Mon, 09 Apr 2018 03:45:35 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 10.28.13.196 with SMTP id 187ls1518336wmn.2.canary-gmail; Mon, 09 Apr 2018 03:45:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+zSXdDnhrHadzUj3vVHo84AzfZ24Q/YwPTIkAmue1uSLRvvS0xo+PPM4KGfwUv0bpVPBrJ X-Received: by 10.28.160.21 with SMTP id j21mr2444339wme.5.1523270734743; Mon, 09 Apr 2018 03:45:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523270734; cv=none; d=google.com; s=arc-20160816; b=hC90nRWzw1T1j8L+f1I98Fa0dbXrYMQ8DbnTHz8SDkm/wAfsjF9vxCF2/vXoTaQ6QV BiRy770GnSosXkXddiu1zUsjv09F7lYUbPIdP1C171l7sZfk9yhBPrmxfzZZd8/UCn+k jyGJfWf3efdiROBMJ5XTE5nFBKzH4r70ak99V8+Ri/JN8E3oZp6tqoXzn+ecCDS3s840 VZFrxOf7rBaV27/XdY2V+fCZyWZK6ue7J1IJsUJiFp2/nHKt3b06kW5hL4Cp4Et/Fxca 2IMUSoqQg0cHx/wqV8cXjjgpF819DEjEthg3gg+5yRDJO0DIFFMRRVofWxk1gNw/Retg tNHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=dzUWkGDwmVHqZeNsTYwHhdgqOIunUGTtqLUBlupFC98=; b=lMu6vcmp6VurCZ+yowKeaIzU/7oCkAa+xJwxwGxtxyq7pUA9hrZjP9/nb/eZQMRQ69 +GnJz0WSc3fFFJD6mUqZUeiD4A9AcGrtGCoYrGOAMm3CCNF6T/1d+DGBkNFoVULoK9Sm 3LZqT3wxoBFhCQACWYhLUVuotGxHdbFEM7bzd62ehArfboILKtJzQUQfBnN1ukrSNpDm wDi/3S6NVUh5Yi2Xx3p8ry4RHfSzTPcNKL4bsvoeZt44gHWYGqeDQdpd+/Op0TgEBxkR qJu9eGdS6MO8GymDvS6pp76x3QpLKbvYcCvR5r3swqFTQi+P8vT+kcoRDD+lX4JnRQmC eFfA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Return-Path: Received: from goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id v195si11296wmf.0.2018.04.09.03.45.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Apr 2018 03:45:34 -0700 (PDT) Received-SPF: pass (google.com: domain of claudius.heine.ext@siemens.com designates 192.35.17.28 as permitted sender) client-ip=192.35.17.28; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Received: from mail2.sbs.de (mail2.sbs.de [192.129.41.66]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id w39AjXp5024647 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Apr 2018 12:45:34 +0200 Received: from ring.ppmd.siemens.net (linux-ses-ext02.ppmd.siemens.net [139.25.69.226]) by mail2.sbs.de (8.15.2/8.15.2) with ESMTP id w39AjW6o007315; Mon, 9 Apr 2018 12:45:33 +0200 From: claudius.heine.ext@siemens.com To: isar-users@googlegroups.com Cc: Claudius Heine Subject: [PATCH v2 1/1] base.bbclass: implement 'root_cleandirs' feature Date: Mon, 9 Apr 2018 12:45:25 +0200 Message-Id: <20180409104525.5830-2-claudius.heine.ext@siemens.com> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180409104525.5830-1-claudius.heine.ext@siemens.com> References: <20180409104525.5830-1-claudius.heine.ext@siemens.com> X-TUID: AXTI8Z5FftS2 From: Claudius Heine With this commits its now possible to set the 'root_cleandirs' flag on tasks. This flag triggers privileged deletion of the directories listed in the value of the flag before the rest of the task is evaluated. This is fully implemented in the 'base.bbclass' without modifying bitbake via a python function that is evaluated on parsing the recipes. After a sanity check: directory paths should be contained within the tmp directory, it adds the 'root_cleandirs' shell function to the top of the task body. Signed-off-by: Claudius Heine --- meta-isar/recipes-core/images/isar-image-base.bb | 6 ---- meta/classes/base.bbclass | 41 ++++++++++++++++++++++++ meta/recipes-devtools/buildchroot/buildchroot.bb | 6 ---- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/meta-isar/recipes-core/images/isar-image-base.bb b/meta-isar/recipes-core/images/isar-image-base.bb index c4799d3..37596ed 100644 --- a/meta-isar/recipes-core/images/isar-image-base.bb +++ b/meta-isar/recipes-core/images/isar-image-base.bb @@ -30,12 +30,6 @@ do_rootfs[root_cleandirs] = "${IMAGE_ROOTFS} \ ${IMAGE_ROOTFS}/isar-apt" do_rootfs() { - CDIRS="${@d.expand(d.getVarFlags("do_rootfs").get("root_cleandirs", ""))}" - if [ -n "$CDIRS" ]; then - sudo rm -rf $CDIRS - mkdir -p $CDIRS - fi - setup_root_file_system "${IMAGE_ROOTFS}" ${IMAGE_PREINSTALL} ${IMAGE_INSTALL} # Configure root filesystem diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass index f83c4db..d1df8cc 100644 --- a/meta/classes/base.bbclass +++ b/meta/classes/base.bbclass @@ -66,6 +66,47 @@ python do_listtasks() { bb.plain("%s %s" % (taskname.ljust(maxlen), taskdescs[taskname])) } +root_cleandirs() { + ROOT_CLEANDIRS_DIRS_PY="${@d.getVar("ROOT_CLEANDIRS_DIRS", True) or ""}" + ROOT_CLEANDIRS_DIRS="${ROOT_CLEANDIRS_DIRS-${ROOT_CLEANDIRS_DIRS_PY}}" + for i in $ROOT_CLEANDIRS_DIRS; do + awk '{ print $2 }' /proc/mounts | grep -q "^${i}\(/\|\$\)" && \ + die "Could not remove $i, because subdir is mounted" + done + if [ -n "$ROOT_CLEANDIRS_DIRS" ]; then + sudo rm -rf --one-file-system $ROOT_CLEANDIRS_DIRS + mkdir -p $ROOT_CLEANDIRS_DIRS + fi +} + +python() { + import re + for e in d.keys(): + flags = d.getVarFlags(e) + if flags and flags.get('task'): + rcleandirs = flags.get('root_cleandirs') + if rcleandirs: + tmpdir = os.path.normpath(d.getVar("TMPDIR", True)) + rcleandirs = list(os.path.normpath(d.expand(i)) + for i in rcleandirs.split()) + + for i in rcleandirs: + if not i.startswith(tmpdir): + bb.fatal("root_cleandirs entry %s is not contained in " + "TMPDIR %s" % (i, tmpdir)) + + ws = re.match("^\s*", d.getVar(e, False)).group() + if flags.get('python'): + d.prependVar(e, ws + "d.setVar('ROOT_CLEANDIRS_DIRS', '" + + " ".join(rcleandirs) + "')\n" + + ws + "bb.build.exec_func(" + + "'root_cleandirs', d)\n") + else: + d.prependVar(e, ws + "ROOT_CLEANDIRS_DIRS='" + + " ".join(rcleandirs) + "'\n" + + ws + "root_cleandirs\n") +} + do_fetch[dirs] = "${DL_DIR}" # Fetch package from the source link diff --git a/meta/recipes-devtools/buildchroot/buildchroot.bb b/meta/recipes-devtools/buildchroot/buildchroot.bb index b16e63a..690dab8 100644 --- a/meta/recipes-devtools/buildchroot/buildchroot.bb +++ b/meta/recipes-devtools/buildchroot/buildchroot.bb @@ -38,12 +38,6 @@ do_build[root_cleandirs] = "${BUILDCHROOT_DIR} \ do_build[depends] = "isar-apt:do_cache_config isar-bootstrap:do_deploy" do_build() { - CDIRS="${@d.expand(d.getVarFlags("do_build").get("root_cleandirs", ""))}" - if [ -n "$CDIRS" ]; then - sudo rm -rf $CDIRS - mkdir -p $CDIRS - fi - setup_root_file_system "${BUILDCHROOT_DIR}" ${BUILDCHROOT_PREINSTALL} # Install package builder script -- 2.16.3