blob: c647d88d267b1cba02f85cbeecec0e806b65789e [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 ;;
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050066 *do_rootfs*)
67 i=dummy
68 break
69 ;;
70 *do_image*)
71 i=dummy
72 break
73 ;;
Patrick Williamsc124f4f2015-09-15 14:41:29 -050074 *do_build*)
75 i=dummy
76 break
77 ;;
78 # We remove do_package entirely, including any
79 # sstate version since otherwise we'd need to leave 'plaindirs' around
80 # such as 'packages' and 'packages-split' and these can be large. No end
81 # of chain tasks depend directly on do_package anymore.
82 *do_package|*do_package.*|*do_package_setscene.*)
83 rm -f $i;
84 i=dummy
85 break
86 ;;
87 *_setscene*)
88 i=dummy
89 break
90 ;;
91 *$j|*$j.*)
92 mv $i `echo $i | sed -e "s#${j}#${j}_setscene#"`
93 i=dummy
94 break
95 ;;
96 esac
97 done
98 rm -f $i
99 done
100}
101addtask rm_work after do_${RMWORK_ORIG_TASK}
102
103do_rm_work_all () {
104 :
105}
106do_rm_work_all[recrdeptask] = "do_rm_work"
107addtask rm_work_all after do_rm_work
108
109do_populate_sdk[postfuncs] += "rm_work_populatesdk"
110rm_work_populatesdk () {
111 :
112}
113rm_work_populatesdk[cleandirs] = "${WORKDIR}/sdk"
114
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500115do_image_complete[postfuncs] += "rm_work_rootfs"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116rm_work_rootfs () {
117 :
118}
119rm_work_rootfs[cleandirs] = "${WORKDIR}/rootfs"
120
121python () {
122 # If the recipe name is in the RM_WORK_EXCLUDE, skip the recipe.
123 excludes = (d.getVar("RM_WORK_EXCLUDE", True) or "").split()
124 pn = d.getVar("PN", True)
125 if pn in excludes:
126 d.delVarFlag('rm_work_rootfs', 'cleandirs')
127 d.delVarFlag('rm_work_populatesdk', 'cleandirs')
128}