From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6540948938494574592 X-Received: by 10.28.22.71 with SMTP id 68mr1209850wmw.32.1522933356479; Thu, 05 Apr 2018 06:02:36 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 10.28.167.84 with SMTP id q81ls1194647wme.1.gmail; Thu, 05 Apr 2018 06:02:36 -0700 (PDT) X-Google-Smtp-Source: AIpwx49CpuNWcFfvsgg5cIvE9bhuFE0xPFT6OvbyUM3aO9oMSZdfAOWM6r740szEwwCa1oyPEZjm X-Received: by 10.28.6.77 with SMTP id 74mr190603wmg.26.1522933355994; Thu, 05 Apr 2018 06:02:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522933355; cv=none; d=google.com; s=arc-20160816; b=h2I7Oi3yG8FSaPTqZ525Eccfhh/NH9h9d6RJ3YaB9PHmjYNv+DuOT3yvOA9WunY/Ch zUUyxrbzPspcf1AzQ/MfE7lsJf4eSeFMvmzFhqHxMg6k8Wfe9ukJckldLWk04c89s3+i TxeOZvh6Y39a5IMWf5y061ia/4EYflcWFtaMnYgUgyGYHk+njyjO2HZrDjNoD99DgWaO 2E3VJYp8E5HTPF6QRSJMmuBagtY6TCghI+GVZXu2nC0zR00+ufUVg+kL5hMt01rCZXpV nF0Z2yCaKW0ASh8+dh9WgjV5vqrp9UYtSHcuss4itaEf+H6KGd2LsoZF9DuD3tGx1QbC 8Afw== 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=wQB2iP1Vnp7o0eIluyUNF0uKNoA91tVGvwREMOfSgNU=; b=ziA2ZBFpXkqlzaLVeHxT80T+7PC/xusZUHRJIT+OPpPc4K/IYjKGwUlBGUjbHGTa0g o62qKQNo1SOmaJImsEhKhkimW8d90YTPkleSNyrkBkfZ8xLDXxBkUOGr+SCkkikErL4L L5x9HharLCaOsLnOMi/NSCdyTf1bd7edEHGRIVJyw8/lxjpUnt9Dq2/StOyOmIDAHYMs jE8F1QntpUopgXaQnWdM8PVuKFUXqxR2S3MGv9GcmjtymEb1kFC9IihXYh4uaivEXTuG K3rhCKb39E0R4y8UejBC2KV7EB5/dFbVVuhWxlGucH9Lf92yzrivK7JWmoUDXS3N4mwX 13sA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 194.138.37.40 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Return-Path: Received: from gecko.sbs.de (gecko.sbs.de. [194.138.37.40]) by gmr-mx.google.com with ESMTPS id r21si199560wmc.1.2018.04.05.06.02.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Apr 2018 06:02:35 -0700 (PDT) Received-SPF: pass (google.com: domain of claudius.heine.ext@siemens.com designates 194.138.37.40 as permitted sender) client-ip=194.138.37.40; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 194.138.37.40 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Received: from mail2.sbs.de (mail2.sbs.de [192.129.41.66]) by gecko.sbs.de (8.15.2/8.15.2) with ESMTPS id w35D2UVP022980 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 5 Apr 2018 15:02:35 +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 w35D2THj026004; Thu, 5 Apr 2018 15:02:30 +0200 From: claudius.heine.ext@siemens.com To: isar-users@googlegroups.com Cc: Claudius Heine Subject: [PATCH 1/1] base.bbclass: implement 'root_cleandirs' feature Date: Thu, 5 Apr 2018 15:02:24 +0200 Message-Id: <20180405130224.12181-2-claudius.heine.ext@siemens.com> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180405130224.12181-1-claudius.heine.ext@siemens.com> References: <20180405130224.12181-1-claudius.heine.ext@siemens.com> X-TUID: 473X7opOh2IS 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 | 38 ++++++++++++++++++++++++ meta/recipes-devtools/buildchroot/buildchroot.bb | 6 ---- 3 files changed, 38 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..53c15e1 100644 --- a/meta/classes/base.bbclass +++ b/meta/classes/base.bbclass @@ -66,6 +66,44 @@ python do_listtasks() { bb.plain("%s %s" % (taskname.ljust(maxlen), taskdescs[taskname])) } +root_cleandirs() { + CDIRS="${@d.getVar("CDIRS", True)}" + for i in $CDIRS; do + awk '{ print $2 }' /proc/mounts | grep -q "^${i}\(/\|\$\)" && \ + die "Could not remove $i, because subdir is mounted" + done + if [ -n "$CDIRS" ]; then + sudo rm -rf --one-file-system $CDIRS + mkdir -p $CDIRS + 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)) + + d.setVar("CDIRS", " ".join(rcleandirs)) + whitespaces = re.match("^\s*", d.getVar(e, False)).group() + if flags.get('python'): + d.prependVar(e, whitespaces + + "bb.build.exec_func('root_cleandirs', d))\n") + else: + d.prependVar(e, whitespaces + + "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