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