* [PATCH 1/1] base.bbclass: implement 'root_cleandirs' feature
2018-04-05 13:02 [PATCH 0/1] Centralize root_cleandirs feature claudius.heine.ext
@ 2018-04-05 13:02 ` claudius.heine.ext
2018-04-05 13:18 ` [PATCH 0/1] Centralize root_cleandirs feature Claudius Heine
1 sibling, 0 replies; 3+ messages in thread
From: claudius.heine.ext @ 2018-04-05 13:02 UTC (permalink / raw)
To: isar-users; +Cc: Claudius Heine
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 | 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 0/1] Centralize root_cleandirs feature
2018-04-05 13:02 [PATCH 0/1] Centralize root_cleandirs feature claudius.heine.ext
2018-04-05 13:02 ` [PATCH 1/1] base.bbclass: implement 'root_cleandirs' feature claudius.heine.ext
@ 2018-04-05 13:18 ` Claudius Heine
1 sibling, 0 replies; 3+ messages in thread
From: Claudius Heine @ 2018-04-05 13:18 UTC (permalink / raw)
To: isar-users; +Cc: Claudius Heine
Hi again,
On 04/05/2018 03:02 PM, [ext] claudius.heine.ext@siemens.com wrote:
> From: Claudius Heine <ch@denx.de>
>
> Hi,
>
> since Baurzhan asked about this, I created a patch to show how I would
> envision the 'root_cleandirs' feature.
>
> Later maybe even something like 'root_cleanmounts' could be implemented,
> that unmounts all mount points under specified paths before calling
> 'root_cleandirs'.
>
> What do you think? Feedback welcome.
Just to make it clear, this is WIP. There are some issues that need to
be worked out and thought over.
For instance it currently supports only one such task per recipe, since
is uses the recipe global 'CDIRS' variable. This needs to be changed
before merging.
Cheers,
Claudius
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-54 Fax: (+49)-8142-66989-80 Email: ch@denx.de
^ permalink raw reply [flat|nested] 3+ messages in thread