Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | SSTATE_VERSION = "3" |
| 2 | |
| 3 | SSTATE_MANIFESTS ?= "${TMPDIR}/sstate-control" |
| 4 | SSTATE_MANFILEPREFIX = "${SSTATE_MANIFESTS}/manifest-${SSTATE_MANMACH}-${PN}" |
| 5 | |
| 6 | def generate_sstatefn(spec, hash, d): |
| 7 | if not hash: |
| 8 | hash = "INVALID" |
| 9 | return hash[:2] + "/" + spec + hash |
| 10 | |
| 11 | SSTATE_PKGARCH = "${PACKAGE_ARCH}" |
| 12 | SSTATE_PKGSPEC = "sstate:${PN}:${PACKAGE_ARCH}${TARGET_VENDOR}-${TARGET_OS}:${PV}:${PR}:${SSTATE_PKGARCH}:${SSTATE_VERSION}:" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 13 | SSTATE_SWSPEC = "sstate:${PN}::${PV}:${PR}::${SSTATE_VERSION}:" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 14 | SSTATE_PKGNAME = "${SSTATE_EXTRAPATH}${@generate_sstatefn(d.getVar('SSTATE_PKGSPEC'), d.getVar('BB_UNIHASH'), d)}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | SSTATE_PKG = "${SSTATE_DIR}/${SSTATE_PKGNAME}" |
| 16 | SSTATE_EXTRAPATH = "" |
| 17 | SSTATE_EXTRAPATHWILDCARD = "" |
| 18 | SSTATE_PATHSPEC = "${SSTATE_DIR}/${SSTATE_EXTRAPATHWILDCARD}*/${SSTATE_PKGSPEC}" |
| 19 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 20 | # explicitly make PV to depend on evaluated value of PV variable |
| 21 | PV[vardepvalue] = "${PV}" |
| 22 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | # We don't want the sstate to depend on things like the distro string |
| 24 | # of the system, we let the sstate paths take care of this. |
| 25 | SSTATE_EXTRAPATH[vardepvalue] = "" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 26 | SSTATE_EXTRAPATHWILDCARD[vardepvalue] = "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 27 | |
| 28 | # For multilib rpm the allarch packagegroup files can overwrite (in theory they're identical) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 29 | SSTATE_DUPWHITELIST = "${DEPLOY_DIR}/licenses/" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | # Avoid docbook/sgml catalog warnings for now |
| 31 | SSTATE_DUPWHITELIST += "${STAGING_ETCDIR_NATIVE}/sgml ${STAGING_DATADIR_NATIVE}/sgml" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 32 | # sdk-provides-dummy-nativesdk and nativesdk-buildtools-perl-dummy overlap for different SDKMACHINE |
| 33 | SSTATE_DUPWHITELIST += "${DEPLOY_DIR_RPM}/sdk_provides_dummy_nativesdk/ ${DEPLOY_DIR_IPK}/sdk-provides-dummy-nativesdk/" |
| 34 | SSTATE_DUPWHITELIST += "${DEPLOY_DIR_RPM}/buildtools_dummy_nativesdk/ ${DEPLOY_DIR_IPK}/buildtools-dummy-nativesdk/" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 35 | # target-sdk-provides-dummy overlaps that allarch is disabled when multilib is used |
| 36 | SSTATE_DUPWHITELIST += "${COMPONENTS_DIR}/sdk-provides-dummy-target/ ${DEPLOY_DIR_RPM}/sdk_provides_dummy_target/ ${DEPLOY_DIR_IPK}/sdk-provides-dummy-target/" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 | # Archive the sources for many architectures in one deploy folder |
| 38 | SSTATE_DUPWHITELIST += "${DEPLOY_DIR_SRC}" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 39 | # ovmf/grub-efi/systemd-boot/intel-microcode multilib recipes can generate identical overlapping files |
| 40 | SSTATE_DUPWHITELIST += "${DEPLOY_DIR_IMAGE}/ovmf" |
| 41 | SSTATE_DUPWHITELIST += "${DEPLOY_DIR_IMAGE}/grub-efi" |
| 42 | SSTATE_DUPWHITELIST += "${DEPLOY_DIR_IMAGE}/systemd-boot" |
| 43 | SSTATE_DUPWHITELIST += "${DEPLOY_DIR_IMAGE}/microcode" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 45 | SSTATE_SCAN_FILES ?= "*.la *-config *_config postinst-*" |
| 46 | SSTATE_SCAN_CMD ??= 'find ${SSTATE_BUILDDIR} \( -name "${@"\" -o -name \"".join(d.getVar("SSTATE_SCAN_FILES").split())}" \) -type f' |
| 47 | SSTATE_SCAN_CMD_NATIVE ??= 'grep -Irl -e ${RECIPE_SYSROOT} -e ${RECIPE_SYSROOT_NATIVE} -e ${HOSTTOOLS_DIR} ${SSTATE_BUILDDIR}' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 49 | BB_HASHFILENAME = "False ${SSTATE_PKGSPEC} ${SSTATE_SWSPEC}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 50 | |
| 51 | SSTATE_ARCHS = " \ |
| 52 | ${BUILD_ARCH} \ |
| 53 | ${BUILD_ARCH}_${SDK_ARCH}_${SDK_OS} \ |
| 54 | ${BUILD_ARCH}_${TARGET_ARCH} \ |
| 55 | ${SDK_ARCH}_${SDK_OS} \ |
| 56 | ${SDK_ARCH}_${PACKAGE_ARCH} \ |
| 57 | allarch \ |
| 58 | ${PACKAGE_ARCH} \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 59 | ${PACKAGE_EXTRA_ARCHS} \ |
| 60 | ${MACHINE_ARCH}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | |
| 62 | SSTATE_MANMACH ?= "${SSTATE_PKGARCH}" |
| 63 | |
| 64 | SSTATECREATEFUNCS = "sstate_hardcode_path" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 65 | SSTATECREATEFUNCS[vardeps] = "SSTATE_SCAN_FILES" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 66 | SSTATEPOSTCREATEFUNCS = "" |
| 67 | SSTATEPREINSTFUNCS = "" |
| 68 | SSTATEPOSTUNPACKFUNCS = "sstate_hardcode_path_unpack" |
| 69 | SSTATEPOSTINSTFUNCS = "" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 70 | EXTRA_STAGING_FIXMES ?= "HOSTTOOLS_DIR" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 71 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 72 | # Check whether sstate exists for tasks that support sstate and are in the |
| 73 | # locked signatures file. |
| 74 | SIGGEN_LOCKEDSIGS_SSTATE_EXISTS_CHECK ?= 'error' |
| 75 | |
| 76 | # Check whether the task's computed hash matches the task's hash in the |
| 77 | # locked signatures file. |
| 78 | SIGGEN_LOCKEDSIGS_TASKSIG_CHECK ?= "error" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 79 | |
| 80 | # The GnuPG key ID and passphrase to use to sign sstate archives (or unset to |
| 81 | # not sign) |
| 82 | SSTATE_SIG_KEY ?= "" |
| 83 | SSTATE_SIG_PASSPHRASE ?= "" |
| 84 | # Whether to verify the GnUPG signatures when extracting sstate archives |
| 85 | SSTATE_VERIFY_SIG ?= "0" |
| 86 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 87 | SSTATE_HASHEQUIV_METHOD ?= "oe.sstatesig.OEOuthashBasic" |
| 88 | SSTATE_HASHEQUIV_METHOD[doc] = "The fully-qualified function used to calculate \ |
| 89 | the output hash for a task, which in turn is used to determine equivalency. \ |
| 90 | " |
| 91 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 92 | SSTATE_HASHEQUIV_REPORT_TASKDATA ?= "0" |
| 93 | SSTATE_HASHEQUIV_REPORT_TASKDATA[doc] = "Report additional useful data to the \ |
| 94 | hash equivalency server, such as PN, PV, taskname, etc. This information \ |
| 95 | is very useful for developers looking at task data, but may leak sensitive \ |
| 96 | data if the equivalence server is public. \ |
| 97 | " |
| 98 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 99 | python () { |
| 100 | if bb.data.inherits_class('native', d): |
| 101 | d.setVar('SSTATE_PKGARCH', d.getVar('BUILD_ARCH', False)) |
| 102 | elif bb.data.inherits_class('crosssdk', d): |
| 103 | d.setVar('SSTATE_PKGARCH', d.expand("${BUILD_ARCH}_${SDK_ARCH}_${SDK_OS}")) |
| 104 | elif bb.data.inherits_class('cross', d): |
| 105 | d.setVar('SSTATE_PKGARCH', d.expand("${BUILD_ARCH}_${TARGET_ARCH}")) |
| 106 | elif bb.data.inherits_class('nativesdk', d): |
| 107 | d.setVar('SSTATE_PKGARCH', d.expand("${SDK_ARCH}_${SDK_OS}")) |
| 108 | elif bb.data.inherits_class('cross-canadian', d): |
| 109 | d.setVar('SSTATE_PKGARCH', d.expand("${SDK_ARCH}_${PACKAGE_ARCH}")) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 110 | elif bb.data.inherits_class('allarch', d) and d.getVar("PACKAGE_ARCH") == "all": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 111 | d.setVar('SSTATE_PKGARCH', "allarch") |
| 112 | else: |
| 113 | d.setVar('SSTATE_MANMACH', d.expand("${PACKAGE_ARCH}")) |
| 114 | |
| 115 | if bb.data.inherits_class('native', d) or bb.data.inherits_class('crosssdk', d) or bb.data.inherits_class('cross', d): |
| 116 | d.setVar('SSTATE_EXTRAPATH', "${NATIVELSBSTRING}/") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 117 | d.setVar('BB_HASHFILENAME', "True ${SSTATE_PKGSPEC} ${SSTATE_SWSPEC}") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 118 | d.setVar('SSTATE_EXTRAPATHWILDCARD', "${NATIVELSBSTRING}/") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 119 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 120 | unique_tasks = sorted(set((d.getVar('SSTATETASKS') or "").split())) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 121 | d.setVar('SSTATETASKS', " ".join(unique_tasks)) |
| 122 | for task in unique_tasks: |
| 123 | d.prependVarFlag(task, 'prefuncs', "sstate_task_prefunc ") |
| 124 | d.appendVarFlag(task, 'postfuncs', " sstate_task_postfunc") |
| 125 | } |
| 126 | |
| 127 | def sstate_init(task, d): |
| 128 | ss = {} |
| 129 | ss['task'] = task |
| 130 | ss['dirs'] = [] |
| 131 | ss['plaindirs'] = [] |
| 132 | ss['lockfiles'] = [] |
| 133 | ss['lockfiles-shared'] = [] |
| 134 | return ss |
| 135 | |
| 136 | def sstate_state_fromvars(d, task = None): |
| 137 | if task is None: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 138 | task = d.getVar('BB_CURRENTTASK') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 139 | if not task: |
| 140 | bb.fatal("sstate code running without task context?!") |
| 141 | task = task.replace("_setscene", "") |
| 142 | |
| 143 | if task.startswith("do_"): |
| 144 | task = task[3:] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 145 | inputs = (d.getVarFlag("do_" + task, 'sstate-inputdirs') or "").split() |
| 146 | outputs = (d.getVarFlag("do_" + task, 'sstate-outputdirs') or "").split() |
| 147 | plaindirs = (d.getVarFlag("do_" + task, 'sstate-plaindirs') or "").split() |
| 148 | lockfiles = (d.getVarFlag("do_" + task, 'sstate-lockfile') or "").split() |
| 149 | lockfilesshared = (d.getVarFlag("do_" + task, 'sstate-lockfile-shared') or "").split() |
| 150 | interceptfuncs = (d.getVarFlag("do_" + task, 'sstate-interceptfuncs') or "").split() |
| 151 | fixmedir = d.getVarFlag("do_" + task, 'sstate-fixmedir') or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 152 | if not task or len(inputs) != len(outputs): |
| 153 | bb.fatal("sstate variables not setup correctly?!") |
| 154 | |
| 155 | if task == "populate_lic": |
| 156 | d.setVar("SSTATE_PKGSPEC", "${SSTATE_SWSPEC}") |
| 157 | d.setVar("SSTATE_EXTRAPATH", "") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 158 | d.setVar('SSTATE_EXTRAPATHWILDCARD', "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 159 | |
| 160 | ss = sstate_init(task, d) |
| 161 | for i in range(len(inputs)): |
| 162 | sstate_add(ss, inputs[i], outputs[i], d) |
| 163 | ss['lockfiles'] = lockfiles |
| 164 | ss['lockfiles-shared'] = lockfilesshared |
| 165 | ss['plaindirs'] = plaindirs |
| 166 | ss['interceptfuncs'] = interceptfuncs |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 167 | ss['fixmedir'] = fixmedir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 168 | return ss |
| 169 | |
| 170 | def sstate_add(ss, source, dest, d): |
| 171 | if not source.endswith("/"): |
| 172 | source = source + "/" |
| 173 | if not dest.endswith("/"): |
| 174 | dest = dest + "/" |
| 175 | source = os.path.normpath(source) |
| 176 | dest = os.path.normpath(dest) |
| 177 | srcbase = os.path.basename(source) |
| 178 | ss['dirs'].append([srcbase, source, dest]) |
| 179 | return ss |
| 180 | |
| 181 | def sstate_install(ss, d): |
| 182 | import oe.path |
| 183 | import oe.sstatesig |
| 184 | import subprocess |
| 185 | |
| 186 | sharedfiles = [] |
| 187 | shareddirs = [] |
| 188 | bb.utils.mkdirhier(d.expand("${SSTATE_MANIFESTS}")) |
| 189 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 190 | sstateinst = d.expand("${WORKDIR}/sstate-install-%s/" % ss['task']) |
| 191 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 192 | manifest, d2 = oe.sstatesig.sstate_get_manifest_filename(ss['task'], d) |
| 193 | |
| 194 | if os.access(manifest, os.R_OK): |
| 195 | bb.fatal("Package already staged (%s)?!" % manifest) |
| 196 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 197 | d.setVar("SSTATE_INST_POSTRM", manifest + ".postrm") |
| 198 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 199 | locks = [] |
| 200 | for lock in ss['lockfiles-shared']: |
| 201 | locks.append(bb.utils.lockfile(lock, True)) |
| 202 | for lock in ss['lockfiles']: |
| 203 | locks.append(bb.utils.lockfile(lock)) |
| 204 | |
| 205 | for state in ss['dirs']: |
| 206 | bb.debug(2, "Staging files from %s to %s" % (state[1], state[2])) |
| 207 | for walkroot, dirs, files in os.walk(state[1]): |
| 208 | for file in files: |
| 209 | srcpath = os.path.join(walkroot, file) |
| 210 | dstpath = srcpath.replace(state[1], state[2]) |
| 211 | #bb.debug(2, "Staging %s to %s" % (srcpath, dstpath)) |
| 212 | sharedfiles.append(dstpath) |
| 213 | for dir in dirs: |
| 214 | srcdir = os.path.join(walkroot, dir) |
| 215 | dstdir = srcdir.replace(state[1], state[2]) |
| 216 | #bb.debug(2, "Staging %s to %s" % (srcdir, dstdir)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 217 | if os.path.islink(srcdir): |
| 218 | sharedfiles.append(dstdir) |
| 219 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 220 | if not dstdir.endswith("/"): |
| 221 | dstdir = dstdir + "/" |
| 222 | shareddirs.append(dstdir) |
| 223 | |
| 224 | # Check the file list for conflicts against files which already exist |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 225 | whitelist = (d.getVar("SSTATE_DUPWHITELIST") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 226 | match = [] |
| 227 | for f in sharedfiles: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 228 | if os.path.exists(f) and not os.path.islink(f): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 229 | f = os.path.normpath(f) |
| 230 | realmatch = True |
| 231 | for w in whitelist: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 232 | w = os.path.normpath(w) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 233 | if f.startswith(w): |
| 234 | realmatch = False |
| 235 | break |
| 236 | if realmatch: |
| 237 | match.append(f) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 238 | sstate_search_cmd = "grep -rlF '%s' %s --exclude=master.list | sed -e 's:^.*/::'" % (f, d.expand("${SSTATE_MANIFESTS}")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 239 | search_output = subprocess.Popen(sstate_search_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 240 | if search_output: |
| 241 | match.append(" (matched in %s)" % search_output.decode('utf-8').rstrip()) |
| 242 | else: |
| 243 | match.append(" (not matched to any task)") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 244 | if match: |
| 245 | bb.error("The recipe %s is trying to install files into a shared " \ |
| 246 | "area when those files already exist. Those files and their manifest " \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 247 | "location are:\n %s\nPlease verify which recipe should provide the " \ |
| 248 | "above files.\n\nThe build has stopped, as continuing in this scenario WILL " \ |
| 249 | "break things - if not now, possibly in the future (we've seen builds fail " \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 250 | "several months later). If the system knew how to recover from this " \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 251 | "automatically it would, however there are several different scenarios " \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 252 | "which can result in this and we don't know which one this is. It may be " \ |
| 253 | "you have switched providers of something like virtual/kernel (e.g. from " \ |
| 254 | "linux-yocto to linux-yocto-dev), in that case you need to execute the " \ |
| 255 | "clean task for both recipes and it will resolve this error. It may be " \ |
| 256 | "you changed DISTRO_FEATURES from systemd to udev or vice versa. Cleaning " \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 257 | "those recipes should again resolve this error, however switching " \ |
| 258 | "DISTRO_FEATURES on an existing build directory is not supported - you " \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 259 | "should really clean out tmp and rebuild (reusing sstate should be safe). " \ |
| 260 | "It could be the overlapping files detected are harmless in which case " \ |
| 261 | "adding them to SSTATE_DUPWHITELIST may be the correct solution. It could " \ |
| 262 | "also be your build is including two different conflicting versions of " \ |
| 263 | "things (e.g. bluez 4 and bluez 5 and the correct solution for that would " \ |
| 264 | "be to resolve the conflict. If in doubt, please ask on the mailing list, " \ |
| 265 | "sharing the error and filelist above." % \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 266 | (d.getVar('PN'), "\n ".join(match))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 267 | bb.fatal("If the above message is too much, the simpler version is you're advised to wipe out tmp and rebuild (reusing sstate is fine). That will likely fix things in most (but not all) cases.") |
| 268 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 269 | if ss['fixmedir'] and os.path.exists(ss['fixmedir'] + "/fixmepath.cmd"): |
| 270 | sharedfiles.append(ss['fixmedir'] + "/fixmepath.cmd") |
| 271 | sharedfiles.append(ss['fixmedir'] + "/fixmepath") |
| 272 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 273 | # Write out the manifest |
| 274 | f = open(manifest, "w") |
| 275 | for file in sharedfiles: |
| 276 | f.write(file + "\n") |
| 277 | |
| 278 | # We want to ensure that directories appear at the end of the manifest |
| 279 | # so that when we test to see if they should be deleted any contents |
| 280 | # added by the task will have been removed first. |
| 281 | dirs = sorted(shareddirs, key=len) |
| 282 | # Must remove children first, which will have a longer path than the parent |
| 283 | for di in reversed(dirs): |
| 284 | f.write(di + "\n") |
| 285 | f.close() |
| 286 | |
| 287 | # Append to the list of manifests for this PACKAGE_ARCH |
| 288 | |
| 289 | i = d2.expand("${SSTATE_MANIFESTS}/index-${SSTATE_MANMACH}") |
| 290 | l = bb.utils.lockfile(i + ".lock") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 291 | filedata = d.getVar("STAMP") + " " + d2.getVar("SSTATE_MANFILEPREFIX") + " " + d.getVar("WORKDIR") + "\n" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 292 | manifests = [] |
| 293 | if os.path.exists(i): |
| 294 | with open(i, "r") as f: |
| 295 | manifests = f.readlines() |
| 296 | if filedata not in manifests: |
| 297 | with open(i, "a+") as f: |
| 298 | f.write(filedata) |
| 299 | bb.utils.unlockfile(l) |
| 300 | |
| 301 | # Run the actual file install |
| 302 | for state in ss['dirs']: |
| 303 | if os.path.exists(state[1]): |
| 304 | oe.path.copyhardlinktree(state[1], state[2]) |
| 305 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 306 | for postinst in (d.getVar('SSTATEPOSTINSTFUNCS') or '').split(): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 307 | # All hooks should run in the SSTATE_INSTDIR |
| 308 | bb.build.exec_func(postinst, d, (sstateinst,)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 309 | |
| 310 | for lock in locks: |
| 311 | bb.utils.unlockfile(lock) |
| 312 | |
| 313 | sstate_install[vardepsexclude] += "SSTATE_DUPWHITELIST STATE_MANMACH SSTATE_MANFILEPREFIX" |
| 314 | sstate_install[vardeps] += "${SSTATEPOSTINSTFUNCS}" |
| 315 | |
| 316 | def sstate_installpkg(ss, d): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 317 | from oe.gpg_sign import get_signer |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 318 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 319 | sstateinst = d.expand("${WORKDIR}/sstate-install-%s/" % ss['task']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 320 | sstatefetch = d.getVar('SSTATE_PKGNAME') + '_' + ss['task'] + ".tgz" |
| 321 | sstatepkg = d.getVar('SSTATE_PKG') + '_' + ss['task'] + ".tgz" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 322 | |
| 323 | if not os.path.exists(sstatepkg): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 324 | pstaging_fetch(sstatefetch, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 325 | |
| 326 | if not os.path.isfile(sstatepkg): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 327 | bb.note("Sstate package %s does not exist" % sstatepkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 328 | return False |
| 329 | |
| 330 | sstate_clean(ss, d) |
| 331 | |
| 332 | d.setVar('SSTATE_INSTDIR', sstateinst) |
| 333 | d.setVar('SSTATE_PKG', sstatepkg) |
| 334 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 335 | if bb.utils.to_boolean(d.getVar("SSTATE_VERIFY_SIG"), False): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 336 | signer = get_signer(d, 'local') |
| 337 | if not signer.verify(sstatepkg + '.sig'): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 338 | bb.warn("Cannot verify signature on sstate package %s, skipping acceleration..." % sstatepkg) |
| 339 | return False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 340 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 341 | # Empty sstateinst directory, ensure its clean |
| 342 | if os.path.exists(sstateinst): |
| 343 | oe.path.remove(sstateinst) |
| 344 | bb.utils.mkdirhier(sstateinst) |
| 345 | |
| 346 | sstateinst = d.getVar("SSTATE_INSTDIR") |
| 347 | d.setVar('SSTATE_FIXMEDIR', ss['fixmedir']) |
| 348 | |
| 349 | for f in (d.getVar('SSTATEPREINSTFUNCS') or '').split() + ['sstate_unpack_package']: |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 350 | # All hooks should run in the SSTATE_INSTDIR |
| 351 | bb.build.exec_func(f, d, (sstateinst,)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 352 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 353 | return sstate_installpkgdir(ss, d) |
| 354 | |
| 355 | def sstate_installpkgdir(ss, d): |
| 356 | import oe.path |
| 357 | import subprocess |
| 358 | |
| 359 | sstateinst = d.getVar("SSTATE_INSTDIR") |
| 360 | d.setVar('SSTATE_FIXMEDIR', ss['fixmedir']) |
| 361 | |
| 362 | for f in (d.getVar('SSTATEPOSTUNPACKFUNCS') or '').split(): |
| 363 | # All hooks should run in the SSTATE_INSTDIR |
| 364 | bb.build.exec_func(f, d, (sstateinst,)) |
| 365 | |
| 366 | def prepdir(dir): |
| 367 | # remove dir if it exists, ensure any parent directories do exist |
| 368 | if os.path.exists(dir): |
| 369 | oe.path.remove(dir) |
| 370 | bb.utils.mkdirhier(dir) |
| 371 | oe.path.remove(dir) |
| 372 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 373 | for state in ss['dirs']: |
| 374 | prepdir(state[1]) |
| 375 | os.rename(sstateinst + state[0], state[1]) |
| 376 | sstate_install(ss, d) |
| 377 | |
| 378 | for plain in ss['plaindirs']: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 379 | workdir = d.getVar('WORKDIR') |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 380 | sharedworkdir = os.path.join(d.getVar('TMPDIR'), "work-shared") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 381 | src = sstateinst + "/" + plain.replace(workdir, '') |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 382 | if sharedworkdir in plain: |
| 383 | src = sstateinst + "/" + plain.replace(sharedworkdir, '') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 384 | dest = plain |
| 385 | bb.utils.mkdirhier(src) |
| 386 | prepdir(dest) |
| 387 | os.rename(src, dest) |
| 388 | |
| 389 | return True |
| 390 | |
| 391 | python sstate_hardcode_path_unpack () { |
| 392 | # Fixup hardcoded paths |
| 393 | # |
| 394 | # Note: The logic below must match the reverse logic in |
| 395 | # sstate_hardcode_path(d) |
| 396 | import subprocess |
| 397 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 398 | sstateinst = d.getVar('SSTATE_INSTDIR') |
| 399 | sstatefixmedir = d.getVar('SSTATE_FIXMEDIR') |
| 400 | fixmefn = sstateinst + "fixmepath" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 401 | if os.path.isfile(fixmefn): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 402 | staging_target = d.getVar('RECIPE_SYSROOT') |
| 403 | staging_host = d.getVar('RECIPE_SYSROOT_NATIVE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 404 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 405 | if bb.data.inherits_class('native', d) or bb.data.inherits_class('cross-canadian', d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 406 | sstate_sed_cmd = "sed -i -e 's:FIXMESTAGINGDIRHOST:%s:g'" % (staging_host) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 407 | elif bb.data.inherits_class('cross', d) or bb.data.inherits_class('crosssdk', d): |
| 408 | sstate_sed_cmd = "sed -i -e 's:FIXMESTAGINGDIRTARGET:%s:g; s:FIXMESTAGINGDIRHOST:%s:g'" % (staging_target, staging_host) |
| 409 | else: |
| 410 | sstate_sed_cmd = "sed -i -e 's:FIXMESTAGINGDIRTARGET:%s:g'" % (staging_target) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 411 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 412 | extra_staging_fixmes = d.getVar('EXTRA_STAGING_FIXMES') or '' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 413 | for fixmevar in extra_staging_fixmes.split(): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 414 | fixme_path = d.getVar(fixmevar) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 415 | sstate_sed_cmd += " -e 's:FIXME_%s:%s:g'" % (fixmevar, fixme_path) |
| 416 | |
| 417 | # Add sstateinst to each filename in fixmepath, use xargs to efficiently call sed |
| 418 | sstate_hardcode_cmd = "sed -e 's:^:%s:g' %s | xargs %s" % (sstateinst, fixmefn, sstate_sed_cmd) |
| 419 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 420 | # Defer do_populate_sysroot relocation command |
| 421 | if sstatefixmedir: |
| 422 | bb.utils.mkdirhier(sstatefixmedir) |
| 423 | with open(sstatefixmedir + "/fixmepath.cmd", "w") as f: |
| 424 | sstate_hardcode_cmd = sstate_hardcode_cmd.replace(fixmefn, sstatefixmedir + "/fixmepath") |
| 425 | sstate_hardcode_cmd = sstate_hardcode_cmd.replace(sstateinst, "FIXMEFINALSSTATEINST") |
| 426 | sstate_hardcode_cmd = sstate_hardcode_cmd.replace(staging_host, "FIXMEFINALSSTATEHOST") |
| 427 | sstate_hardcode_cmd = sstate_hardcode_cmd.replace(staging_target, "FIXMEFINALSSTATETARGET") |
| 428 | f.write(sstate_hardcode_cmd) |
| 429 | bb.utils.copyfile(fixmefn, sstatefixmedir + "/fixmepath") |
| 430 | return |
| 431 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 432 | bb.note("Replacing fixme paths in sstate package: %s" % (sstate_hardcode_cmd)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 433 | subprocess.check_call(sstate_hardcode_cmd, shell=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 434 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 435 | # Need to remove this or we'd copy it into the target directory and may |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 436 | # conflict with another writer |
| 437 | os.remove(fixmefn) |
| 438 | } |
| 439 | |
| 440 | def sstate_clean_cachefile(ss, d): |
| 441 | import oe.path |
| 442 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 443 | sstatepkgfile = d.getVar('SSTATE_PATHSPEC') + "*_" + ss['task'] + ".tgz*" |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 444 | if d.getVarFlag('do_%s' % ss['task'], 'task'): |
| 445 | bb.note("Removing %s" % sstatepkgfile) |
| 446 | oe.path.remove(sstatepkgfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 447 | |
| 448 | def sstate_clean_cachefiles(d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 449 | for task in (d.getVar('SSTATETASKS') or "").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 450 | ld = d.createCopy() |
| 451 | ss = sstate_state_fromvars(ld, task) |
| 452 | sstate_clean_cachefile(ss, ld) |
| 453 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 454 | def sstate_clean_manifest(manifest, d, prefix=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 455 | import oe.path |
| 456 | |
| 457 | mfile = open(manifest) |
| 458 | entries = mfile.readlines() |
| 459 | mfile.close() |
| 460 | |
| 461 | for entry in entries: |
| 462 | entry = entry.strip() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 463 | if prefix and not entry.startswith("/"): |
| 464 | entry = prefix + "/" + entry |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 465 | bb.debug(2, "Removing manifest: %s" % entry) |
| 466 | # We can race against another package populating directories as we're removing them |
| 467 | # so we ignore errors here. |
| 468 | try: |
| 469 | if entry.endswith("/"): |
| 470 | if os.path.islink(entry[:-1]): |
| 471 | os.remove(entry[:-1]) |
| 472 | elif os.path.exists(entry) and len(os.listdir(entry)) == 0: |
| 473 | os.rmdir(entry[:-1]) |
| 474 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 475 | os.remove(entry) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 476 | except OSError: |
| 477 | pass |
| 478 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 479 | postrm = manifest + ".postrm" |
| 480 | if os.path.exists(manifest + ".postrm"): |
| 481 | import subprocess |
| 482 | os.chmod(postrm, 0o755) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 483 | subprocess.check_call(postrm, shell=True) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 484 | oe.path.remove(postrm) |
| 485 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 486 | oe.path.remove(manifest) |
| 487 | |
| 488 | def sstate_clean(ss, d): |
| 489 | import oe.path |
| 490 | import glob |
| 491 | |
| 492 | d2 = d.createCopy() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 493 | stamp_clean = d.getVar("STAMPCLEAN") |
| 494 | extrainf = d.getVarFlag("do_" + ss['task'], 'stamp-extra-info') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 495 | if extrainf: |
| 496 | d2.setVar("SSTATE_MANMACH", extrainf) |
| 497 | wildcard_stfile = "%s.do_%s*.%s" % (stamp_clean, ss['task'], extrainf) |
| 498 | else: |
| 499 | wildcard_stfile = "%s.do_%s*" % (stamp_clean, ss['task']) |
| 500 | |
| 501 | manifest = d2.expand("${SSTATE_MANFILEPREFIX}.%s" % ss['task']) |
| 502 | |
| 503 | if os.path.exists(manifest): |
| 504 | locks = [] |
| 505 | for lock in ss['lockfiles-shared']: |
| 506 | locks.append(bb.utils.lockfile(lock)) |
| 507 | for lock in ss['lockfiles']: |
| 508 | locks.append(bb.utils.lockfile(lock)) |
| 509 | |
| 510 | sstate_clean_manifest(manifest, d) |
| 511 | |
| 512 | for lock in locks: |
| 513 | bb.utils.unlockfile(lock) |
| 514 | |
| 515 | # Remove the current and previous stamps, but keep the sigdata. |
| 516 | # |
| 517 | # The glob() matches do_task* which may match multiple tasks, for |
| 518 | # example: do_package and do_package_write_ipk, so we need to |
| 519 | # exactly match *.do_task.* and *.do_task_setscene.* |
| 520 | rm_stamp = '.do_%s.' % ss['task'] |
| 521 | rm_setscene = '.do_%s_setscene.' % ss['task'] |
| 522 | # For BB_SIGNATURE_HANDLER = "noop" |
| 523 | rm_nohash = ".do_%s" % ss['task'] |
| 524 | for stfile in glob.glob(wildcard_stfile): |
| 525 | # Keep the sigdata |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 526 | if ".sigdata." in stfile or ".sigbasedata." in stfile: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 527 | continue |
| 528 | # Preserve taint files in the stamps directory |
| 529 | if stfile.endswith('.taint'): |
| 530 | continue |
| 531 | if rm_stamp in stfile or rm_setscene in stfile or \ |
| 532 | stfile.endswith(rm_nohash): |
| 533 | oe.path.remove(stfile) |
| 534 | |
| 535 | sstate_clean[vardepsexclude] = "SSTATE_MANFILEPREFIX" |
| 536 | |
| 537 | CLEANFUNCS += "sstate_cleanall" |
| 538 | |
| 539 | python sstate_cleanall() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 540 | bb.note("Removing shared state for package %s" % d.getVar('PN')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 541 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 542 | manifest_dir = d.getVar('SSTATE_MANIFESTS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 543 | if not os.path.exists(manifest_dir): |
| 544 | return |
| 545 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 546 | tasks = d.getVar('SSTATETASKS').split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 547 | for name in tasks: |
| 548 | ld = d.createCopy() |
| 549 | shared_state = sstate_state_fromvars(ld, name) |
| 550 | sstate_clean(shared_state, ld) |
| 551 | } |
| 552 | |
| 553 | python sstate_hardcode_path () { |
| 554 | import subprocess, platform |
| 555 | |
| 556 | # Need to remove hardcoded paths and fix these when we install the |
| 557 | # staging packages. |
| 558 | # |
| 559 | # Note: the logic in this function needs to match the reverse logic |
| 560 | # in sstate_installpkg(ss, d) |
| 561 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 562 | staging_target = d.getVar('RECIPE_SYSROOT') |
| 563 | staging_host = d.getVar('RECIPE_SYSROOT_NATIVE') |
| 564 | sstate_builddir = d.getVar('SSTATE_BUILDDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 565 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 566 | sstate_sed_cmd = "sed -i -e 's:%s:FIXMESTAGINGDIRHOST:g'" % staging_host |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 567 | if bb.data.inherits_class('native', d) or bb.data.inherits_class('cross-canadian', d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 568 | sstate_grep_cmd = "grep -l -e '%s'" % (staging_host) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 569 | elif bb.data.inherits_class('cross', d) or bb.data.inherits_class('crosssdk', d): |
| 570 | sstate_grep_cmd = "grep -l -e '%s' -e '%s'" % (staging_target, staging_host) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 571 | sstate_sed_cmd += " -e 's:%s:FIXMESTAGINGDIRTARGET:g'" % staging_target |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 572 | else: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 573 | sstate_grep_cmd = "grep -l -e '%s' -e '%s'" % (staging_target, staging_host) |
| 574 | sstate_sed_cmd += " -e 's:%s:FIXMESTAGINGDIRTARGET:g'" % staging_target |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 575 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 576 | extra_staging_fixmes = d.getVar('EXTRA_STAGING_FIXMES') or '' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 577 | for fixmevar in extra_staging_fixmes.split(): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 578 | fixme_path = d.getVar(fixmevar) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 579 | sstate_sed_cmd += " -e 's:%s:FIXME_%s:g'" % (fixme_path, fixmevar) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 580 | sstate_grep_cmd += " -e '%s'" % (fixme_path) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 581 | |
| 582 | fixmefn = sstate_builddir + "fixmepath" |
| 583 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 584 | sstate_scan_cmd = d.getVar('SSTATE_SCAN_CMD') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 585 | sstate_filelist_cmd = "tee %s" % (fixmefn) |
| 586 | |
| 587 | # fixmepath file needs relative paths, drop sstate_builddir prefix |
| 588 | sstate_filelist_relative_cmd = "sed -i -e 's:^%s::g' %s" % (sstate_builddir, fixmefn) |
| 589 | |
| 590 | xargs_no_empty_run_cmd = '--no-run-if-empty' |
| 591 | if platform.system() == 'Darwin': |
| 592 | xargs_no_empty_run_cmd = '' |
| 593 | |
| 594 | # Limit the fixpaths and sed operations based on the initial grep search |
| 595 | # This has the side effect of making sure the vfs cache is hot |
| 596 | sstate_hardcode_cmd = "%s | xargs %s | %s | xargs %s %s" % (sstate_scan_cmd, sstate_grep_cmd, sstate_filelist_cmd, xargs_no_empty_run_cmd, sstate_sed_cmd) |
| 597 | |
| 598 | bb.note("Removing hardcoded paths from sstate package: '%s'" % (sstate_hardcode_cmd)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 599 | subprocess.check_output(sstate_hardcode_cmd, shell=True, cwd=sstate_builddir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 600 | |
| 601 | # If the fixmefn is empty, remove it.. |
| 602 | if os.stat(fixmefn).st_size == 0: |
| 603 | os.remove(fixmefn) |
| 604 | else: |
| 605 | bb.note("Replacing absolute paths in fixmepath file: '%s'" % (sstate_filelist_relative_cmd)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 606 | subprocess.check_output(sstate_filelist_relative_cmd, shell=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | def sstate_package(ss, d): |
| 610 | import oe.path |
| 611 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 612 | tmpdir = d.getVar('TMPDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 613 | |
| 614 | sstatebuild = d.expand("${WORKDIR}/sstate-build-%s/" % ss['task']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 615 | sstatepkg = d.getVar('SSTATE_PKG') + '_'+ ss['task'] + ".tgz" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 616 | bb.utils.remove(sstatebuild, recurse=True) |
| 617 | bb.utils.mkdirhier(sstatebuild) |
| 618 | bb.utils.mkdirhier(os.path.dirname(sstatepkg)) |
| 619 | for state in ss['dirs']: |
| 620 | if not os.path.exists(state[1]): |
| 621 | continue |
| 622 | srcbase = state[0].rstrip("/").rsplit('/', 1)[0] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 623 | # Find and error for absolute symlinks. We could attempt to relocate but its not |
| 624 | # clear where the symlink is relative to in this context. We could add that markup |
| 625 | # to sstate tasks but there aren't many of these so better just avoid them entirely. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 626 | for walkroot, dirs, files in os.walk(state[1]): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 627 | for file in files + dirs: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 628 | srcpath = os.path.join(walkroot, file) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 629 | if not os.path.islink(srcpath): |
| 630 | continue |
| 631 | link = os.readlink(srcpath) |
| 632 | if not os.path.isabs(link): |
| 633 | continue |
| 634 | if not link.startswith(tmpdir): |
| 635 | continue |
| 636 | bb.error("sstate found an absolute path symlink %s pointing at %s. Please replace this with a relative link." % (srcpath, link)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 637 | bb.debug(2, "Preparing tree %s for packaging at %s" % (state[1], sstatebuild + state[0])) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 638 | os.rename(state[1], sstatebuild + state[0]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 639 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 640 | workdir = d.getVar('WORKDIR') |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 641 | sharedworkdir = os.path.join(d.getVar('TMPDIR'), "work-shared") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 642 | for plain in ss['plaindirs']: |
| 643 | pdir = plain.replace(workdir, sstatebuild) |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 644 | if sharedworkdir in plain: |
| 645 | pdir = plain.replace(sharedworkdir, sstatebuild) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 646 | bb.utils.mkdirhier(plain) |
| 647 | bb.utils.mkdirhier(pdir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 648 | os.rename(plain, pdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 649 | |
| 650 | d.setVar('SSTATE_BUILDDIR', sstatebuild) |
| 651 | d.setVar('SSTATE_PKG', sstatepkg) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 652 | d.setVar('SSTATE_INSTDIR', sstatebuild) |
| 653 | |
| 654 | if d.getVar('SSTATE_SKIP_CREATION') == '1': |
| 655 | return |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 656 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 657 | sstate_create_package = ['sstate_report_unihash', 'sstate_create_package'] |
| 658 | if d.getVar('SSTATE_SIG_KEY'): |
| 659 | sstate_create_package.append('sstate_sign_package') |
| 660 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 661 | for f in (d.getVar('SSTATECREATEFUNCS') or '').split() + \ |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 662 | sstate_create_package + \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 663 | (d.getVar('SSTATEPOSTCREATEFUNCS') or '').split(): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 664 | # All hooks should run in SSTATE_BUILDDIR. |
| 665 | bb.build.exec_func(f, d, (sstatebuild,)) |
| 666 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 667 | bb.siggen.dump_this_task(sstatepkg + ".siginfo", d) |
| 668 | |
| 669 | return |
| 670 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 671 | def pstaging_fetch(sstatefetch, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 672 | import bb.fetch2 |
| 673 | |
| 674 | # Only try and fetch if the user has configured a mirror |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 675 | mirrors = d.getVar('SSTATE_MIRRORS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 676 | if not mirrors: |
| 677 | return |
| 678 | |
| 679 | # Copy the data object and override DL_DIR and SRC_URI |
| 680 | localdata = bb.data.createCopy(d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 681 | |
| 682 | dldir = localdata.expand("${SSTATE_DIR}") |
| 683 | bb.utils.mkdirhier(dldir) |
| 684 | |
| 685 | localdata.delVar('MIRRORS') |
| 686 | localdata.setVar('FILESPATH', dldir) |
| 687 | localdata.setVar('DL_DIR', dldir) |
| 688 | localdata.setVar('PREMIRRORS', mirrors) |
| 689 | |
| 690 | # if BB_NO_NETWORK is set but we also have SSTATE_MIRROR_ALLOW_NETWORK, |
| 691 | # we'll want to allow network access for the current set of fetches. |
Brad Bishop | d89cb5f | 2019-04-10 09:02:41 -0400 | [diff] [blame] | 692 | if bb.utils.to_boolean(localdata.getVar('BB_NO_NETWORK')) and \ |
| 693 | bb.utils.to_boolean(localdata.getVar('SSTATE_MIRROR_ALLOW_NETWORK')): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 694 | localdata.delVar('BB_NO_NETWORK') |
| 695 | |
| 696 | # Try a fetch from the sstate mirror, if it fails just return and |
| 697 | # we will build the package |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 698 | uris = ['file://{0};downloadfilename={0}'.format(sstatefetch), |
| 699 | 'file://{0}.siginfo;downloadfilename={0}.siginfo'.format(sstatefetch)] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 700 | if bb.utils.to_boolean(d.getVar("SSTATE_VERIFY_SIG"), False): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 701 | uris += ['file://{0}.sig;downloadfilename={0}.sig'.format(sstatefetch)] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 702 | |
| 703 | for srcuri in uris: |
| 704 | localdata.setVar('SRC_URI', srcuri) |
| 705 | try: |
| 706 | fetcher = bb.fetch2.Fetch([srcuri], localdata, cache=False) |
| 707 | fetcher.download() |
| 708 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 709 | except bb.fetch2.BBFetchException: |
| 710 | break |
| 711 | |
| 712 | def sstate_setscene(d): |
| 713 | shared_state = sstate_state_fromvars(d) |
| 714 | accelerate = sstate_installpkg(shared_state, d) |
| 715 | if not accelerate: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 716 | bb.fatal("No suitable staging package found") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 717 | |
| 718 | python sstate_task_prefunc () { |
| 719 | shared_state = sstate_state_fromvars(d) |
| 720 | sstate_clean(shared_state, d) |
| 721 | } |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 722 | sstate_task_prefunc[dirs] = "${WORKDIR}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 723 | |
| 724 | python sstate_task_postfunc () { |
| 725 | shared_state = sstate_state_fromvars(d) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 726 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 727 | for intercept in shared_state['interceptfuncs']: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 728 | bb.build.exec_func(intercept, d, (d.getVar("WORKDIR"),)) |
| 729 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 730 | omask = os.umask(0o002) |
| 731 | if omask != 0o002: |
| 732 | bb.note("Using umask 0o002 (not %0o) for sstate packaging" % omask) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 733 | sstate_package(shared_state, d) |
| 734 | os.umask(omask) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 735 | |
| 736 | sstateinst = d.getVar("SSTATE_INSTDIR") |
| 737 | d.setVar('SSTATE_FIXMEDIR', shared_state['fixmedir']) |
| 738 | |
| 739 | sstate_installpkgdir(shared_state, d) |
| 740 | |
| 741 | bb.utils.remove(d.getVar("SSTATE_BUILDDIR"), recurse=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 742 | } |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 743 | sstate_task_postfunc[dirs] = "${WORKDIR}" |
| 744 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 745 | |
| 746 | # |
| 747 | # Shell function to generate a sstate package from a directory |
| 748 | # set as SSTATE_BUILDDIR. Will be run from within SSTATE_BUILDDIR. |
| 749 | # |
| 750 | sstate_create_package () { |
| 751 | TFILE=`mktemp ${SSTATE_PKG}.XXXXXXXX` |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 752 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 753 | # Exit earlu if it already exists |
| 754 | if [ -e ${SSTATE_PKG} ]; then |
| 755 | return |
| 756 | fi |
| 757 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 758 | # Use pigz if available |
| 759 | OPT="-czS" |
| 760 | if [ -x "$(command -v pigz)" ]; then |
| 761 | OPT="-I pigz -cS" |
| 762 | fi |
| 763 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 764 | # Need to handle empty directories |
| 765 | if [ "$(ls -A)" ]; then |
| 766 | set +e |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 767 | tar $OPT -f $TFILE * |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 768 | ret=$? |
| 769 | if [ $ret -ne 0 ] && [ $ret -ne 1 ]; then |
| 770 | exit 1 |
| 771 | fi |
| 772 | set -e |
| 773 | else |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 774 | tar $OPT --file=$TFILE --files-from=/dev/null |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 775 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 776 | chmod 0664 $TFILE |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 777 | # Skip if it was already created by some other process |
| 778 | if [ ! -e ${SSTATE_PKG} ]; then |
| 779 | mv -f $TFILE ${SSTATE_PKG} |
| 780 | else |
| 781 | rm $TFILE |
| 782 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 783 | } |
| 784 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 785 | python sstate_sign_package () { |
| 786 | from oe.gpg_sign import get_signer |
| 787 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 788 | |
| 789 | signer = get_signer(d, 'local') |
| 790 | sstate_pkg = d.getVar('SSTATE_PKG') |
| 791 | if os.path.exists(sstate_pkg + '.sig'): |
| 792 | os.unlink(sstate_pkg + '.sig') |
| 793 | signer.detach_sign(sstate_pkg, d.getVar('SSTATE_SIG_KEY', False), None, |
| 794 | d.getVar('SSTATE_SIG_PASSPHRASE'), armor=False) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 795 | } |
| 796 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 797 | python sstate_report_unihash() { |
| 798 | report_unihash = getattr(bb.parse.siggen, 'report_unihash', None) |
| 799 | |
| 800 | if report_unihash: |
| 801 | ss = sstate_state_fromvars(d) |
| 802 | report_unihash(os.getcwd(), ss['task'], d) |
| 803 | } |
| 804 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 805 | # |
| 806 | # Shell function to decompress and prepare a package for installation |
| 807 | # Will be run from within SSTATE_INSTDIR. |
| 808 | # |
| 809 | sstate_unpack_package () { |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 810 | tar -xvzf ${SSTATE_PKG} |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 811 | # update .siginfo atime on local/NFS mirror |
| 812 | [ -w ${SSTATE_PKG}.siginfo ] && [ -h ${SSTATE_PKG}.siginfo ] && touch -a ${SSTATE_PKG}.siginfo |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 813 | # Use "! -w ||" to return true for read only files |
| 814 | [ ! -w ${SSTATE_PKG} ] || touch --no-dereference ${SSTATE_PKG} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 815 | [ ! -w ${SSTATE_PKG}.sig ] || [ ! -e ${SSTATE_PKG}.sig ] || touch --no-dereference ${SSTATE_PKG}.sig |
| 816 | [ ! -w ${SSTATE_PKG}.siginfo ] || [ ! -e ${SSTATE_PKG}.siginfo ] || touch --no-dereference ${SSTATE_PKG}.siginfo |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | BB_HASHCHECK_FUNCTION = "sstate_checkhashes" |
| 820 | |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 821 | def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True, **kwargs): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 822 | found = set() |
| 823 | missed = set() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 824 | extension = ".tgz" |
| 825 | if siginfo: |
| 826 | extension = extension + ".siginfo" |
| 827 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 828 | def gethash(task): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 829 | return sq_data['unihash'][task] |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 830 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 831 | def getpathcomponents(task, d): |
| 832 | # Magic data from BB_HASHFILENAME |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 833 | splithashfn = sq_data['hashfn'][task].split(" ") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 834 | spec = splithashfn[1] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 835 | if splithashfn[0] == "True": |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 836 | extrapath = d.getVar("NATIVELSBSTRING") + "/" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 837 | else: |
| 838 | extrapath = "" |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 839 | |
| 840 | tname = bb.runqueue.taskname_from_tid(task)[3:] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 841 | |
| 842 | if tname in ["fetch", "unpack", "patch", "populate_lic", "preconfigure"] and splithashfn[2]: |
| 843 | spec = splithashfn[2] |
| 844 | extrapath = "" |
| 845 | |
| 846 | return spec, extrapath, tname |
| 847 | |
| 848 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 849 | for tid in sq_data['hash']: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 850 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 851 | spec, extrapath, tname = getpathcomponents(tid, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 852 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 853 | sstatefile = d.expand("${SSTATE_DIR}/" + extrapath + generate_sstatefn(spec, gethash(tid), d) + "_" + tname + extension) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 854 | |
| 855 | if os.path.exists(sstatefile): |
| 856 | bb.debug(2, "SState: Found valid sstate file %s" % sstatefile) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 857 | found.add(tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 858 | continue |
| 859 | else: |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 860 | missed.add(tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 861 | bb.debug(2, "SState: Looked for but didn't find file %s" % sstatefile) |
| 862 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 863 | mirrors = d.getVar("SSTATE_MIRRORS") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 864 | if mirrors: |
| 865 | # Copy the data object and override DL_DIR and SRC_URI |
| 866 | localdata = bb.data.createCopy(d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 867 | |
| 868 | dldir = localdata.expand("${SSTATE_DIR}") |
| 869 | localdata.delVar('MIRRORS') |
| 870 | localdata.setVar('FILESPATH', dldir) |
| 871 | localdata.setVar('DL_DIR', dldir) |
| 872 | localdata.setVar('PREMIRRORS', mirrors) |
| 873 | |
| 874 | bb.debug(2, "SState using premirror of: %s" % mirrors) |
| 875 | |
| 876 | # if BB_NO_NETWORK is set but we also have SSTATE_MIRROR_ALLOW_NETWORK, |
| 877 | # we'll want to allow network access for the current set of fetches. |
Brad Bishop | d89cb5f | 2019-04-10 09:02:41 -0400 | [diff] [blame] | 878 | if bb.utils.to_boolean(localdata.getVar('BB_NO_NETWORK')) and \ |
| 879 | bb.utils.to_boolean(localdata.getVar('SSTATE_MIRROR_ALLOW_NETWORK')): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 880 | localdata.delVar('BB_NO_NETWORK') |
| 881 | |
| 882 | from bb.fetch2 import FetchConnectionCache |
| 883 | def checkstatus_init(thread_worker): |
| 884 | thread_worker.connection_cache = FetchConnectionCache() |
| 885 | |
| 886 | def checkstatus_end(thread_worker): |
| 887 | thread_worker.connection_cache.close_connections() |
| 888 | |
| 889 | def checkstatus(thread_worker, arg): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 890 | (tid, sstatefile) = arg |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 891 | |
| 892 | localdata2 = bb.data.createCopy(localdata) |
| 893 | srcuri = "file://" + sstatefile |
| 894 | localdata.setVar('SRC_URI', srcuri) |
| 895 | bb.debug(2, "SState: Attempting to fetch %s" % srcuri) |
| 896 | |
| 897 | try: |
| 898 | fetcher = bb.fetch2.Fetch(srcuri.split(), localdata2, |
| 899 | connection_cache=thread_worker.connection_cache) |
| 900 | fetcher.checkstatus() |
| 901 | bb.debug(2, "SState: Successful fetch test for %s" % srcuri) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 902 | found.add(tid) |
| 903 | if tid in missed: |
| 904 | missed.remove(tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 905 | except: |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 906 | missed.add(tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 907 | bb.debug(2, "SState: Unsuccessful fetch test for %s" % srcuri) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 908 | pass |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 909 | bb.event.fire(bb.event.ProcessProgress(msg, len(tasklist) - thread_worker.tasks.qsize()), d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 910 | |
| 911 | tasklist = [] |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 912 | for tid in sq_data['hash']: |
| 913 | if tid in found: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 914 | continue |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 915 | spec, extrapath, tname = getpathcomponents(tid, d) |
| 916 | sstatefile = d.expand(extrapath + generate_sstatefn(spec, gethash(tid), d) + "_" + tname + extension) |
| 917 | tasklist.append((tid, sstatefile)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 918 | |
| 919 | if tasklist: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 920 | msg = "Checking sstate mirror object availability" |
| 921 | bb.event.fire(bb.event.ProcessStarted(msg, len(tasklist)), d) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 922 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 923 | import multiprocessing |
| 924 | nproc = min(multiprocessing.cpu_count(), len(tasklist)) |
| 925 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 926 | bb.event.enable_threadlock() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 927 | pool = oe.utils.ThreadedPool(nproc, len(tasklist), |
| 928 | worker_init=checkstatus_init, worker_end=checkstatus_end) |
| 929 | for t in tasklist: |
| 930 | pool.add_task(checkstatus, t) |
| 931 | pool.start() |
| 932 | pool.wait_completion() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 933 | bb.event.disable_threadlock() |
| 934 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 935 | bb.event.fire(bb.event.ProcessFinished(msg), d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 936 | |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 937 | # Likely checking an individual task hash again for multiconfig sharing of sstate tasks so skip reporting |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 938 | if len(sq_data['hash']) == 1: |
| 939 | return found |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 940 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 941 | inheritlist = d.getVar("INHERIT") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 942 | if "toaster" in inheritlist: |
| 943 | evdata = {'missed': [], 'found': []}; |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 944 | for tid in missed: |
| 945 | spec, extrapath, tname = getpathcomponents(tid, d) |
| 946 | sstatefile = d.expand(extrapath + generate_sstatefn(spec, gethash(tid), d) + "_" + tname + ".tgz") |
| 947 | evdata['missed'].append((bb.runqueue.fn_from_tid(tid), bb.runqueue.taskname_from_tid(tid), gethash(tid), sstatefile ) ) |
| 948 | for tid in found: |
| 949 | spec, extrapath, tname = getpathcomponents(tid, d) |
| 950 | sstatefile = d.expand(extrapath + generate_sstatefn(spec, gethash(tid), d) + "_" + tname + ".tgz") |
| 951 | evdata['found'].append((bb.runqueue.fn_from_tid(tid), bb.runqueue.taskname_from_tid(tid), gethash(tid), sstatefile ) ) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 952 | bb.event.fire(bb.event.MetadataEvent("MissedSstate", evdata), d) |
| 953 | |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 954 | if summary: |
| 955 | # Print some summary statistics about the current task completion and how much sstate |
| 956 | # reuse there was. Avoid divide by zero errors. |
| 957 | total = len(sq_data['hash']) |
| 958 | complete = 0 |
| 959 | if currentcount: |
| 960 | complete = (len(found) + currentcount) / (total + currentcount) * 100 |
| 961 | match = 0 |
| 962 | if total: |
| 963 | match = len(found) / total * 100 |
| 964 | bb.plain("Sstate summary: Wanted %d Found %d Missed %d Current %d (%d%% match, %d%% complete)" % (total, len(found), len(missed), currentcount, match, complete)) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 965 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 966 | if hasattr(bb.parse.siggen, "checkhashes"): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 967 | bb.parse.siggen.checkhashes(sq_data, missed, found, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 968 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 969 | return found |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 970 | |
| 971 | BB_SETSCENE_DEPVALID = "setscene_depvalid" |
| 972 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 973 | def setscene_depvalid(task, taskdependees, notneeded, d, log=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 974 | # taskdependees is a dict of tasks which depend on task, each being a 3 item list of [PN, TASKNAME, FILENAME] |
| 975 | # task is included in taskdependees too |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 976 | # Return - False - We need this dependency |
| 977 | # - True - We can skip this dependency |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 978 | import re |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 979 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 980 | def logit(msg, log): |
| 981 | if log is not None: |
| 982 | log.append(msg) |
| 983 | else: |
| 984 | bb.debug(2, msg) |
| 985 | |
| 986 | logit("Considering setscene task: %s" % (str(taskdependees[task])), log) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 987 | |
| 988 | def isNativeCross(x): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 989 | return x.endswith("-native") or "-cross-" in x or "-crosssdk" in x or x.endswith("-cross") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 990 | |
| 991 | # We only need to trigger populate_lic through direct dependencies |
| 992 | if taskdependees[task][1] == "do_populate_lic": |
| 993 | return True |
| 994 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 995 | # stash_locale and gcc_stash_builddir are never needed as a dependency for built objects |
| 996 | if taskdependees[task][1] == "do_stash_locale" or taskdependees[task][1] == "do_gcc_stash_builddir": |
| 997 | return True |
| 998 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 999 | # We only need to trigger packagedata through direct dependencies |
| 1000 | # but need to preserve packagedata on packagedata links |
| 1001 | if taskdependees[task][1] == "do_packagedata": |
| 1002 | for dep in taskdependees: |
| 1003 | if taskdependees[dep][1] == "do_packagedata": |
| 1004 | return False |
| 1005 | return True |
| 1006 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1007 | for dep in taskdependees: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1008 | logit(" considering dependency: %s" % (str(taskdependees[dep])), log) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1009 | if task == dep: |
| 1010 | continue |
| 1011 | if dep in notneeded: |
| 1012 | continue |
| 1013 | # do_package_write_* and do_package doesn't need do_package |
| 1014 | if taskdependees[task][1] == "do_package" and taskdependees[dep][1] in ['do_package', 'do_package_write_deb', 'do_package_write_ipk', 'do_package_write_rpm', 'do_packagedata', 'do_package_qa']: |
| 1015 | continue |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1016 | # do_package_write_* need do_populate_sysroot as they're mainly postinstall dependencies |
| 1017 | if taskdependees[task][1] == "do_populate_sysroot" and taskdependees[dep][1] in ['do_package_write_deb', 'do_package_write_ipk', 'do_package_write_rpm']: |
| 1018 | return False |
| 1019 | # do_package/packagedata/package_qa don't need do_populate_sysroot |
| 1020 | if taskdependees[task][1] == "do_populate_sysroot" and taskdependees[dep][1] in ['do_package', 'do_packagedata', 'do_package_qa']: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1021 | continue |
| 1022 | # Native/Cross packages don't exist and are noexec anyway |
| 1023 | if isNativeCross(taskdependees[dep][0]) and taskdependees[dep][1] in ['do_package_write_deb', 'do_package_write_ipk', 'do_package_write_rpm', 'do_packagedata', 'do_package', 'do_package_qa']: |
| 1024 | continue |
| 1025 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1026 | # This is due to the [depends] in useradd.bbclass complicating matters |
| 1027 | # The logic *is* reversed here due to the way hard setscene dependencies are injected |
| 1028 | if (taskdependees[task][1] == 'do_package' or taskdependees[task][1] == 'do_populate_sysroot') and taskdependees[dep][0].endswith(('shadow-native', 'shadow-sysroot', 'base-passwd', 'pseudo-native')) and taskdependees[dep][1] == 'do_populate_sysroot': |
| 1029 | continue |
| 1030 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1031 | # Consider sysroot depending on sysroot tasks |
| 1032 | if taskdependees[task][1] == 'do_populate_sysroot' and taskdependees[dep][1] == 'do_populate_sysroot': |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1033 | # Allow excluding certain recursive dependencies. If a recipe needs it should add a |
| 1034 | # specific dependency itself, rather than relying on one of its dependees to pull |
| 1035 | # them in. |
| 1036 | # See also http://lists.openembedded.org/pipermail/openembedded-core/2018-January/146324.html |
| 1037 | not_needed = False |
| 1038 | excludedeps = d.getVar('_SSTATE_EXCLUDEDEPS_SYSROOT') |
| 1039 | if excludedeps is None: |
| 1040 | # Cache the regular expressions for speed |
| 1041 | excludedeps = [] |
| 1042 | for excl in (d.getVar('SSTATE_EXCLUDEDEPS_SYSROOT') or "").split(): |
| 1043 | excludedeps.append((re.compile(excl.split('->', 1)[0]), re.compile(excl.split('->', 1)[1]))) |
| 1044 | d.setVar('_SSTATE_EXCLUDEDEPS_SYSROOT', excludedeps) |
| 1045 | for excl in excludedeps: |
| 1046 | if excl[0].match(taskdependees[dep][0]): |
| 1047 | if excl[1].match(taskdependees[task][0]): |
| 1048 | not_needed = True |
| 1049 | break |
| 1050 | if not_needed: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1051 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1052 | # For meta-extsdk-toolchain we want all sysroot dependencies |
| 1053 | if taskdependees[dep][0] == 'meta-extsdk-toolchain': |
| 1054 | return False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1055 | # Native/Cross populate_sysroot need their dependencies |
| 1056 | if isNativeCross(taskdependees[task][0]) and isNativeCross(taskdependees[dep][0]): |
| 1057 | return False |
| 1058 | # Target populate_sysroot depended on by cross tools need to be installed |
| 1059 | if isNativeCross(taskdependees[dep][0]): |
| 1060 | return False |
| 1061 | # Native/cross tools depended upon by target sysroot are not needed |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1062 | # Add an exception for shadow-native as required by useradd.bbclass |
| 1063 | if isNativeCross(taskdependees[task][0]) and taskdependees[task][0] != 'shadow-native': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1064 | continue |
| 1065 | # Target populate_sysroot need their dependencies |
| 1066 | return False |
| 1067 | |
| 1068 | if taskdependees[task][1] == 'do_shared_workdir': |
| 1069 | continue |
| 1070 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1071 | if taskdependees[dep][1] == "do_populate_lic": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1072 | continue |
| 1073 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1074 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1075 | # Safe fallthrough default |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1076 | logit(" Default setscene dependency fall through due to dependency: %s" % (str(taskdependees[dep])), log) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1077 | return False |
| 1078 | return True |
| 1079 | |
| 1080 | addhandler sstate_eventhandler |
| 1081 | sstate_eventhandler[eventmask] = "bb.build.TaskSucceeded" |
| 1082 | python sstate_eventhandler() { |
| 1083 | d = e.data |
| 1084 | # When we write an sstate package we rewrite the SSTATE_PKG |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1085 | spkg = d.getVar('SSTATE_PKG') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1086 | if not spkg.endswith(".tgz"): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1087 | taskname = d.getVar("BB_RUNTASK")[3:] |
| 1088 | spec = d.getVar('SSTATE_PKGSPEC') |
| 1089 | swspec = d.getVar('SSTATE_SWSPEC') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1090 | if taskname in ["fetch", "unpack", "patch", "populate_lic", "preconfigure"] and swspec: |
| 1091 | d.setVar("SSTATE_PKGSPEC", "${SSTATE_SWSPEC}") |
| 1092 | d.setVar("SSTATE_EXTRAPATH", "") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1093 | sstatepkg = d.getVar('SSTATE_PKG') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1094 | bb.siggen.dump_this_task(sstatepkg + '_' + taskname + ".tgz" ".siginfo", d) |
| 1095 | } |
| 1096 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1097 | SSTATE_PRUNE_OBSOLETEWORKDIR ?= "1" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1098 | |
| 1099 | # Event handler which removes manifests and stamps file for |
| 1100 | # recipes which are no longer reachable in a build where they |
| 1101 | # once were. |
| 1102 | # Also optionally removes the workdir of those tasks/recipes |
| 1103 | # |
| 1104 | addhandler sstate_eventhandler2 |
| 1105 | sstate_eventhandler2[eventmask] = "bb.event.ReachableStamps" |
| 1106 | python sstate_eventhandler2() { |
| 1107 | import glob |
| 1108 | d = e.data |
| 1109 | stamps = e.stamps.values() |
| 1110 | removeworkdir = (d.getVar("SSTATE_PRUNE_OBSOLETEWORKDIR", False) == "1") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1111 | preservestampfile = d.expand('${SSTATE_MANIFESTS}/preserve-stamps') |
| 1112 | preservestamps = [] |
| 1113 | if os.path.exists(preservestampfile): |
| 1114 | with open(preservestampfile, 'r') as f: |
| 1115 | preservestamps = f.readlines() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1116 | seen = [] |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1117 | |
| 1118 | # The machine index contains all the stamps this machine has ever seen in this build directory. |
| 1119 | # We should only remove things which this machine once accessed but no longer does. |
| 1120 | machineindex = set() |
| 1121 | bb.utils.mkdirhier(d.expand("${SSTATE_MANIFESTS}")) |
| 1122 | mi = d.expand("${SSTATE_MANIFESTS}/index-machine-${MACHINE}") |
| 1123 | if os.path.exists(mi): |
| 1124 | with open(mi, "r") as f: |
| 1125 | machineindex = set(line.strip() for line in f.readlines()) |
| 1126 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1127 | for a in sorted(list(set(d.getVar("SSTATE_ARCHS").split()))): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1128 | toremove = [] |
| 1129 | i = d.expand("${SSTATE_MANIFESTS}/index-" + a) |
| 1130 | if not os.path.exists(i): |
| 1131 | continue |
| 1132 | with open(i, "r") as f: |
| 1133 | lines = f.readlines() |
| 1134 | for l in lines: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1135 | try: |
| 1136 | (stamp, manifest, workdir) = l.split() |
| 1137 | if stamp not in stamps and stamp not in preservestamps and stamp in machineindex: |
| 1138 | toremove.append(l) |
| 1139 | if stamp not in seen: |
| 1140 | bb.debug(2, "Stamp %s is not reachable, removing related manifests" % stamp) |
| 1141 | seen.append(stamp) |
| 1142 | except ValueError: |
| 1143 | bb.fatal("Invalid line '%s' in sstate manifest '%s'" % (l, i)) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1144 | |
| 1145 | if toremove: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1146 | msg = "Removing %d recipes from the %s sysroot" % (len(toremove), a) |
| 1147 | bb.event.fire(bb.event.ProcessStarted(msg, len(toremove)), d) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1148 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1149 | removed = 0 |
| 1150 | for r in toremove: |
| 1151 | (stamp, manifest, workdir) = r.split() |
| 1152 | for m in glob.glob(manifest + ".*"): |
| 1153 | if m.endswith(".postrm"): |
| 1154 | continue |
| 1155 | sstate_clean_manifest(m, d) |
| 1156 | bb.utils.remove(stamp + "*") |
| 1157 | if removeworkdir: |
| 1158 | bb.utils.remove(workdir, recurse = True) |
| 1159 | lines.remove(r) |
| 1160 | removed = removed + 1 |
| 1161 | bb.event.fire(bb.event.ProcessProgress(msg, removed), d) |
| 1162 | |
| 1163 | bb.event.fire(bb.event.ProcessFinished(msg), d) |
| 1164 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1165 | with open(i, "w") as f: |
| 1166 | for l in lines: |
| 1167 | f.write(l) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1168 | machineindex |= set(stamps) |
| 1169 | with open(mi, "w") as f: |
| 1170 | for l in machineindex: |
| 1171 | f.write(l + "\n") |
| 1172 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1173 | if preservestamps: |
| 1174 | os.remove(preservestampfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1175 | } |