public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: claudius.heine.ext@siemens.com
To: isar-users@googlegroups.com
Cc: Claudius Heine <ch@denx.de>
Subject: [PATCH v2 1/1] base.bbclass: implement 'root_cleandirs' feature
Date: Mon,  9 Apr 2018 12:45:25 +0200	[thread overview]
Message-ID: <20180409104525.5830-2-claudius.heine.ext@siemens.com> (raw)
In-Reply-To: <20180409104525.5830-1-claudius.heine.ext@siemens.com>

From: Claudius Heine <ch@denx.de>

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 <ch@denx.de>
---
 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


      reply	other threads:[~2018-04-09 10:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-09 10:45 [PATCH v2 0/1] Centralize root_cleandirs feature claudius.heine.ext
2018-04-09 10:45 ` claudius.heine.ext [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180409104525.5830-2-claudius.heine.ext@siemens.com \
    --to=claudius.heine.ext@siemens.com \
    --cc=ch@denx.de \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox