* [PATCH v2 0/1] Centralize root_cleandirs feature
@ 2018-04-09 10:45 claudius.heine.ext
2018-04-09 10:45 ` [PATCH v2 1/1] base.bbclass: implement 'root_cleandirs' feature claudius.heine.ext
0 siblings, 1 reply; 2+ messages in thread
From: claudius.heine.ext @ 2018-04-09 10:45 UTC (permalink / raw)
To: isar-users; +Cc: Claudius Heine
From: Claudius Heine <ch@denx.de>
Hi,
I fixed the issue that disallowed the root_cleandirs on multiple tasks
in one recipe. Also I renamed the internal environment variables from
'CDIRS' to 'ROOT_CLEANDIRS_DIRS' to avoid possible conflicts.
Cheers,
Claudius
Changes from v1:
- now possible to use root_cleandirs for multiple tasks in on recipe
- renamed 'CDIRS' variable to 'ROOT_CLEANDIRS_DIRS'
Claudius Heine (1):
base.bbclass: implement 'root_cleandirs' feature
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(-)
--
2.16.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH v2 1/1] base.bbclass: implement 'root_cleandirs' feature
2018-04-09 10:45 [PATCH v2 0/1] Centralize root_cleandirs feature claudius.heine.ext
@ 2018-04-09 10:45 ` claudius.heine.ext
0 siblings, 0 replies; 2+ messages in thread
From: claudius.heine.ext @ 2018-04-09 10:45 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 | 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-04-09 10:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-09 10:45 [PATCH v2 0/1] Centralize root_cleandirs feature claudius.heine.ext
2018-04-09 10:45 ` [PATCH v2 1/1] base.bbclass: implement 'root_cleandirs' feature claudius.heine.ext
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox