diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-02-15 23:17:29 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-02-21 23:37:26 +0000 |
commit | 478cb0ce2c71273799695240845a687aaac0cb0c (patch) | |
tree | 7433e60ecbf569d6dd0a8bc9a63cb7140c9b90eb /bitbake/lib/bb/data_smart.py | |
parent | 8f4b84c98cbe962a3c432b404c7d66b8e518cd40 (diff) | |
download | poky-478cb0ce2c71273799695240845a687aaac0cb0c.tar.gz |
bitbake: data_smart/cookerdata: Add variable remapping support
This change adds support for improving the user experience when variables
are renamed. This isn't as simple as it might first appear since some
bitbake variables are used through the environment before the datastore
exists, some are bitbake variables which we know about straight away
and some are metadata defined which we don't know about until later.
This patch adds support for handling these different cases, allowing a list
of bitbake renamed variables to be defined in bitbake itself and allows this
to be extended through the metadata using BB_RENAMED_VARIABLES.
In order to give the best feedback to the user, we default to turning on
variable history tracking in the base data store from knotty, which allows
filename and line number information to be shown.
(Bitbake rev: bd50a5d5e4b4fa90844464396887ebdff0d4e5f7)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/data_smart.py')
-rw-r--r-- | bitbake/lib/bb/data_smart.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py index cb2d4b620f..01604ec36c 100644 --- a/bitbake/lib/bb/data_smart.py +++ b/bitbake/lib/bb/data_smart.py | |||
@@ -33,6 +33,9 @@ __expand_python_regexp__ = re.compile(r"\${@.+?}") | |||
33 | __whitespace_split__ = re.compile(r'(\s)') | 33 | __whitespace_split__ = re.compile(r'(\s)') |
34 | __override_regexp__ = re.compile(r'[a-z0-9]+') | 34 | __override_regexp__ = re.compile(r'[a-z0-9]+') |
35 | 35 | ||
36 | bitbake_renamed_vars = { | ||
37 | } | ||
38 | |||
36 | def infer_caller_details(loginfo, parent = False, varval = True): | 39 | def infer_caller_details(loginfo, parent = False, varval = True): |
37 | """Save the caller the trouble of specifying everything.""" | 40 | """Save the caller the trouble of specifying everything.""" |
38 | # Save effort. | 41 | # Save effort. |
@@ -336,6 +339,16 @@ class VariableHistory(object): | |||
336 | lines.append(line) | 339 | lines.append(line) |
337 | return lines | 340 | return lines |
338 | 341 | ||
342 | def get_variable_refs(self, var): | ||
343 | """Return a dict of file/line references""" | ||
344 | var_history = self.variable(var) | ||
345 | refs = {} | ||
346 | for event in var_history: | ||
347 | if event['file'] not in refs: | ||
348 | refs[event['file']] = [] | ||
349 | refs[event['file']].append(event['line']) | ||
350 | return refs | ||
351 | |||
339 | def get_variable_items_files(self, var): | 352 | def get_variable_items_files(self, var): |
340 | """ | 353 | """ |
341 | Use variable history to map items added to a list variable and | 354 | Use variable history to map items added to a list variable and |
@@ -377,6 +390,8 @@ class DataSmart(MutableMapping): | |||
377 | self.inchistory = IncludeHistory() | 390 | self.inchistory = IncludeHistory() |
378 | self.varhistory = VariableHistory(self) | 391 | self.varhistory = VariableHistory(self) |
379 | self._tracking = False | 392 | self._tracking = False |
393 | self._var_renames = {} | ||
394 | self._var_renames.update(bitbake_renamed_vars) | ||
380 | 395 | ||
381 | self.expand_cache = {} | 396 | self.expand_cache = {} |
382 | 397 | ||
@@ -491,6 +506,16 @@ class DataSmart(MutableMapping): | |||
491 | def hasOverrides(self, var): | 506 | def hasOverrides(self, var): |
492 | return var in self.overridedata | 507 | return var in self.overridedata |
493 | 508 | ||
509 | def _print_rename_error(self, var, loginfo): | ||
510 | info = "" | ||
511 | if "file" in loginfo: | ||
512 | info = " file: %s" % loginfo["file"] | ||
513 | if "line" in loginfo: | ||
514 | info += " line: %s" % loginfo["line"] | ||
515 | if info: | ||
516 | info = " (%s)" % info.strip() | ||
517 | bb.erroronce('Variable %s has been renamed to %s%s' % (var, self._var_renames[var], info)) | ||
518 | |||
494 | def setVar(self, var, value, **loginfo): | 519 | def setVar(self, var, value, **loginfo): |
495 | #print("var=" + str(var) + " val=" + str(value)) | 520 | #print("var=" + str(var) + " val=" + str(value)) |
496 | 521 | ||
@@ -502,6 +527,10 @@ class DataSmart(MutableMapping): | |||
502 | info += " line: %s" % loginfo["line"] | 527 | info += " line: %s" % loginfo["line"] |
503 | bb.fatal("Variable %s contains an operation using the old override syntax. Please convert this layer/metadata before attempting to use with a newer bitbake." % info) | 528 | bb.fatal("Variable %s contains an operation using the old override syntax. Please convert this layer/metadata before attempting to use with a newer bitbake." % info) |
504 | 529 | ||
530 | shortvar = var.split(":", 1)[0] | ||
531 | if shortvar in self._var_renames: | ||
532 | self._print_rename_error(shortvar, loginfo) | ||
533 | |||
505 | self.expand_cache = {} | 534 | self.expand_cache = {} |
506 | parsing=False | 535 | parsing=False |
507 | if 'parsing' in loginfo: | 536 | if 'parsing' in loginfo: |
@@ -687,6 +716,12 @@ class DataSmart(MutableMapping): | |||
687 | def setVarFlag(self, var, flag, value, **loginfo): | 716 | def setVarFlag(self, var, flag, value, **loginfo): |
688 | self.expand_cache = {} | 717 | self.expand_cache = {} |
689 | 718 | ||
719 | if var == "BB_RENAMED_VARIABLES": | ||
720 | self._var_renames[flag] = value | ||
721 | |||
722 | if var in self._var_renames: | ||
723 | self._print_rename_error(var, loginfo) | ||
724 | |||
690 | if 'op' not in loginfo: | 725 | if 'op' not in loginfo: |
691 | loginfo['op'] = "set" | 726 | loginfo['op'] = "set" |
692 | loginfo['flag'] = flag | 727 | loginfo['flag'] = flag |
@@ -926,6 +961,7 @@ class DataSmart(MutableMapping): | |||
926 | data.inchistory = self.inchistory.copy() | 961 | data.inchistory = self.inchistory.copy() |
927 | 962 | ||
928 | data._tracking = self._tracking | 963 | data._tracking = self._tracking |
964 | data._var_renames = self._var_renames | ||
929 | 965 | ||
930 | data.overrides = None | 966 | data.overrides = None |
931 | data.overridevars = copy.copy(self.overridevars) | 967 | data.overridevars = copy.copy(self.overridevars) |