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