Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | import bb.siggen |
| 2 | |
| 3 | def sstate_rundepfilter(siggen, fn, recipename, task, dep, depname, dataCache): |
| 4 | # Return True if we should keep the dependency, False to drop it |
| 5 | def isNative(x): |
| 6 | return x.endswith("-native") |
| 7 | def isCross(x): |
| 8 | return "-cross-" in x |
| 9 | def isNativeSDK(x): |
| 10 | return x.startswith("nativesdk-") |
| 11 | def isKernel(fn): |
| 12 | inherits = " ".join(dataCache.inherits[fn]) |
| 13 | return inherits.find("/module-base.bbclass") != -1 or inherits.find("/linux-kernel-base.bbclass") != -1 |
| 14 | def isPackageGroup(fn): |
| 15 | inherits = " ".join(dataCache.inherits[fn]) |
| 16 | return "/packagegroup.bbclass" in inherits |
| 17 | def isAllArch(fn): |
| 18 | inherits = " ".join(dataCache.inherits[fn]) |
| 19 | return "/allarch.bbclass" in inherits |
| 20 | def isImage(fn): |
| 21 | return "/image.bbclass" in " ".join(dataCache.inherits[fn]) |
| 22 | |
| 23 | # Always include our own inter-task dependencies |
| 24 | if recipename == depname: |
| 25 | return True |
| 26 | |
| 27 | # Quilt (patch application) changing isn't likely to affect anything |
| 28 | excludelist = ['quilt-native', 'subversion-native', 'git-native'] |
| 29 | if depname in excludelist and recipename != depname: |
| 30 | return False |
| 31 | |
| 32 | # Exclude well defined recipe->dependency |
| 33 | if "%s->%s" % (recipename, depname) in siggen.saferecipedeps: |
| 34 | return False |
| 35 | |
| 36 | # Don't change native/cross/nativesdk recipe dependencies any further |
| 37 | if isNative(recipename) or isCross(recipename) or isNativeSDK(recipename): |
| 38 | return True |
| 39 | |
| 40 | # Only target packages beyond here |
| 41 | |
| 42 | # allarch packagegroups are assumed to have well behaved names which don't change between architecures/tunes |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 43 | if isPackageGroup(fn) and isAllArch(fn) and not isNative(depname): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | return False |
| 45 | |
| 46 | # Exclude well defined machine specific configurations which don't change ABI |
| 47 | if depname in siggen.abisaferecipes and not isImage(fn): |
| 48 | return False |
| 49 | |
| 50 | # Kernel modules are well namespaced. We don't want to depend on the kernel's checksum |
| 51 | # if we're just doing an RRECOMMENDS_xxx = "kernel-module-*", not least because the checksum |
| 52 | # is machine specific. |
| 53 | # Therefore if we're not a kernel or a module recipe (inheriting the kernel classes) |
| 54 | # and we reccomend a kernel-module, we exclude the dependency. |
| 55 | depfn = dep.rsplit(".", 1)[0] |
| 56 | if dataCache and isKernel(depfn) and not isKernel(fn): |
| 57 | for pkg in dataCache.runrecs[fn]: |
| 58 | if " ".join(dataCache.runrecs[fn][pkg]).find("kernel-module-") != -1: |
| 59 | return False |
| 60 | |
| 61 | # Default to keep dependencies |
| 62 | return True |
| 63 | |
| 64 | def sstate_lockedsigs(d): |
| 65 | sigs = {} |
| 66 | types = (d.getVar("SIGGEN_LOCKEDSIGS_TYPES", True) or "").split() |
| 67 | for t in types: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 68 | siggen_lockedsigs_var = "SIGGEN_LOCKEDSIGS_%s" % t |
| 69 | lockedsigs = (d.getVar(siggen_lockedsigs_var, True) or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | for ls in lockedsigs: |
| 71 | pn, task, h = ls.split(":", 2) |
| 72 | if pn not in sigs: |
| 73 | sigs[pn] = {} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 74 | sigs[pn][task] = [h, siggen_lockedsigs_var] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | return sigs |
| 76 | |
| 77 | class SignatureGeneratorOEBasic(bb.siggen.SignatureGeneratorBasic): |
| 78 | name = "OEBasic" |
| 79 | def init_rundepcheck(self, data): |
| 80 | self.abisaferecipes = (data.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE", True) or "").split() |
| 81 | self.saferecipedeps = (data.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS", True) or "").split() |
| 82 | pass |
| 83 | def rundep_check(self, fn, recipename, task, dep, depname, dataCache = None): |
| 84 | return sstate_rundepfilter(self, fn, recipename, task, dep, depname, dataCache) |
| 85 | |
| 86 | class SignatureGeneratorOEBasicHash(bb.siggen.SignatureGeneratorBasicHash): |
| 87 | name = "OEBasicHash" |
| 88 | def init_rundepcheck(self, data): |
| 89 | self.abisaferecipes = (data.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE", True) or "").split() |
| 90 | self.saferecipedeps = (data.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS", True) or "").split() |
| 91 | self.lockedsigs = sstate_lockedsigs(data) |
| 92 | self.lockedhashes = {} |
| 93 | self.lockedpnmap = {} |
| 94 | self.lockedhashfn = {} |
| 95 | self.machine = data.getVar("MACHINE", True) |
| 96 | self.mismatch_msgs = [] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 97 | self.unlockedrecipes = (data.getVar("SIGGEN_UNLOCKED_RECIPES", True) or |
| 98 | "").split() |
| 99 | self.unlockedrecipes = { k: "" for k in self.unlockedrecipes } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 100 | pass |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 101 | |
| 102 | def tasks_resolved(self, virtmap, virtpnmap, dataCache): |
| 103 | # Translate virtual/xxx entries to PN values |
| 104 | newabisafe = [] |
| 105 | for a in self.abisaferecipes: |
| 106 | if a in virtpnmap: |
| 107 | newabisafe.append(virtpnmap[a]) |
| 108 | else: |
| 109 | newabisafe.append(a) |
| 110 | self.abisaferecipes = newabisafe |
| 111 | newsafedeps = [] |
| 112 | for a in self.saferecipedeps: |
| 113 | a1, a2 = a.split("->") |
| 114 | if a1 in virtpnmap: |
| 115 | a1 = virtpnmap[a1] |
| 116 | if a2 in virtpnmap: |
| 117 | a2 = virtpnmap[a2] |
| 118 | newsafedeps.append(a1 + "->" + a2) |
| 119 | self.saferecipedeps = newsafedeps |
| 120 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 121 | def rundep_check(self, fn, recipename, task, dep, depname, dataCache = None): |
| 122 | return sstate_rundepfilter(self, fn, recipename, task, dep, depname, dataCache) |
| 123 | |
| 124 | def get_taskdata(self): |
| 125 | data = super(bb.siggen.SignatureGeneratorBasicHash, self).get_taskdata() |
| 126 | return (data, self.lockedpnmap, self.lockedhashfn) |
| 127 | |
| 128 | def set_taskdata(self, data): |
| 129 | coredata, self.lockedpnmap, self.lockedhashfn = data |
| 130 | super(bb.siggen.SignatureGeneratorBasicHash, self).set_taskdata(coredata) |
| 131 | |
| 132 | def dump_sigs(self, dataCache, options): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 133 | sigfile = os.getcwd() + "/locked-sigs.inc" |
| 134 | bb.plain("Writing locked sigs to %s" % sigfile) |
| 135 | self.dump_lockedsigs(sigfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 136 | return super(bb.siggen.SignatureGeneratorBasicHash, self).dump_sigs(dataCache, options) |
| 137 | |
| 138 | def get_taskhash(self, fn, task, deps, dataCache): |
| 139 | h = super(bb.siggen.SignatureGeneratorBasicHash, self).get_taskhash(fn, task, deps, dataCache) |
| 140 | |
| 141 | recipename = dataCache.pkg_fn[fn] |
| 142 | self.lockedpnmap[fn] = recipename |
| 143 | self.lockedhashfn[fn] = dataCache.hashfn[fn] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 144 | |
| 145 | unlocked = False |
| 146 | if recipename in self.unlockedrecipes: |
| 147 | unlocked = True |
| 148 | else: |
| 149 | def recipename_from_dep(dep): |
| 150 | # The dep entry will look something like |
| 151 | # /path/path/recipename.bb.task, virtual:native:/p/foo.bb.task, |
| 152 | # ... |
| 153 | fn = dep.rsplit('.', 1)[0] |
| 154 | return dataCache.pkg_fn[fn] |
| 155 | |
| 156 | # If any unlocked recipe is in the direct dependencies then the |
| 157 | # current recipe should be unlocked as well. |
| 158 | depnames = [ recipename_from_dep(x) for x in deps ] |
| 159 | if any(x in y for y in depnames for x in self.unlockedrecipes): |
| 160 | self.unlockedrecipes[recipename] = '' |
| 161 | unlocked = True |
| 162 | |
| 163 | if not unlocked and recipename in self.lockedsigs: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | if task in self.lockedsigs[recipename]: |
| 165 | k = fn + "." + task |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 166 | h_locked = self.lockedsigs[recipename][task][0] |
| 167 | var = self.lockedsigs[recipename][task][1] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 168 | self.lockedhashes[k] = h_locked |
| 169 | self.taskhash[k] = h_locked |
| 170 | #bb.warn("Using %s %s %s" % (recipename, task, h)) |
| 171 | |
| 172 | if h != h_locked: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 173 | self.mismatch_msgs.append('The %s:%s sig is computed to be %s, but the sig is locked to %s in %s' |
| 174 | % (recipename, task, h, h_locked, var)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 175 | |
| 176 | return h_locked |
| 177 | #bb.warn("%s %s %s" % (recipename, task, h)) |
| 178 | return h |
| 179 | |
| 180 | def dump_sigtask(self, fn, task, stampbase, runtime): |
| 181 | k = fn + "." + task |
| 182 | if k in self.lockedhashes: |
| 183 | return |
| 184 | super(bb.siggen.SignatureGeneratorBasicHash, self).dump_sigtask(fn, task, stampbase, runtime) |
| 185 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 186 | def dump_lockedsigs(self, sigfile, taskfilter=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 187 | types = {} |
| 188 | for k in self.runtaskdeps: |
| 189 | if taskfilter: |
| 190 | if not k in taskfilter: |
| 191 | continue |
| 192 | fn = k.rsplit(".",1)[0] |
| 193 | t = self.lockedhashfn[fn].split(" ")[1].split(":")[5] |
| 194 | t = 't-' + t.replace('_', '-') |
| 195 | if t not in types: |
| 196 | types[t] = [] |
| 197 | types[t].append(k) |
| 198 | |
| 199 | with open(sigfile, "w") as f: |
| 200 | for t in types: |
| 201 | f.write('SIGGEN_LOCKEDSIGS_%s = "\\\n' % t) |
| 202 | types[t].sort() |
| 203 | sortedk = sorted(types[t], key=lambda k: self.lockedpnmap[k.rsplit(".",1)[0]]) |
| 204 | for k in sortedk: |
| 205 | fn = k.rsplit(".",1)[0] |
| 206 | task = k.rsplit(".",1)[1] |
| 207 | if k not in self.taskhash: |
| 208 | continue |
| 209 | f.write(" " + self.lockedpnmap[fn] + ":" + task + ":" + self.taskhash[k] + " \\\n") |
| 210 | f.write(' "\n') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 211 | f.write('SIGGEN_LOCKEDSIGS_TYPES_%s = "%s"' % (self.machine, " ".join(list(types.keys())))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 212 | |
| 213 | def checkhashes(self, missed, ret, sq_fn, sq_task, sq_hash, sq_hashfn, d): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 214 | warn_msgs = [] |
| 215 | error_msgs = [] |
| 216 | sstate_missing_msgs = [] |
| 217 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 218 | for task in range(len(sq_fn)): |
| 219 | if task not in ret: |
| 220 | for pn in self.lockedsigs: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 221 | if sq_hash[task] in iter(self.lockedsigs[pn].values()): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 222 | if sq_task[task] == 'do_shared_workdir': |
| 223 | continue |
| 224 | sstate_missing_msgs.append("Locked sig is set for %s:%s (%s) yet not in sstate cache?" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 225 | % (pn, sq_task[task], sq_hash[task])) |
| 226 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 227 | checklevel = d.getVar("SIGGEN_LOCKEDSIGS_TASKSIG_CHECK", True) |
| 228 | if checklevel == 'warn': |
| 229 | warn_msgs += self.mismatch_msgs |
| 230 | elif checklevel == 'error': |
| 231 | error_msgs += self.mismatch_msgs |
| 232 | |
| 233 | checklevel = d.getVar("SIGGEN_LOCKEDSIGS_SSTATE_EXISTS_CHECK", True) |
| 234 | if checklevel == 'warn': |
| 235 | warn_msgs += sstate_missing_msgs |
| 236 | elif checklevel == 'error': |
| 237 | error_msgs += sstate_missing_msgs |
| 238 | |
| 239 | if warn_msgs: |
| 240 | bb.warn("\n".join(warn_msgs)) |
| 241 | if error_msgs: |
| 242 | bb.fatal("\n".join(error_msgs)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 243 | |
| 244 | |
| 245 | # Insert these classes into siggen's namespace so it can see and select them |
| 246 | bb.siggen.SignatureGeneratorOEBasic = SignatureGeneratorOEBasic |
| 247 | bb.siggen.SignatureGeneratorOEBasicHash = SignatureGeneratorOEBasicHash |
| 248 | |
| 249 | |
| 250 | def find_siginfo(pn, taskname, taskhashlist, d): |
| 251 | """ Find signature data files for comparison purposes """ |
| 252 | |
| 253 | import fnmatch |
| 254 | import glob |
| 255 | |
| 256 | if taskhashlist: |
| 257 | hashfiles = {} |
| 258 | |
| 259 | if not taskname: |
| 260 | # We have to derive pn and taskname |
| 261 | key = pn |
| 262 | splitit = key.split('.bb.') |
| 263 | taskname = splitit[1] |
| 264 | pn = os.path.basename(splitit[0]).split('_')[0] |
| 265 | if key.startswith('virtual:native:'): |
| 266 | pn = pn + '-native' |
| 267 | |
| 268 | filedates = {} |
| 269 | |
| 270 | # First search in stamps dir |
| 271 | localdata = d.createCopy() |
| 272 | localdata.setVar('MULTIMACH_TARGET_SYS', '*') |
| 273 | localdata.setVar('PN', pn) |
| 274 | localdata.setVar('PV', '*') |
| 275 | localdata.setVar('PR', '*') |
| 276 | localdata.setVar('EXTENDPE', '') |
| 277 | stamp = localdata.getVar('STAMP', True) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 278 | if pn.startswith("gcc-source"): |
| 279 | # gcc-source shared workdir is a special case :( |
| 280 | stamp = localdata.expand("${STAMPS_DIR}/work-shared/gcc-${PV}-${PR}") |
| 281 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 282 | filespec = '%s.%s.sigdata.*' % (stamp, taskname) |
| 283 | foundall = False |
| 284 | import glob |
| 285 | for fullpath in glob.glob(filespec): |
| 286 | match = False |
| 287 | if taskhashlist: |
| 288 | for taskhash in taskhashlist: |
| 289 | if fullpath.endswith('.%s' % taskhash): |
| 290 | hashfiles[taskhash] = fullpath |
| 291 | if len(hashfiles) == len(taskhashlist): |
| 292 | foundall = True |
| 293 | break |
| 294 | else: |
| 295 | try: |
| 296 | filedates[fullpath] = os.stat(fullpath).st_mtime |
| 297 | except OSError: |
| 298 | continue |
| 299 | |
| 300 | if not taskhashlist or (len(filedates) < 2 and not foundall): |
| 301 | # That didn't work, look in sstate-cache |
| 302 | hashes = taskhashlist or ['*'] |
| 303 | localdata = bb.data.createCopy(d) |
| 304 | for hashval in hashes: |
| 305 | localdata.setVar('PACKAGE_ARCH', '*') |
| 306 | localdata.setVar('TARGET_VENDOR', '*') |
| 307 | localdata.setVar('TARGET_OS', '*') |
| 308 | localdata.setVar('PN', pn) |
| 309 | localdata.setVar('PV', '*') |
| 310 | localdata.setVar('PR', '*') |
| 311 | localdata.setVar('BB_TASKHASH', hashval) |
| 312 | swspec = localdata.getVar('SSTATE_SWSPEC', True) |
| 313 | if taskname in ['do_fetch', 'do_unpack', 'do_patch', 'do_populate_lic', 'do_preconfigure'] and swspec: |
| 314 | localdata.setVar('SSTATE_PKGSPEC', '${SSTATE_SWSPEC}') |
| 315 | elif pn.endswith('-native') or "-cross-" in pn or "-crosssdk-" in pn: |
| 316 | localdata.setVar('SSTATE_EXTRAPATH', "${NATIVELSBSTRING}/") |
| 317 | sstatename = taskname[3:] |
| 318 | filespec = '%s_%s.*.siginfo' % (localdata.getVar('SSTATE_PKG', True), sstatename) |
| 319 | |
| 320 | if hashval != '*': |
| 321 | sstatedir = "%s/%s" % (d.getVar('SSTATE_DIR', True), hashval[:2]) |
| 322 | else: |
| 323 | sstatedir = d.getVar('SSTATE_DIR', True) |
| 324 | |
| 325 | for root, dirs, files in os.walk(sstatedir): |
| 326 | for fn in files: |
| 327 | fullpath = os.path.join(root, fn) |
| 328 | if fnmatch.fnmatch(fullpath, filespec): |
| 329 | if taskhashlist: |
| 330 | hashfiles[hashval] = fullpath |
| 331 | else: |
| 332 | try: |
| 333 | filedates[fullpath] = os.stat(fullpath).st_mtime |
| 334 | except: |
| 335 | continue |
| 336 | |
| 337 | if taskhashlist: |
| 338 | return hashfiles |
| 339 | else: |
| 340 | return filedates |
| 341 | |
| 342 | bb.siggen.find_siginfo = find_siginfo |
| 343 | |
| 344 | |
| 345 | def sstate_get_manifest_filename(task, d): |
| 346 | """ |
| 347 | Return the sstate manifest file path for a particular task. |
| 348 | Also returns the datastore that can be used to query related variables. |
| 349 | """ |
| 350 | d2 = d.createCopy() |
| 351 | extrainf = d.getVarFlag("do_" + task, 'stamp-extra-info', True) |
| 352 | if extrainf: |
| 353 | d2.setVar("SSTATE_MANMACH", extrainf) |
| 354 | return (d2.expand("${SSTATE_MANFILEPREFIX}.%s" % task), d2) |