Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 13 | # 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" |
| 20 | RM_WORK_EXCLUDE_ITEMS = "temp" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 | |
| 22 | # Use the completion scheduler by default when rm_work is active |
| 23 | # to try and reduce disk usage |
| 24 | BB_SCHEDULER ?= "completion" |
| 25 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 26 | # Run the rm_work task in the idle scheduling class |
| 27 | BB_TASK_IONICE_LEVEL_task-rm_work = "3.0" |
| 28 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 29 | do_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 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 38 | # Need to add pseudo back or subsqeuent work in this workdir |
| 39 | # might fail since setscene may not rerun to recreate it |
| 40 | mkdir -p ${WORKDIR}/pseudo/ |
| 41 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 42 | excludes='${RM_WORK_EXCLUDE_ITEMS}' |
| 43 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | # Change normal stamps into setscene stamps as they better reflect the |
| 45 | # fact WORKDIR is now empty |
| 46 | # Also leave noexec stamps since setscene stamps don't cover them |
| 47 | cd `dirname ${STAMP}` |
| 48 | for i in `basename ${STAMP}`* |
| 49 | do |
| 50 | for j in ${SSTATETASKS} do_shared_workdir |
| 51 | do |
| 52 | case $i in |
| 53 | *do_setscene*) |
| 54 | break |
| 55 | ;; |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 56 | *sigdata*|*sigbasedata*) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | i=dummy |
| 58 | break |
| 59 | ;; |
| 60 | *do_package_write*) |
| 61 | i=dummy |
| 62 | break |
| 63 | ;; |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 64 | *do_image_complete*) |
| 65 | mv $i `echo $i | sed -e "s#do_image_complete#do_image_complete_setscene#"` |
| 66 | i=dummy |
| 67 | break |
| 68 | ;; |
| 69 | *do_rootfs*|*do_image*|*do_bootimg*|*do_write_qemuboot_conf*) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 70 | i=dummy |
| 71 | break |
| 72 | ;; |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | *do_build*) |
| 74 | i=dummy |
| 75 | break |
| 76 | ;; |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 77 | *do_addto_recipe_sysroot*) |
| 78 | # Preserve recipe-sysroot-native if do_addto_recipe_sysroot has been used |
| 79 | excludes="$excludes recipe-sysroot-native" |
| 80 | i=dummy |
| 81 | break |
| 82 | ;; |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 83 | # We remove do_package entirely, including any |
| 84 | # sstate version since otherwise we'd need to leave 'plaindirs' around |
| 85 | # such as 'packages' and 'packages-split' and these can be large. No end |
| 86 | # of chain tasks depend directly on do_package anymore. |
| 87 | *do_package|*do_package.*|*do_package_setscene.*) |
| 88 | rm -f $i; |
| 89 | i=dummy |
| 90 | break |
| 91 | ;; |
| 92 | *_setscene*) |
| 93 | i=dummy |
| 94 | break |
| 95 | ;; |
| 96 | *$j|*$j.*) |
| 97 | mv $i `echo $i | sed -e "s#${j}#${j}_setscene#"` |
| 98 | i=dummy |
| 99 | break |
| 100 | ;; |
| 101 | esac |
| 102 | done |
| 103 | rm -f $i |
| 104 | done |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 105 | |
| 106 | cd ${WORKDIR} |
| 107 | for dir in * |
| 108 | do |
| 109 | # Retain only logs and other files in temp, safely ignore |
| 110 | # failures of removing pseudo folers on NFS2/3 server. |
| 111 | if [ $dir = 'pseudo' ]; then |
| 112 | rm -rf $dir 2> /dev/null || true |
| 113 | elif ! echo "$excludes" | grep -q -w "$dir"; then |
| 114 | rm -rf $dir |
| 115 | fi |
| 116 | done |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 118 | do_rm_work_all () { |
| 119 | : |
| 120 | } |
| 121 | do_rm_work_all[recrdeptask] = "do_rm_work" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 122 | do_rm_work_all[noexec] = "1" |
| 123 | addtask rm_work_all after before do_build |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 124 | |
| 125 | do_populate_sdk[postfuncs] += "rm_work_populatesdk" |
| 126 | rm_work_populatesdk () { |
| 127 | : |
| 128 | } |
| 129 | rm_work_populatesdk[cleandirs] = "${WORKDIR}/sdk" |
| 130 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 131 | do_image_complete[postfuncs] += "rm_work_rootfs" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 132 | rm_work_rootfs () { |
| 133 | : |
| 134 | } |
| 135 | rm_work_rootfs[cleandirs] = "${WORKDIR}/rootfs" |
| 136 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 137 | # This task can be used instead of do_build to trigger building |
| 138 | # without also invoking do_rm_work. It only exists when rm_work.bbclass |
| 139 | # is active, otherwise do_build needs to be used. |
| 140 | # |
| 141 | # The intended usage is |
| 142 | # ${@ d.getVar('RM_WORK_BUILD_WITHOUT') or 'do_build'} |
| 143 | # in places that previously used just 'do_build'. |
| 144 | RM_WORK_BUILD_WITHOUT = "do_build_without_rm_work" |
| 145 | do_build_without_rm_work () { |
| 146 | : |
| 147 | } |
| 148 | do_build_without_rm_work[noexec] = "1" |
| 149 | |
| 150 | # We have to add these tasks already now, because all tasks are |
| 151 | # meant to be defined before the RecipeTaskPreProcess event triggers. |
| 152 | # The inject_rm_work event handler then merely changes task dependencies. |
| 153 | addtask do_rm_work |
| 154 | addtask do_build_without_rm_work |
| 155 | addhandler inject_rm_work |
| 156 | inject_rm_work[eventmask] = "bb.event.RecipeTaskPreProcess" |
| 157 | python inject_rm_work() { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 158 | if bb.data.inherits_class('kernel', d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 159 | d.appendVar("RM_WORK_EXCLUDE", ' ' + d.getVar("PN")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 160 | # If the recipe name is in the RM_WORK_EXCLUDE, skip the recipe. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 161 | excludes = (d.getVar("RM_WORK_EXCLUDE") or "").split() |
| 162 | pn = d.getVar("PN") |
| 163 | |
| 164 | # Determine what do_build depends upon, without including do_build |
| 165 | # itself or our own special do_rm_work_all. |
| 166 | deps = set(bb.build.preceedtask('do_build', True, d)) |
| 167 | deps.difference_update(('do_build', 'do_rm_work_all')) |
| 168 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 169 | # deps can be empty if do_build doesn't exist, e.g. *-inital recipes |
| 170 | if not deps: |
| 171 | deps = ["do_populate_sysroot", "do_populate_lic"] |
| 172 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 173 | if pn in excludes: |
| 174 | d.delVarFlag('rm_work_rootfs', 'cleandirs') |
| 175 | d.delVarFlag('rm_work_populatesdk', 'cleandirs') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 176 | else: |
| 177 | # Inject do_rm_work into the tasks of the current recipe such that do_build |
| 178 | # depends on it and that it runs after all other tasks that block do_build, |
| 179 | # i.e. after all work on the current recipe is done. The reason for taking |
| 180 | # this approach instead of making do_rm_work depend on do_build is that |
| 181 | # do_build inherits additional runtime dependencies on |
| 182 | # other recipes and thus will typically run much later than completion of |
| 183 | # work in the recipe itself. |
| 184 | # In practice, addtask() here merely updates the dependencies. |
| 185 | bb.build.addtask('do_rm_work', 'do_build', ' '.join(deps), d) |
| 186 | |
| 187 | # Always update do_build_without_rm_work dependencies. |
| 188 | bb.build.addtask('do_build_without_rm_work', '', ' '.join(deps), d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 189 | } |