Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | """ |
| 2 | BitBake 'Data' implementations |
| 3 | |
| 4 | Functions for interacting with the data structure used by the |
| 5 | BitBake build tools. |
| 6 | |
| 7 | The expandKeys and update_data are the most expensive |
| 8 | operations. At night the cookie monster came by and |
| 9 | suggested 'give me cookies on setting the variables and |
| 10 | things will work out'. Taking this suggestion into account |
| 11 | applying the skills from the not yet passed 'Entwurf und |
| 12 | Analyse von Algorithmen' lecture and the cookie |
| 13 | monster seems to be right. We will track setVar more carefully |
| 14 | to have faster update_data and expandKeys operations. |
| 15 | |
| 16 | This is a trade-off between speed and memory again but |
| 17 | the speed is more critical here. |
| 18 | """ |
| 19 | |
| 20 | # Copyright (C) 2003, 2004 Chris Larson |
| 21 | # Copyright (C) 2005 Holger Hans Peter Freyther |
| 22 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 23 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | # |
| 25 | # Based on functions from the base bb module, Copyright 2003 Holger Schurig |
| 26 | |
| 27 | import sys, os, re |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 28 | import hashlib |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 29 | if sys.argv[0][-5:] == "pydoc": |
| 30 | path = os.path.dirname(os.path.dirname(sys.argv[1])) |
| 31 | else: |
| 32 | path = os.path.dirname(os.path.dirname(sys.argv[0])) |
| 33 | sys.path.insert(0, path) |
| 34 | from itertools import groupby |
| 35 | |
| 36 | from bb import data_smart |
| 37 | from bb import codeparser |
| 38 | import bb |
| 39 | |
| 40 | logger = data_smart.logger |
| 41 | _dict_type = data_smart.DataSmart |
| 42 | |
| 43 | def init(): |
| 44 | """Return a new object representing the Bitbake data""" |
| 45 | return _dict_type() |
| 46 | |
| 47 | def init_db(parent = None): |
| 48 | """Return a new object representing the Bitbake data, |
| 49 | optionally based on an existing object""" |
| 50 | if parent is not None: |
| 51 | return parent.createCopy() |
| 52 | else: |
| 53 | return _dict_type() |
| 54 | |
| 55 | def createCopy(source): |
| 56 | """Link the source set to the destination |
| 57 | If one does not find the value in the destination set, |
| 58 | search will go on to the source set to get the value. |
| 59 | Value from source are copy-on-write. i.e. any try to |
| 60 | modify one of them will end up putting the modified value |
| 61 | in the destination set. |
| 62 | """ |
| 63 | return source.createCopy() |
| 64 | |
| 65 | def initVar(var, d): |
| 66 | """Non-destructive var init for data structure""" |
| 67 | d.initVar(var) |
| 68 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 69 | def keys(d): |
| 70 | """Return a list of keys in d""" |
| 71 | return d.keys() |
| 72 | |
| 73 | |
| 74 | __expand_var_regexp__ = re.compile(r"\${[^{}]+}") |
| 75 | __expand_python_regexp__ = re.compile(r"\${@.+?}") |
| 76 | |
| 77 | def expand(s, d, varname = None): |
| 78 | """Variable expansion using the data store""" |
| 79 | return d.expand(s, varname) |
| 80 | |
| 81 | def expandKeys(alterdata, readdata = None): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 82 | if readdata is None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 83 | readdata = alterdata |
| 84 | |
| 85 | todolist = {} |
| 86 | for key in alterdata: |
| 87 | if not '${' in key: |
| 88 | continue |
| 89 | |
| 90 | ekey = expand(key, readdata) |
| 91 | if key == ekey: |
| 92 | continue |
| 93 | todolist[key] = ekey |
| 94 | |
| 95 | # These two for loops are split for performance to maximise the |
| 96 | # usefulness of the expand cache |
| 97 | for key in sorted(todolist): |
| 98 | ekey = todolist[key] |
| 99 | newval = alterdata.getVar(ekey, False) |
| 100 | if newval is not None: |
| 101 | val = alterdata.getVar(key, False) |
| 102 | if val is not None: |
| 103 | bb.warn("Variable key %s (%s) replaces original key %s (%s)." % (key, val, ekey, newval)) |
| 104 | alterdata.renameVar(key, ekey) |
| 105 | |
| 106 | def inheritFromOS(d, savedenv, permitted): |
| 107 | """Inherit variables from the initial environment.""" |
| 108 | exportlist = bb.utils.preserved_envvars_exported() |
| 109 | for s in savedenv.keys(): |
| 110 | if s in permitted: |
| 111 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 112 | d.setVar(s, savedenv.getVar(s), op = 'from env') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 113 | if s in exportlist: |
| 114 | d.setVarFlag(s, "export", True, op = 'auto env export') |
| 115 | except TypeError: |
| 116 | pass |
| 117 | |
| 118 | def emit_var(var, o=sys.__stdout__, d = init(), all=False): |
| 119 | """Emit a variable to be sourced by a shell.""" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 120 | func = d.getVarFlag(var, "func", False) |
| 121 | if d.getVarFlag(var, 'python', False) and func: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 122 | return False |
| 123 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 124 | export = d.getVarFlag(var, "export", False) |
| 125 | unexport = d.getVarFlag(var, "unexport", False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 126 | if not all and not export and not unexport and not func: |
| 127 | return False |
| 128 | |
| 129 | try: |
| 130 | if all: |
| 131 | oval = d.getVar(var, False) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 132 | val = d.getVar(var) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 133 | except (KeyboardInterrupt): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 134 | raise |
| 135 | except Exception as exc: |
| 136 | o.write('# expansion of %s threw %s: %s\n' % (var, exc.__class__.__name__, str(exc))) |
| 137 | return False |
| 138 | |
| 139 | if all: |
| 140 | d.varhistory.emit(var, oval, val, o, d) |
| 141 | |
| 142 | if (var.find("-") != -1 or var.find(".") != -1 or var.find('{') != -1 or var.find('}') != -1 or var.find('+') != -1) and not all: |
| 143 | return False |
| 144 | |
| 145 | varExpanded = d.expand(var) |
| 146 | |
| 147 | if unexport: |
| 148 | o.write('unset %s\n' % varExpanded) |
| 149 | return False |
| 150 | |
| 151 | if val is None: |
| 152 | return False |
| 153 | |
| 154 | val = str(val) |
| 155 | |
| 156 | if varExpanded.startswith("BASH_FUNC_"): |
| 157 | varExpanded = varExpanded[10:-2] |
| 158 | val = val[3:] # Strip off "() " |
| 159 | o.write("%s() %s\n" % (varExpanded, val)) |
| 160 | o.write("export -f %s\n" % (varExpanded)) |
| 161 | return True |
| 162 | |
| 163 | if func: |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 164 | # Write a comment indicating where the shell function came from (line number and filename) to make it easier |
| 165 | # for the user to diagnose task failures. This comment is also used by build.py to determine the metadata |
| 166 | # location of shell functions. |
| 167 | o.write("# line: {0}, file: {1}\n".format( |
| 168 | d.getVarFlag(var, "lineno", False), |
| 169 | d.getVarFlag(var, "filename", False))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 170 | # NOTE: should probably check for unbalanced {} within the var |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 171 | val = val.rstrip('\n') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 172 | o.write("%s() {\n%s\n}\n" % (varExpanded, val)) |
| 173 | return 1 |
| 174 | |
| 175 | if export: |
| 176 | o.write('export ') |
| 177 | |
| 178 | # if we're going to output this within doublequotes, |
| 179 | # to a shell, we need to escape the quotes in the var |
| 180 | alter = re.sub('"', '\\"', val) |
| 181 | alter = re.sub('\n', ' \\\n', alter) |
| 182 | alter = re.sub('\\$', '\\\\$', alter) |
| 183 | o.write('%s="%s"\n' % (varExpanded, alter)) |
| 184 | return False |
| 185 | |
| 186 | def emit_env(o=sys.__stdout__, d = init(), all=False): |
| 187 | """Emits all items in the data store in a format such that it can be sourced by a shell.""" |
| 188 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 189 | isfunc = lambda key: bool(d.getVarFlag(key, "func", False)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 190 | keys = sorted((key for key in d.keys() if not key.startswith("__")), key=isfunc) |
| 191 | grouped = groupby(keys, isfunc) |
| 192 | for isfunc, keys in grouped: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 193 | for key in sorted(keys): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 194 | emit_var(key, o, d, all and not isfunc) and o.write('\n') |
| 195 | |
| 196 | def exported_keys(d): |
| 197 | return (key for key in d.keys() if not key.startswith('__') and |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 198 | d.getVarFlag(key, 'export', False) and |
| 199 | not d.getVarFlag(key, 'unexport', False)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 200 | |
| 201 | def exported_vars(d): |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 202 | k = list(exported_keys(d)) |
| 203 | for key in k: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 204 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 205 | value = d.getVar(key) |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 206 | except Exception as err: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 207 | bb.warn("%s: Unable to export ${%s}: %s" % (d.getVar("FILE"), key, err)) |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 208 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 209 | |
| 210 | if value is not None: |
| 211 | yield key, str(value) |
| 212 | |
| 213 | def emit_func(func, o=sys.__stdout__, d = init()): |
| 214 | """Emits all items in the data store in a format such that it can be sourced by a shell.""" |
| 215 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 216 | keys = (key for key in d.keys() if not key.startswith("__") and not d.getVarFlag(key, "func", False)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 217 | for key in sorted(keys): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 218 | emit_var(key, o, d, False) |
| 219 | |
| 220 | o.write('\n') |
| 221 | emit_var(func, o, d, False) and o.write('\n') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 222 | newdeps = bb.codeparser.ShellParser(func, logger).parse_shell(d.getVar(func)) |
| 223 | newdeps |= set((d.getVarFlag(func, "vardeps") or "").split()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 224 | seen = set() |
| 225 | while newdeps: |
| 226 | deps = newdeps |
| 227 | seen |= deps |
| 228 | newdeps = set() |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 229 | for dep in sorted(deps): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 230 | if d.getVarFlag(dep, "func", False) and not d.getVarFlag(dep, "python", False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 231 | emit_var(dep, o, d, False) and o.write('\n') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 232 | newdeps |= bb.codeparser.ShellParser(dep, logger).parse_shell(d.getVar(dep)) |
| 233 | newdeps |= set((d.getVarFlag(dep, "vardeps") or "").split()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 234 | newdeps -= seen |
| 235 | |
| 236 | _functionfmt = """ |
| 237 | def {function}(d): |
| 238 | {body}""" |
| 239 | |
| 240 | def emit_func_python(func, o=sys.__stdout__, d = init()): |
| 241 | """Emits all items in the data store in a format such that it can be sourced by a shell.""" |
| 242 | |
| 243 | def write_func(func, o, call = False): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 244 | body = d.getVar(func, False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 245 | if not body.startswith("def"): |
| 246 | body = _functionfmt.format(function=func, body=body) |
| 247 | |
| 248 | o.write(body.strip() + "\n\n") |
| 249 | if call: |
| 250 | o.write(func + "(d)" + "\n\n") |
| 251 | |
| 252 | write_func(func, o, True) |
| 253 | pp = bb.codeparser.PythonParser(func, logger) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 254 | pp.parse_python(d.getVar(func, False)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 255 | newdeps = pp.execs |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 256 | newdeps |= set((d.getVarFlag(func, "vardeps") or "").split()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 257 | seen = set() |
| 258 | while newdeps: |
| 259 | deps = newdeps |
| 260 | seen |= deps |
| 261 | newdeps = set() |
| 262 | for dep in deps: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 263 | if d.getVarFlag(dep, "func", False) and d.getVarFlag(dep, "python", False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 264 | write_func(dep, o) |
| 265 | pp = bb.codeparser.PythonParser(dep, logger) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 266 | pp.parse_python(d.getVar(dep, False)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 267 | newdeps |= pp.execs |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 268 | newdeps |= set((d.getVarFlag(dep, "vardeps") or "").split()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 269 | newdeps -= seen |
| 270 | |
| 271 | def update_data(d): |
| 272 | """Performs final steps upon the datastore, including application of overrides""" |
| 273 | d.finalize(parent = True) |
| 274 | |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame^] | 275 | def build_dependencies(key, keys, shelldeps, varflagsexcl, ignored_vars, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 276 | deps = set() |
| 277 | try: |
| 278 | if key[-1] == ']': |
| 279 | vf = key[:-1].split('[') |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 280 | value, parser = d.getVarFlag(vf[0], vf[1], False, retparser=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 281 | deps |= parser.references |
| 282 | deps = deps | (keys & parser.execs) |
| 283 | return deps, value |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 284 | varflags = d.getVarFlags(key, ["vardeps", "vardepvalue", "vardepsexclude", "exports", "postfuncs", "prefuncs", "lineno", "filename"]) or {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 285 | vardeps = varflags.get("vardeps") |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame^] | 286 | exclusions = varflags.get("vardepsexclude", "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 287 | |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame^] | 288 | def handle_contains(value, contains, exclusions, d): |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 289 | newvalue = [] |
| 290 | if value: |
| 291 | newvalue.append(str(value)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 292 | for k in sorted(contains): |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame^] | 293 | if k in exclusions or k in ignored_vars: |
| 294 | continue |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 295 | l = (d.getVar(k) or "").split() |
| 296 | for item in sorted(contains[k]): |
| 297 | for word in item.split(): |
| 298 | if not word in l: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 299 | newvalue.append("\n%s{%s} = Unset" % (k, item)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 300 | break |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 301 | else: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 302 | newvalue.append("\n%s{%s} = Set" % (k, item)) |
| 303 | return "".join(newvalue) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 304 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 305 | def handle_remove(value, deps, removes, d): |
| 306 | for r in sorted(removes): |
| 307 | r2 = d.expandWithRefs(r, None) |
| 308 | value += "\n_remove of %s" % r |
| 309 | deps |= r2.references |
| 310 | deps = deps | (keys & r2.execs) |
| 311 | return value |
| 312 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 313 | if "vardepvalue" in varflags: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 314 | value = varflags.get("vardepvalue") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 315 | elif varflags.get("func"): |
| 316 | if varflags.get("python"): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 317 | value = d.getVarFlag(key, "_content", False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 318 | parser = bb.codeparser.PythonParser(key, logger) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 319 | parser.parse_python(value, filename=varflags.get("filename"), lineno=varflags.get("lineno")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 320 | deps = deps | parser.references |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 321 | deps = deps | (keys & parser.execs) |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame^] | 322 | value = handle_contains(value, parser.contains, exclusions, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 323 | else: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 324 | value, parsedvar = d.getVarFlag(key, "_content", False, retparser=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 325 | parser = bb.codeparser.ShellParser(key, logger) |
| 326 | parser.parse_shell(parsedvar.value) |
| 327 | deps = deps | shelldeps |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 328 | deps = deps | parsedvar.references |
| 329 | deps = deps | (keys & parser.execs) | (keys & parsedvar.execs) |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame^] | 330 | value = handle_contains(value, parsedvar.contains, exclusions, d) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 331 | if hasattr(parsedvar, "removes"): |
| 332 | value = handle_remove(value, deps, parsedvar.removes, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 333 | if vardeps is None: |
| 334 | parser.log.flush() |
| 335 | if "prefuncs" in varflags: |
| 336 | deps = deps | set(varflags["prefuncs"].split()) |
| 337 | if "postfuncs" in varflags: |
| 338 | deps = deps | set(varflags["postfuncs"].split()) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 339 | if "exports" in varflags: |
| 340 | deps = deps | set(varflags["exports"].split()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 341 | else: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 342 | value, parser = d.getVarFlag(key, "_content", False, retparser=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 343 | deps |= parser.references |
| 344 | deps = deps | (keys & parser.execs) |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame^] | 345 | value = handle_contains(value, parser.contains, exclusions, d) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 346 | if hasattr(parser, "removes"): |
| 347 | value = handle_remove(value, deps, parser.removes, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 348 | |
| 349 | if "vardepvalueexclude" in varflags: |
| 350 | exclude = varflags.get("vardepvalueexclude") |
| 351 | for excl in exclude.split('|'): |
| 352 | if excl: |
| 353 | value = value.replace(excl, '') |
| 354 | |
| 355 | # Add varflags, assuming an exclusion list is set |
| 356 | if varflagsexcl: |
| 357 | varfdeps = [] |
| 358 | for f in varflags: |
| 359 | if f not in varflagsexcl: |
| 360 | varfdeps.append('%s[%s]' % (key, f)) |
| 361 | if varfdeps: |
| 362 | deps |= set(varfdeps) |
| 363 | |
| 364 | deps |= set((vardeps or "").split()) |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame^] | 365 | deps -= set(exclusions) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 366 | except bb.parse.SkipRecipe: |
| 367 | raise |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 368 | except Exception as e: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 369 | bb.warn("Exception during build_dependencies for %s" % key) |
| 370 | raise |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 371 | return deps, value |
| 372 | #bb.note("Variable %s references %s and calls %s" % (key, str(deps), str(execs))) |
| 373 | #d.setVarFlag(key, "vardeps", deps) |
| 374 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 375 | def generate_dependencies(d, ignored_vars): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 376 | |
| 377 | keys = set(key for key in d if not key.startswith("__")) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 378 | shelldeps = set(key for key in d.getVar("__exportlist", False) if d.getVarFlag(key, "export", False) and not d.getVarFlag(key, "unexport", False)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 379 | varflagsexcl = d.getVar('BB_SIGNATURE_EXCLUDE_FLAGS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 380 | |
| 381 | deps = {} |
| 382 | values = {} |
| 383 | |
| 384 | tasklist = d.getVar('__BBTASKS', False) or [] |
| 385 | for task in tasklist: |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame^] | 386 | deps[task], values[task] = build_dependencies(task, keys, shelldeps, varflagsexcl, ignored_vars, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 387 | newdeps = deps[task] |
| 388 | seen = set() |
| 389 | while newdeps: |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 390 | nextdeps = newdeps - ignored_vars |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 391 | seen |= nextdeps |
| 392 | newdeps = set() |
| 393 | for dep in nextdeps: |
| 394 | if dep not in deps: |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame^] | 395 | deps[dep], values[dep] = build_dependencies(dep, keys, shelldeps, varflagsexcl, ignored_vars, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 396 | newdeps |= deps[dep] |
| 397 | newdeps -= seen |
| 398 | #print "For %s: %s" % (task, str(deps[task])) |
| 399 | return tasklist, deps, values |
| 400 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 401 | def generate_dependency_hash(tasklist, gendeps, lookupcache, ignored_vars, fn): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 402 | taskdeps = {} |
| 403 | basehash = {} |
| 404 | |
| 405 | for task in tasklist: |
| 406 | data = lookupcache[task] |
| 407 | |
| 408 | if data is None: |
| 409 | bb.error("Task %s from %s seems to be empty?!" % (task, fn)) |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 410 | data = [] |
| 411 | else: |
| 412 | data = [data] |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 413 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 414 | gendeps[task] -= ignored_vars |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 415 | newdeps = gendeps[task] |
| 416 | seen = set() |
| 417 | while newdeps: |
| 418 | nextdeps = newdeps |
| 419 | seen |= nextdeps |
| 420 | newdeps = set() |
| 421 | for dep in nextdeps: |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 422 | if dep in ignored_vars: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 423 | continue |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 424 | gendeps[dep] -= ignored_vars |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 425 | newdeps |= gendeps[dep] |
| 426 | newdeps -= seen |
| 427 | |
| 428 | alldeps = sorted(seen) |
| 429 | for dep in alldeps: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 430 | data.append(dep) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 431 | var = lookupcache[dep] |
| 432 | if var is not None: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 433 | data.append(str(var)) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 434 | k = fn + ":" + task |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 435 | basehash[k] = hashlib.sha256("".join(data).encode("utf-8")).hexdigest() |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 436 | taskdeps[task] = alldeps |
| 437 | |
| 438 | return taskdeps, basehash |
| 439 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 440 | def inherits_class(klass, d): |
| 441 | val = d.getVar('__inherit_cache', False) or [] |
| 442 | needle = os.path.join('classes', '%s.bbclass' % klass) |
| 443 | for v in val: |
| 444 | if v.endswith(needle): |
| 445 | return True |
| 446 | return False |