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.bbclass126
1 files changed, 72 insertions, 54 deletions
diff --git a/meta/classes/rm_work.bbclass b/meta/classes/rm_work.bbclass
index 01c2ab1c78..52ecfafb72 100644
--- a/meta/classes/rm_work.bbclass
+++ b/meta/classes/rm_work.bbclass
@@ -1,4 +1,10 @@
1# 1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7#
2# Removes source after build 8# Removes source after build
3# 9#
4# To use it add that line to conf/local.conf: 10# To use it add that line to conf/local.conf:
@@ -13,7 +19,7 @@
13# Recipes can also configure which entries in their ${WORKDIR} 19# Recipes can also configure which entries in their ${WORKDIR}
14# are preserved besides temp, which already gets excluded by default 20# are preserved besides temp, which already gets excluded by default
15# because it contains logs: 21# because it contains logs:
16# do_install_append () { 22# do_install:append () {
17# echo "bar" >${WORKDIR}/foo 23# echo "bar" >${WORKDIR}/foo
18# } 24# }
19# RM_WORK_EXCLUDE_ITEMS += "foo" 25# RM_WORK_EXCLUDE_ITEMS += "foo"
@@ -24,9 +30,16 @@ RM_WORK_EXCLUDE_ITEMS = "temp"
24BB_SCHEDULER ?= "completion" 30BB_SCHEDULER ?= "completion"
25 31
26# Run the rm_work task in the idle scheduling class 32# Run the rm_work task in the idle scheduling class
27BB_TASK_IONICE_LEVEL_task-rm_work = "3.0" 33BB_TASK_IONICE_LEVEL:task-rm_work = "3.0"
28 34
29do_rm_work () { 35do_rm_work () {
36 # Force using the HOSTTOOLS 'rm' - otherwise the SYSROOT_NATIVE 'rm' can be selected depending on PATH
37 # Avoids race-condition accessing 'rm' when deleting WORKDIR folders at the end of this function
38 RM_BIN="$(PATH=${HOSTTOOLS_DIR} command -v rm)"
39 if [ -z "${RM_BIN}" ]; then
40 bbfatal "Binary 'rm' not found in HOSTTOOLS_DIR, cannot remove WORKDIR data."
41 fi
42
30 # If the recipe name is in the RM_WORK_EXCLUDE, skip the recipe. 43 # If the recipe name is in the RM_WORK_EXCLUDE, skip the recipe.
31 for p in ${RM_WORK_EXCLUDE}; do 44 for p in ${RM_WORK_EXCLUDE}; do
32 if [ "$p" = "${PN}" ]; then 45 if [ "$p" = "${PN}" ]; then
@@ -44,55 +57,58 @@ do_rm_work () {
44 # Change normal stamps into setscene stamps as they better reflect the 57 # Change normal stamps into setscene stamps as they better reflect the
45 # fact WORKDIR is now empty 58 # fact WORKDIR is now empty
46 # Also leave noexec stamps since setscene stamps don't cover them 59 # Also leave noexec stamps since setscene stamps don't cover them
47 cd `dirname ${STAMP}` 60 STAMPDIR=`dirname ${STAMP}`
48 for i in `basename ${STAMP}`* 61 if test -d $STAMPDIR; then
49 do 62 cd $STAMPDIR
50 case $i in 63 for i in `basename ${STAMP}`*
51 *sigdata*|*sigbasedata*) 64 do
52 # Save/skip anything that looks like a signature data file. 65 case $i in
53 ;; 66 *sigdata*|*sigbasedata*)
54 *do_image_complete_setscene*|*do_image_qa_setscene*) 67 # Save/skip anything that looks like a signature data file.
55 # Ensure we don't 'stack' setscene extensions to these stamps with the sections below 68 ;;
56 ;; 69 *do_image_complete_setscene*|*do_image_qa_setscene*)
57 *do_image_complete*) 70 # Ensure we don't 'stack' setscene extensions to these stamps with the sections below
58 # Promote do_image_complete stamps to setscene versions (ahead of *do_image* below) 71 ;;
59 mv $i `echo $i | sed -e "s#do_image_complete#do_image_complete_setscene#"` 72 *do_image_complete*)
60 ;; 73 # Promote do_image_complete stamps to setscene versions (ahead of *do_image* below)
61 *do_image_qa*) 74 mv $i `echo $i | sed -e "s#do_image_complete#do_image_complete_setscene#"`
62 # Promote do_image_qa stamps to setscene versions (ahead of *do_image* below) 75 ;;
63 mv $i `echo $i | sed -e "s#do_image_qa#do_image_qa_setscene#"` 76 *do_image_qa*)
64 ;; 77 # Promote do_image_qa stamps to setscene versions (ahead of *do_image* below)
65 *do_package_write*|*do_rootfs*|*do_image*|*do_bootimg*|*do_write_qemuboot_conf*|*do_build*) 78 mv $i `echo $i | sed -e "s#do_image_qa#do_image_qa_setscene#"`
66 ;; 79 ;;
67 *do_addto_recipe_sysroot*) 80 *do_package_write*|*do_rootfs*|*do_image*|*do_bootimg*|*do_write_qemuboot_conf*|*do_build*)
68 # Preserve recipe-sysroot-native if do_addto_recipe_sysroot has been used 81 ;;
69 excludes="$excludes recipe-sysroot-native" 82 *do_addto_recipe_sysroot*)
70 ;; 83 # Preserve recipe-sysroot-native if do_addto_recipe_sysroot has been used
71 *do_package|*do_package.*|*do_package_setscene.*) 84 excludes="$excludes recipe-sysroot-native"
72 # We remove do_package entirely, including any 85 ;;
73 # sstate version since otherwise we'd need to leave 'plaindirs' around 86 *do_package|*do_package.*|*do_package_setscene.*)
74 # such as 'packages' and 'packages-split' and these can be large. No end 87 # We remove do_package entirely, including any
75 # of chain tasks depend directly on do_package anymore. 88 # sstate version since otherwise we'd need to leave 'plaindirs' around
76 rm -f $i; 89 # such as 'packages' and 'packages-split' and these can be large. No end
77 ;; 90 # of chain tasks depend directly on do_package anymore.
78 *_setscene*) 91 "${RM_BIN}" -f -- $i;
79 # Skip stamps which are already setscene versions 92 ;;
80 ;; 93 *_setscene*)
81 *) 94 # Skip stamps which are already setscene versions
82 # For everything else: if suitable, promote the stamp to a setscene 95 ;;
83 # version, otherwise remove it 96 *)
84 for j in ${SSTATETASKS} do_shared_workdir 97 # For everything else: if suitable, promote the stamp to a setscene
85 do 98 # version, otherwise remove it
86 case $i in 99 for j in ${SSTATETASKS} do_shared_workdir
87 *$j|*$j.*) 100 do
88 mv $i `echo $i | sed -e "s#${j}#${j}_setscene#"` 101 case $i in
89 break 102 *$j|*$j.*)
90 ;; 103 mv $i `echo $i | sed -e "s#${j}#${j}_setscene#"`
91 esac 104 break
92 done 105 ;;
93 rm -f $i 106 esac
94 esac 107 done
95 done 108 "${RM_BIN}" -f -- $i
109 esac
110 done
111 fi
96 112
97 cd ${WORKDIR} 113 cd ${WORKDIR}
98 for dir in * 114 for dir in *
@@ -100,12 +116,14 @@ do_rm_work () {
100 # Retain only logs and other files in temp, safely ignore 116 # Retain only logs and other files in temp, safely ignore
101 # failures of removing pseudo folers on NFS2/3 server. 117 # failures of removing pseudo folers on NFS2/3 server.
102 if [ $dir = 'pseudo' ]; then 118 if [ $dir = 'pseudo' ]; then
103 rm -rf $dir 2> /dev/null || true 119 "${RM_BIN}" -rf -- $dir 2> /dev/null || true
104 elif ! echo "$excludes" | grep -q -w "$dir"; then 120 elif ! echo "$excludes" | grep -q -w "$dir"; then
105 rm -rf $dir 121 "${RM_BIN}" -rf -- $dir
106 fi 122 fi
107 done 123 done
108} 124}
125do_rm_work[vardepsexclude] += "SSTATETASKS"
126
109do_rm_work_all () { 127do_rm_work_all () {
110 : 128 :
111} 129}
@@ -172,7 +190,7 @@ python inject_rm_work() {
172 # other recipes and thus will typically run much later than completion of 190 # other recipes and thus will typically run much later than completion of
173 # work in the recipe itself. 191 # work in the recipe itself.
174 # In practice, addtask() here merely updates the dependencies. 192 # In practice, addtask() here merely updates the dependencies.
175 bb.build.addtask('do_rm_work', 'do_build', ' '.join(deps), d) 193 bb.build.addtask('do_rm_work', 'do_rm_work_all do_build', ' '.join(deps), d)
176 194
177 # Always update do_build_without_rm_work dependencies. 195 # Always update do_build_without_rm_work dependencies.
178 bb.build.addtask('do_build_without_rm_work', '', ' '.join(deps), d) 196 bb.build.addtask('do_build_without_rm_work', '', ' '.join(deps), d)