summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2015-01-25 21:37:05 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-07-12 22:50:45 +0100
commit95be16f428ae4cf4254da0b814a327459a983ef5 (patch)
treeebfa5c64156aa776c5c1255bc9ad7dbac1079a58 /bitbake
parent7fc6f6c98d4479a8ae81e0961a7dd93d436e804e (diff)
downloadpoky-95be16f428ae4cf4254da0b814a327459a983ef5.tar.gz
bitbake: data_smart: Move override handling to getVar
Compeltely remove the replaces functionality and move all overrides handling to getVar time. We can move the cookie cache into a hidden flag within the variables themselves. This removes the need for any of the internal_finalize steps. This obsolete the need for the _seen_overrides COW cache. (Bitbake rev: 2a0b73110bede91777ada54d1d89b45fb6034b6c) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/data_smart.py131
1 files changed, 61 insertions, 70 deletions
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py
index 884ca190a6..28ea2aef63 100644
--- a/bitbake/lib/bb/data_smart.py
+++ b/bitbake/lib/bb/data_smart.py
@@ -296,24 +296,18 @@ class VariableHistory(object):
296 self.variables[var] = [] 296 self.variables[var] = []
297 297
298class DataSmart(MutableMapping): 298class DataSmart(MutableMapping):
299 def __init__(self, seen = None): 299 def __init__(self):
300 self.dict = {} 300 self.dict = {}
301 301
302 if seen is None:
303 seen = COWDictBase.copy()
304
305 self.inchistory = IncludeHistory() 302 self.inchistory = IncludeHistory()
306 self.varhistory = VariableHistory(self) 303 self.varhistory = VariableHistory(self)
307 self._tracking = False 304 self._tracking = False
308 305
309 # cookie monster tribute
310 self._seen_overrides = seen
311
312 self.expand_cache = {} 306 self.expand_cache = {}
313 307
308 # cookie monster tribute
314 self.overrides = [] 309 self.overrides = []
315 self.overridevars = set(["OVERRIDES", "FILE"]) 310 self.overridevars = set(["OVERRIDES", "FILE"])
316 self.replaces = {}
317 311
318 def enableTracking(self): 312 def enableTracking(self):
319 self._tracking = True 313 self._tracking = True
@@ -363,49 +357,6 @@ class DataSmart(MutableMapping):
363 357
364 self.overrides = (self.getVar("OVERRIDES", True) or "").split(":") or [] 358 self.overrides = (self.getVar("OVERRIDES", True) or "").split(":") or []
365 359
366 #
367 # Well let us see what breaks here. We used to iterate
368 # over each variable and apply the override and then
369 # do the line expanding.
370 # If we have bad luck - which we will have - the keys
371 # where in some order that is so important for this
372 # method which we don't have anymore.
373 # Anyway we will fix that and write test cases this
374 # time.
375
376 #
377 # First we apply all overrides
378 # Then we will handle _append and _prepend and store the _remove
379 # information for later.
380 #
381
382 self.replaces = {}
383
384 for o in self.overrides:
385 # calculate '_'+override
386 l = len(o) + 1
387
388 # see if one should even try
389 if o not in self._seen_overrides:
390 continue
391
392 vars = self._seen_overrides[o].copy()
393 for var in vars:
394 name = var[:-l]
395 self.replaces[name] = var
396
397 def internal_finalize2(self, var, o):
398 """Performs final steps upon the datastore, including application of overrides"""
399
400 l = len(o) + 1
401 name = var[:-l]
402
403 if name in self.replaces:
404 del self.replaces[name]
405 for o in self.overrides:
406 if o in self._seen_overrides and name + "_" + o in self._seen_overrides[o]:
407 self.replaces[name] = name + "_" + o
408
409 def initVar(self, var): 360 def initVar(self, var):
410 self.expand_cache = {} 361 self.expand_cache = {}
411 if not var in self.dict: 362 if not var in self.dict:
@@ -457,6 +408,11 @@ class DataSmart(MutableMapping):
457 # todo make sure keyword is not __doc__ or __module__ 408 # todo make sure keyword is not __doc__ or __module__
458 # pay the cookie monster 409 # pay the cookie monster
459 410
411 # more cookies for the cookie monster
412 if '_' in var:
413 self._setvar_update_overrides(base, **loginfo)
414
415
460 if base in self.overridevars: 416 if base in self.overridevars:
461 self.overridevars.update(self.expandWithRefs(value, var).references) 417 self.overridevars.update(self.expandWithRefs(value, var).references)
462 self.internal_finalize(True) 418 self.internal_finalize(True)
@@ -469,16 +425,12 @@ class DataSmart(MutableMapping):
469 del self.dict[var]["_append"] 425 del self.dict[var]["_append"]
470 if "_prepend" in self.dict[var]: 426 if "_prepend" in self.dict[var]:
471 del self.dict[var]["_prepend"] 427 del self.dict[var]["_prepend"]
472 428 if "_overrides" in self.dict[var]:
473 if var in self.replaces: 429 del self.dict[var]["_overrides"]
474 del self.replaces[var]
475 for o in self.overrides:
476 if o in self._seen_overrides and var + "_" + o in self._seen_overrides[o]:
477 self.delVar(var + "_" + o)
478 430
479 # more cookies for the cookie monster 431 # more cookies for the cookie monster
480 if '_' in var: 432 if '_' in var:
481 self._setvar_update_overrides(var) 433 self._setvar_update_overrides(var, **loginfo)
482 434
483 # setting var 435 # setting var
484 self.dict[var]["_content"] = value 436 self.dict[var]["_content"] = value
@@ -488,19 +440,29 @@ class DataSmart(MutableMapping):
488 self.overridevars.update(self.expandWithRefs(value, var).references) 440 self.overridevars.update(self.expandWithRefs(value, var).references)
489 self.internal_finalize(True) 441 self.internal_finalize(True)
490 442
491 def _setvar_update_overrides(self, var): 443 def _setvar_update_overrides(self, var, **loginfo):
492 # aka pay the cookie monster 444 # aka pay the cookie monster
493 override = var[var.rfind('_')+1:] 445 override = var[var.rfind('_')+1:]
494 shortvar = var[:var.rfind('_')] 446 shortvar = var[:var.rfind('_')]
495 while override: 447 while override:
496 if override not in self._seen_overrides: 448 l = self.getVarFlag(shortvar, "_overrides") or []
497 self._seen_overrides[override] = set() 449 if [var, override] not in l:
498 self._seen_overrides[override].add( var ) 450 l.append([var, override])
499 self.internal_finalize2(var, override) 451 self.setVarFlag(shortvar, "_overrides", l, ignore=True)
452 for event in self.varhistory.variable(var):
453 if 'flag' in loginfo and not loginfo['flag'].startswith("_"):
454 continue
455 loginfo = event.copy()
456 loginfo['variable'] = shortvar
457 loginfo['op'] = 'override[%s]:%s' % (override, loginfo['op'])
458 self.varhistory.record(**loginfo)
459
500 override = None 460 override = None
501 if "_" in shortvar: 461 if "_" in shortvar:
502 override = var[shortvar.rfind('_')+1:] 462 override = var[shortvar.rfind('_')+1:]
503 shortvar = var[:shortvar.rfind('_')] 463 shortvar = var[:shortvar.rfind('_')]
464 if len(shortvar) == 0:
465 override = None
504 466
505 def getVar(self, var, expand=False, noweakdefault=False): 467 def getVar(self, var, expand=False, noweakdefault=False):
506 return self.getVarFlag(var, "_content", expand, noweakdefault) 468 return self.getVarFlag(var, "_content", expand, noweakdefault)
@@ -526,6 +488,9 @@ class DataSmart(MutableMapping):
526 dest.extend(src) 488 dest.extend(src)
527 self.setVarFlag(newkey, i, dest, ignore=True) 489 self.setVarFlag(newkey, i, dest, ignore=True)
528 490
491 if '_' in newkey and val is None:
492 self._setvar_update_overrides(newkey, **loginfo)
493
529 loginfo['variable'] = key 494 loginfo['variable'] = key
530 loginfo['op'] = 'rename (to)' 495 loginfo['op'] = 'rename (to)'
531 loginfo['detail'] = newkey 496 loginfo['detail'] = newkey
@@ -552,9 +517,13 @@ class DataSmart(MutableMapping):
552 self.dict[var] = {} 517 self.dict[var] = {}
553 if '_' in var: 518 if '_' in var:
554 override = var[var.rfind('_')+1:] 519 override = var[var.rfind('_')+1:]
555 if override and override in self._seen_overrides and var in self._seen_overrides[override]: 520 shortvar = var[:var.rfind('_')]
556 self._seen_overrides[override].remove(var) 521 l = self.getVarFlag(shortvar, "_overrides") or []
557 self.internal_finalize2(var, override) 522 try:
523 l.remove([var, override])
524 except ValueError as e:
525 pass
526 self.setVarFlag(shortvar, "_overrides", l, ignore=True)
558 527
559 def setVarFlag(self, var, flag, value, **loginfo): 528 def setVarFlag(self, var, flag, value, **loginfo):
560 self.expand_cache = {} 529 self.expand_cache = {}
@@ -567,7 +536,7 @@ class DataSmart(MutableMapping):
567 self.dict[var][flag] = value 536 self.dict[var][flag] = value
568 537
569 if flag == "_defaultval" and '_' in var: 538 if flag == "_defaultval" and '_' in var:
570 self._setvar_update_overrides(var) 539 self._setvar_update_overrides(var, **loginfo)
571 540
572 if flag == "unexport" or flag == "export": 541 if flag == "unexport" or flag == "export":
573 if not "__exportlist" in self.dict: 542 if not "__exportlist" in self.dict:
@@ -580,8 +549,30 @@ class DataSmart(MutableMapping):
580 local_var = self._findVar(var) 549 local_var = self._findVar(var)
581 value = None 550 value = None
582 551
583 if flag == "_content" and var in self.replaces: 552 if flag == "_content" and local_var is not None and "_overrides" in local_var:
584 value = self.getVar(self.replaces[var]) 553 match = False
554 active = {}
555 for (r, o) in local_var["_overrides"]:
556 # What about double overrides both with "_" in the name?
557 if o in self.overrides:
558 active[o] = r
559 elif set(o.split("_")).issubset(set(self.overrides)):
560 active[o] = r
561 mod = True
562 while mod:
563 mod = False
564 for o in self.overrides:
565 for a in active.copy():
566 if a.endswith("_" + o):
567 t = active[a]
568 del active[a]
569 active[a.replace("_" + o, "")] = t
570 mod = True
571 elif a == o:
572 match = active[a]
573 del active[a]
574 if match:
575 value = self.getVar(match)
585 576
586 if local_var is not None and value is None: 577 if local_var is not None and value is None:
587 if flag in local_var: 578 if flag in local_var:
@@ -726,7 +717,7 @@ class DataSmart(MutableMapping):
726 Create a copy of self by setting _data to self 717 Create a copy of self by setting _data to self
727 """ 718 """
728 # we really want this to be a DataSmart... 719 # we really want this to be a DataSmart...
729 data = DataSmart(seen=self._seen_overrides.copy()) 720 data = DataSmart()
730 data.dict["_data"] = self.dict 721 data.dict["_data"] = self.dict
731 data.varhistory = self.varhistory.copy() 722 data.varhistory = self.varhistory.copy()
732 data.varhistory.datasmart = data 723 data.varhistory.datasmart = data