blob: b71a9d1cf85a98d47f716df3cdbe42947ac7ee32 [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#
13
14# Use the completion scheduler by default when rm_work is active
15# to try and reduce disk usage
16BB_SCHEDULER ?= "completion"
17
Patrick Williamsc0f7c042017-02-23 20:41:17 -060018# Run the rm_work task in the idle scheduling class
19BB_TASK_IONICE_LEVEL_task-rm_work = "3.0"
20
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021RMWORK_ORIG_TASK := "${BB_DEFAULT_TASK}"
22BB_DEFAULT_TASK = "rm_work_all"
23
24do_rm_work () {
25 # If the recipe name is in the RM_WORK_EXCLUDE, skip the recipe.
26 for p in ${RM_WORK_EXCLUDE}; do
27 if [ "$p" = "${PN}" ]; then
28 bbnote "rm_work: Skipping ${PN} since it is in RM_WORK_EXCLUDE"
29 exit 0
30 fi
31 done
32
33 cd ${WORKDIR}
34 for dir in *
35 do
36 # Retain only logs and other files in temp, safely ignore
37 # failures of removing pseudo folers on NFS2/3 server.
38 if [ $dir = 'pseudo' ]; then
39 rm -rf $dir 2> /dev/null || true
40 elif [ $dir != 'temp' ]; then
41 rm -rf $dir
42 fi
43 done
44
45 # Need to add pseudo back or subsqeuent work in this workdir
46 # might fail since setscene may not rerun to recreate it
47 mkdir -p ${WORKDIR}/pseudo/
48
49 # Change normal stamps into setscene stamps as they better reflect the
50 # fact WORKDIR is now empty
51 # Also leave noexec stamps since setscene stamps don't cover them
52 cd `dirname ${STAMP}`
53 for i in `basename ${STAMP}`*
54 do
55 for j in ${SSTATETASKS} do_shared_workdir
56 do
57 case $i in
58 *do_setscene*)
59 break
60 ;;
61 *sigdata*)
62 i=dummy
63 break
64 ;;
65 *do_package_write*)
66 i=dummy
67 break
68 ;;
Patrick Williamsc0f7c042017-02-23 20:41:17 -060069 *do_rootfs*|*do_image*|*do_bootimg*|*do_bootdirectdisk*|*do_vmimg*)
70 i=dummy
71 break
72 ;;
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073 *do_build*)
74 i=dummy
75 break
76 ;;
77 # We remove do_package entirely, including any
78 # sstate version since otherwise we'd need to leave 'plaindirs' around
79 # such as 'packages' and 'packages-split' and these can be large. No end
80 # of chain tasks depend directly on do_package anymore.
81 *do_package|*do_package.*|*do_package_setscene.*)
82 rm -f $i;
83 i=dummy
84 break
85 ;;
86 *_setscene*)
87 i=dummy
88 break
89 ;;
90 *$j|*$j.*)
91 mv $i `echo $i | sed -e "s#${j}#${j}_setscene#"`
92 i=dummy
93 break
94 ;;
95 esac
96 done
97 rm -f $i
98 done
99}
100addtask rm_work after do_${RMWORK_ORIG_TASK}
101
102do_rm_work_all () {
103 :
104}
105do_rm_work_all[recrdeptask] = "do_rm_work"
106addtask rm_work_all after do_rm_work
107
108do_populate_sdk[postfuncs] += "rm_work_populatesdk"
109rm_work_populatesdk () {
110 :
111}
112rm_work_populatesdk[cleandirs] = "${WORKDIR}/sdk"
113
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500114do_image_complete[postfuncs] += "rm_work_rootfs"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500115rm_work_rootfs () {
116 :
117}
118rm_work_rootfs[cleandirs] = "${WORKDIR}/rootfs"
119
120python () {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600121 if bb.data.inherits_class('kernel', d):
122 d.appendVar("RM_WORK_EXCLUDE", ' ' + d.getVar("PN", True))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500123 # If the recipe name is in the RM_WORK_EXCLUDE, skip the recipe.
124 excludes = (d.getVar("RM_WORK_EXCLUDE", True) or "").split()
125 pn = d.getVar("PN", True)
126 if pn in excludes:
127 d.delVarFlag('rm_work_rootfs', 'cleandirs')
128 d.delVarFlag('rm_work_populatesdk', 'cleandirs')
129}