blob: badeaeba07c1286062ff667b3c5caf4227f8d504 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
2# Removes source after build
3#
4# To use it add that line to conf/local.conf:
5#
6# INHERIT += "rm_work"
7#
8# To inhibit rm_work for some recipes, specify them in RM_WORK_EXCLUDE.
9# For example, in conf/local.conf:
10#
11# RM_WORK_EXCLUDE += "icu-native icu busybox"
12#
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013# Recipes can also configure which entries in their ${WORKDIR}
14# are preserved besides temp, which already gets excluded by default
15# because it contains logs:
16# do_install_append () {
17# echo "bar" >${WORKDIR}/foo
18# }
19# RM_WORK_EXCLUDE_ITEMS += "foo"
20RM_WORK_EXCLUDE_ITEMS = "temp"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021
22# Use the completion scheduler by default when rm_work is active
23# to try and reduce disk usage
24BB_SCHEDULER ?= "completion"
25
Patrick Williamsc0f7c042017-02-23 20:41:17 -060026# Run the rm_work task in the idle scheduling class
27BB_TASK_IONICE_LEVEL_task-rm_work = "3.0"
28
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029do_rm_work () {
30 # If the recipe name is in the RM_WORK_EXCLUDE, skip the recipe.
31 for p in ${RM_WORK_EXCLUDE}; do
32 if [ "$p" = "${PN}" ]; then
33 bbnote "rm_work: Skipping ${PN} since it is in RM_WORK_EXCLUDE"
34 exit 0
35 fi
36 done
37
38 cd ${WORKDIR}
39 for dir in *
40 do
41 # Retain only logs and other files in temp, safely ignore
42 # failures of removing pseudo folers on NFS2/3 server.
43 if [ $dir = 'pseudo' ]; then
44 rm -rf $dir 2> /dev/null || true
Brad Bishop6e60e8b2018-02-01 10:27:11 -050045 elif ! echo '${RM_WORK_EXCLUDE_ITEMS}' | grep -q -w "$dir"; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046 rm -rf $dir
47 fi
48 done
49
50 # Need to add pseudo back or subsqeuent work in this workdir
51 # might fail since setscene may not rerun to recreate it
52 mkdir -p ${WORKDIR}/pseudo/
53
54 # Change normal stamps into setscene stamps as they better reflect the
55 # fact WORKDIR is now empty
56 # Also leave noexec stamps since setscene stamps don't cover them
57 cd `dirname ${STAMP}`
58 for i in `basename ${STAMP}`*
59 do
60 for j in ${SSTATETASKS} do_shared_workdir
61 do
62 case $i in
63 *do_setscene*)
64 break
65 ;;
Brad Bishop37a0e4d2017-12-04 01:01:44 -050066 *sigdata*|*sigbasedata*)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 i=dummy
68 break
69 ;;
70 *do_package_write*)
71 i=dummy
72 break
73 ;;
Brad Bishop6e60e8b2018-02-01 10:27:11 -050074 *do_rootfs*|*do_image*|*do_bootimg*|*do_bootdirectdisk*|*do_vmimg*|*do_write_qemuboot_conf*)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060075 i=dummy
76 break
77 ;;
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078 *do_build*)
79 i=dummy
80 break
81 ;;
82 # We remove do_package entirely, including any
83 # sstate version since otherwise we'd need to leave 'plaindirs' around
84 # such as 'packages' and 'packages-split' and these can be large. No end
85 # of chain tasks depend directly on do_package anymore.
86 *do_package|*do_package.*|*do_package_setscene.*)
87 rm -f $i;
88 i=dummy
89 break
90 ;;
91 *_setscene*)
92 i=dummy
93 break
94 ;;
95 *$j|*$j.*)
96 mv $i `echo $i | sed -e "s#${j}#${j}_setscene#"`
97 i=dummy
98 break
99 ;;
100 esac
101 done
102 rm -f $i
103 done
104}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105do_rm_work_all () {
106 :
107}
108do_rm_work_all[recrdeptask] = "do_rm_work"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500109do_rm_work_all[noexec] = "1"
110addtask rm_work_all after before do_build
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500111
112do_populate_sdk[postfuncs] += "rm_work_populatesdk"
113rm_work_populatesdk () {
114 :
115}
116rm_work_populatesdk[cleandirs] = "${WORKDIR}/sdk"
117
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500118do_image_complete[postfuncs] += "rm_work_rootfs"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119rm_work_rootfs () {
120 :
121}
122rm_work_rootfs[cleandirs] = "${WORKDIR}/rootfs"
123
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500124# This task can be used instead of do_build to trigger building
125# without also invoking do_rm_work. It only exists when rm_work.bbclass
126# is active, otherwise do_build needs to be used.
127#
128# The intended usage is
129# ${@ d.getVar('RM_WORK_BUILD_WITHOUT') or 'do_build'}
130# in places that previously used just 'do_build'.
131RM_WORK_BUILD_WITHOUT = "do_build_without_rm_work"
132do_build_without_rm_work () {
133 :
134}
135do_build_without_rm_work[noexec] = "1"
136
137# We have to add these tasks already now, because all tasks are
138# meant to be defined before the RecipeTaskPreProcess event triggers.
139# The inject_rm_work event handler then merely changes task dependencies.
140addtask do_rm_work
141addtask do_build_without_rm_work
142addhandler inject_rm_work
143inject_rm_work[eventmask] = "bb.event.RecipeTaskPreProcess"
144python inject_rm_work() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600145 if bb.data.inherits_class('kernel', d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500146 d.appendVar("RM_WORK_EXCLUDE", ' ' + d.getVar("PN"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500147 # If the recipe name is in the RM_WORK_EXCLUDE, skip the recipe.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500148 excludes = (d.getVar("RM_WORK_EXCLUDE") or "").split()
149 pn = d.getVar("PN")
150
151 # Determine what do_build depends upon, without including do_build
152 # itself or our own special do_rm_work_all.
153 deps = set(bb.build.preceedtask('do_build', True, d))
154 deps.difference_update(('do_build', 'do_rm_work_all'))
155
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500156 if pn in excludes:
157 d.delVarFlag('rm_work_rootfs', 'cleandirs')
158 d.delVarFlag('rm_work_populatesdk', 'cleandirs')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500159 else:
160 # Inject do_rm_work into the tasks of the current recipe such that do_build
161 # depends on it and that it runs after all other tasks that block do_build,
162 # i.e. after all work on the current recipe is done. The reason for taking
163 # this approach instead of making do_rm_work depend on do_build is that
164 # do_build inherits additional runtime dependencies on
165 # other recipes and thus will typically run much later than completion of
166 # work in the recipe itself.
167 # In practice, addtask() here merely updates the dependencies.
168 bb.build.addtask('do_rm_work', 'do_build', ' '.join(deps), d)
169
170 # Always update do_build_without_rm_work dependencies.
171 bb.build.addtask('do_build_without_rm_work', '', ' '.join(deps), d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500172}