summaryrefslogtreecommitdiffstats
path: root/meta/classes/rm_work.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/rm_work.bbclass')
-rw-r--r--meta/classes/rm_work.bbclass104
1 files changed, 58 insertions, 46 deletions
diff --git a/meta/classes/rm_work.bbclass b/meta/classes/rm_work.bbclass
index 13a9e75d85..52ecfafb72 100644
--- a/meta/classes/rm_work.bbclass
+++ b/meta/classes/rm_work.bbclass
@@ -1,4 +1,10 @@
#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+#
# Removes source after build
#
# To use it add that line to conf/local.conf:
@@ -13,7 +19,7 @@
# Recipes can also configure which entries in their ${WORKDIR}
# are preserved besides temp, which already gets excluded by default
# because it contains logs:
-# do_install_append () {
+# do_install:append () {
# echo "bar" >${WORKDIR}/foo
# }
# RM_WORK_EXCLUDE_ITEMS += "foo"
@@ -24,9 +30,16 @@ RM_WORK_EXCLUDE_ITEMS = "temp"
BB_SCHEDULER ?= "completion"
# Run the rm_work task in the idle scheduling class
-BB_TASK_IONICE_LEVEL_task-rm_work = "3.0"
+BB_TASK_IONICE_LEVEL:task-rm_work = "3.0"
do_rm_work () {
+ # Force using the HOSTTOOLS 'rm' - otherwise the SYSROOT_NATIVE 'rm' can be selected depending on PATH
+ # Avoids race-condition accessing 'rm' when deleting WORKDIR folders at the end of this function
+ RM_BIN="$(PATH=${HOSTTOOLS_DIR} command -v rm)"
+ if [ -z "${RM_BIN}" ]; then
+ bbfatal "Binary 'rm' not found in HOSTTOOLS_DIR, cannot remove WORKDIR data."
+ fi
+
# If the recipe name is in the RM_WORK_EXCLUDE, skip the recipe.
for p in ${RM_WORK_EXCLUDE}; do
if [ "$p" = "${PN}" ]; then
@@ -44,64 +57,58 @@ do_rm_work () {
# Change normal stamps into setscene stamps as they better reflect the
# fact WORKDIR is now empty
# Also leave noexec stamps since setscene stamps don't cover them
- cd `dirname ${STAMP}`
- for i in `basename ${STAMP}`*
- do
- for j in ${SSTATETASKS} do_shared_workdir
+ STAMPDIR=`dirname ${STAMP}`
+ if test -d $STAMPDIR; then
+ cd $STAMPDIR
+ for i in `basename ${STAMP}`*
do
case $i in
- *do_setscene*)
- break
- ;;
*sigdata*|*sigbasedata*)
- i=dummy
- break
+ # Save/skip anything that looks like a signature data file.
;;
- *do_package_write*)
- i=dummy
- break
+ *do_image_complete_setscene*|*do_image_qa_setscene*)
+ # Ensure we don't 'stack' setscene extensions to these stamps with the sections below
;;
*do_image_complete*)
+ # Promote do_image_complete stamps to setscene versions (ahead of *do_image* below)
mv $i `echo $i | sed -e "s#do_image_complete#do_image_complete_setscene#"`
- i=dummy
- break
;;
- *do_rootfs*|*do_image*|*do_bootimg*|*do_write_qemuboot_conf*)
- i=dummy
- break
+ *do_image_qa*)
+ # Promote do_image_qa stamps to setscene versions (ahead of *do_image* below)
+ mv $i `echo $i | sed -e "s#do_image_qa#do_image_qa_setscene#"`
;;
- *do_build*)
- i=dummy
- break
+ *do_package_write*|*do_rootfs*|*do_image*|*do_bootimg*|*do_write_qemuboot_conf*|*do_build*)
;;
*do_addto_recipe_sysroot*)
# Preserve recipe-sysroot-native if do_addto_recipe_sysroot has been used
excludes="$excludes recipe-sysroot-native"
- i=dummy
- break
;;
- # We remove do_package entirely, including any
- # sstate version since otherwise we'd need to leave 'plaindirs' around
- # such as 'packages' and 'packages-split' and these can be large. No end
- # of chain tasks depend directly on do_package anymore.
*do_package|*do_package.*|*do_package_setscene.*)
- rm -f $i;
- i=dummy
- break
+ # We remove do_package entirely, including any
+ # sstate version since otherwise we'd need to leave 'plaindirs' around
+ # such as 'packages' and 'packages-split' and these can be large. No end
+ # of chain tasks depend directly on do_package anymore.
+ "${RM_BIN}" -f -- $i;
;;
*_setscene*)
- i=dummy
- break
+ # Skip stamps which are already setscene versions
;;
- *$j|*$j.*)
- mv $i `echo $i | sed -e "s#${j}#${j}_setscene#"`
- i=dummy
- break
- ;;
+ *)
+ # For everything else: if suitable, promote the stamp to a setscene
+ # version, otherwise remove it
+ for j in ${SSTATETASKS} do_shared_workdir
+ do
+ case $i in
+ *$j|*$j.*)
+ mv $i `echo $i | sed -e "s#${j}#${j}_setscene#"`
+ break
+ ;;
+ esac
+ done
+ "${RM_BIN}" -f -- $i
esac
done
- rm -f $i
- done
+ fi
cd ${WORKDIR}
for dir in *
@@ -109,18 +116,20 @@ do_rm_work () {
# Retain only logs and other files in temp, safely ignore
# failures of removing pseudo folers on NFS2/3 server.
if [ $dir = 'pseudo' ]; then
- rm -rf $dir 2> /dev/null || true
+ "${RM_BIN}" -rf -- $dir 2> /dev/null || true
elif ! echo "$excludes" | grep -q -w "$dir"; then
- rm -rf $dir
+ "${RM_BIN}" -rf -- $dir
fi
done
}
+do_rm_work[vardepsexclude] += "SSTATETASKS"
+
do_rm_work_all () {
:
}
do_rm_work_all[recrdeptask] = "do_rm_work"
do_rm_work_all[noexec] = "1"
-addtask rm_work_all after before do_build
+addtask rm_work_all before do_build
do_populate_sdk[postfuncs] += "rm_work_populatesdk"
rm_work_populatesdk () {
@@ -163,8 +172,11 @@ python inject_rm_work() {
# Determine what do_build depends upon, without including do_build
# itself or our own special do_rm_work_all.
- deps = set(bb.build.preceedtask('do_build', True, d))
- deps.difference_update(('do_build', 'do_rm_work_all'))
+ deps = sorted((set(bb.build.preceedtask('do_build', True, d))).difference(('do_build', 'do_rm_work_all')) or "")
+
+ # deps can be empty if do_build doesn't exist, e.g. *-inital recipes
+ if not deps:
+ deps = ["do_populate_sysroot", "do_populate_lic"]
if pn in excludes:
d.delVarFlag('rm_work_rootfs', 'cleandirs')
@@ -178,7 +190,7 @@ python inject_rm_work() {
# other recipes and thus will typically run much later than completion of
# work in the recipe itself.
# In practice, addtask() here merely updates the dependencies.
- bb.build.addtask('do_rm_work', 'do_build', ' '.join(deps), d)
+ bb.build.addtask('do_rm_work', 'do_rm_work_all do_build', ' '.join(deps), d)
# Always update do_build_without_rm_work dependencies.
bb.build.addtask('do_build_without_rm_work', '', ' '.join(deps), d)