diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-03-09 12:47:21 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-08-26 11:29:46 +0100 |
commit | d7571c0390d53bc9a481277944efae688eee0448 (patch) | |
tree | a256535acde11f066047dd515f670db0763a986a /bitbake | |
parent | 69aab78dd830b0ad570cf9b7bfe2da8e8b793e23 (diff) | |
download | poky-d7571c0390d53bc9a481277944efae688eee0448.tar.gz |
bitbake: data_smart: Add _remove operator
There are long standing complaints about the fact its very difficult
to remove a portion of a variable. The immediate request is for a -=
and =- operator. The trouble is that += and =+ are "immediate"
operators and are applied straight away. Most people would expect
-= and =- to be deferred to have the effect most people desire and
therefore implementing -= and =- would just make the situation more
confusing.
This deferred operation is much more similar to the override syntax
which happens at data store finalisation. The _remove operator is
therefore in keeping with the _append and _prepend operations.
This code is loosely based on a patch from Peter Seebach although it
has been rewritten to be simpler, more efficient and avoid some
potential bugs.
The code currently only works on space delimited variables, which
are by far the most commom type. If bitbake is ehanced to support
types natively in future, we can adjust this code to adapt to that.
(Bitbake rev: 9c91948e10df278dad4832487fa56888cd58d187)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/data_smart.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py index dfa9afe461..3fb88a93df 100644 --- a/bitbake/lib/bb/data_smart.py +++ b/bitbake/lib/bb/data_smart.py | |||
@@ -38,8 +38,8 @@ from bb.COW import COWDictBase | |||
38 | 38 | ||
39 | logger = logging.getLogger("BitBake.Data") | 39 | logger = logging.getLogger("BitBake.Data") |
40 | 40 | ||
41 | __setvar_keyword__ = ["_append", "_prepend"] | 41 | __setvar_keyword__ = ["_append", "_prepend", "_remove"] |
42 | __setvar_regexp__ = re.compile('(?P<base>.*?)(?P<keyword>_append|_prepend)(_(?P<add>.*))?$') | 42 | __setvar_regexp__ = re.compile('(?P<base>.*?)(?P<keyword>_append|_prepend|_remove)(_(?P<add>.*))?$') |
43 | __expand_var_regexp__ = re.compile(r"\${[^{}]+}") | 43 | __expand_var_regexp__ = re.compile(r"\${[^{}]+}") |
44 | __expand_python_regexp__ = re.compile(r"\${@.+?}") | 44 | __expand_python_regexp__ = re.compile(r"\${@.+?}") |
45 | 45 | ||
@@ -357,7 +357,8 @@ class DataSmart(MutableMapping): | |||
357 | 357 | ||
358 | # | 358 | # |
359 | # First we apply all overrides | 359 | # First we apply all overrides |
360 | # Then we will handle _append and _prepend | 360 | # Then we will handle _append and _prepend and store the _remove |
361 | # information for later. | ||
361 | # | 362 | # |
362 | 363 | ||
363 | # We only want to report finalization once per variable overridden. | 364 | # We only want to report finalization once per variable overridden. |
@@ -392,7 +393,7 @@ class DataSmart(MutableMapping): | |||
392 | except Exception: | 393 | except Exception: |
393 | logger.info("Untracked delVar") | 394 | logger.info("Untracked delVar") |
394 | 395 | ||
395 | # now on to the appends and prepends | 396 | # now on to the appends and prepends, and stashing the removes |
396 | for op in __setvar_keyword__: | 397 | for op in __setvar_keyword__: |
397 | if op in self._special_values: | 398 | if op in self._special_values: |
398 | appends = self._special_values[op] or [] | 399 | appends = self._special_values[op] or [] |
@@ -415,6 +416,10 @@ class DataSmart(MutableMapping): | |||
415 | elif op == "_prepend": | 416 | elif op == "_prepend": |
416 | sval = a + (self.getVar(append, False) or "") | 417 | sval = a + (self.getVar(append, False) or "") |
417 | self.setVar(append, sval) | 418 | self.setVar(append, sval) |
419 | elif op == "_remove": | ||
420 | removes = self.getVarFlag(append, "_removeactive", False) or [] | ||
421 | removes.append(a) | ||
422 | self.setVarFlag(append, "_removeactive", removes, ignore=True) | ||
418 | 423 | ||
419 | # We save overrides that may be applied at some later stage | 424 | # We save overrides that may be applied at some later stage |
420 | if keep: | 425 | if keep: |
@@ -519,7 +524,7 @@ class DataSmart(MutableMapping): | |||
519 | self.varhistory.record(**loginfo) | 524 | self.varhistory.record(**loginfo) |
520 | self.setVar(newkey, val, ignore=True) | 525 | self.setVar(newkey, val, ignore=True) |
521 | 526 | ||
522 | for i in ('_append', '_prepend'): | 527 | for i in (__setvar_keyword__): |
523 | src = self.getVarFlag(key, i) | 528 | src = self.getVarFlag(key, i) |
524 | if src is None: | 529 | if src is None: |
525 | continue | 530 | continue |
@@ -583,6 +588,14 @@ class DataSmart(MutableMapping): | |||
583 | value = copy.copy(local_var["defaultval"]) | 588 | value = copy.copy(local_var["defaultval"]) |
584 | if expand and value: | 589 | if expand and value: |
585 | value = self.expand(value, None) | 590 | value = self.expand(value, None) |
591 | if value and flag == "_content" and local_var and "_removeactive" in local_var: | ||
592 | for i in local_var["_removeactive"]: | ||
593 | if " " + i + " " in value: | ||
594 | value = value.replace(" " + i + " ", " ") | ||
595 | if value.startswith(i + " "): | ||
596 | value = value[len(i + " "):] | ||
597 | if value.endswith(" " + i): | ||
598 | value = value[:-len(" " + i)] | ||
586 | return value | 599 | return value |
587 | 600 | ||
588 | def delVarFlag(self, var, flag, **loginfo): | 601 | def delVarFlag(self, var, flag, **loginfo): |