summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-02-15 23:17:29 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-02-21 23:37:26 +0000
commit478cb0ce2c71273799695240845a687aaac0cb0c (patch)
tree7433e60ecbf569d6dd0a8bc9a63cb7140c9b90eb
parent8f4b84c98cbe962a3c432b404c7d66b8e518cd40 (diff)
downloadpoky-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>
-rw-r--r--bitbake/lib/bb/cookerdata.py21
-rw-r--r--bitbake/lib/bb/data_smart.py36
-rw-r--r--bitbake/lib/bb/ui/knotty.py2
3 files changed, 58 insertions, 1 deletions
diff --git a/bitbake/lib/bb/cookerdata.py b/bitbake/lib/bb/cookerdata.py
index e4d91486d1..8426ed786f 100644
--- a/bitbake/lib/bb/cookerdata.py
+++ b/bitbake/lib/bb/cookerdata.py
@@ -247,6 +247,9 @@ class CookerDataBuilder(object):
247 self.savedenv = bb.data.init() 247 self.savedenv = bb.data.init()
248 for k in cookercfg.env: 248 for k in cookercfg.env:
249 self.savedenv.setVar(k, cookercfg.env[k]) 249 self.savedenv.setVar(k, cookercfg.env[k])
250 if k in bb.data_smart.bitbake_renamed_vars:
251 bb.error('Variable %s from the shell environment has been renamed to %s' % (k, bb.data_smart.bitbake_renamed_vars[k]))
252 bb.fatal("Exiting to allow enviroment variables to be corrected")
250 253
251 filtered_keys = bb.utils.approved_variables() 254 filtered_keys = bb.utils.approved_variables()
252 bb.data.inheritFromOS(self.basedata, self.savedenv, filtered_keys) 255 bb.data.inheritFromOS(self.basedata, self.savedenv, filtered_keys)
@@ -307,6 +310,24 @@ class CookerDataBuilder(object):
307 logger.exception("Error parsing configuration files") 310 logger.exception("Error parsing configuration files")
308 raise bb.BBHandledException() 311 raise bb.BBHandledException()
309 312
313
314 # Handle obsolete variable names
315 d = self.data
316 renamedvars = d.getVarFlags('BB_RENAMED_VARIABLES') or {}
317 renamedvars.update(bb.data_smart.bitbake_renamed_vars)
318 issues = False
319 for v in renamedvars:
320 if d.getVar(v) != None or d.hasOverrides(v):
321 issues = True
322 history = d.varhistory.get_variable_refs(v)
323 for h in history:
324 for line in history[h]:
325 bb.erroronce('Variable %s has been renamed to %s (file: %s line: %s)' % (v, renamedvars[v], h, line))
326 if not history:
327 bb.erroronce('Variable %s has been renamed to %s' % (v, renamedvars[v]))
328 if issues:
329 raise bb.BBHandledException()
330
310 # Create a copy so we can reset at a later date when UIs disconnect 331 # Create a copy so we can reset at a later date when UIs disconnect
311 self.origdata = self.data 332 self.origdata = self.data
312 self.data = bb.data.createCopy(self.origdata) 333 self.data = bb.data.createCopy(self.origdata)
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
36bitbake_renamed_vars = {
37}
38
36def infer_caller_details(loginfo, parent = False, varval = True): 39def 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)
diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py
index 8b98da1771..528b8a0760 100644
--- a/bitbake/lib/bb/ui/knotty.py
+++ b/bitbake/lib/bb/ui/knotty.py
@@ -25,7 +25,7 @@ from itertools import groupby
25 25
26from bb.ui import uihelper 26from bb.ui import uihelper
27 27
28featureSet = [bb.cooker.CookerFeatures.SEND_SANITYEVENTS] 28featureSet = [bb.cooker.CookerFeatures.SEND_SANITYEVENTS, bb.cooker.CookerFeatures.BASEDATASTORE_TRACKING]
29 29
30logger = logging.getLogger("BitBake") 30logger = logging.getLogger("BitBake")
31interactive = sys.stdout.isatty() 31interactive = sys.stdout.isatty()