diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-02-25 09:42:28 -0700 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-03-22 15:02:59 +0000 |
commit | 57044b9a6240235a403eac4067e2e2113e03b6eb (patch) | |
tree | 46f15cb768778aa0f8363d6da2e98c6aaa69aadb /bitbake | |
parent | ada2a8494a88b59de25c0a44fce30190f560eff4 (diff) | |
download | poky-57044b9a6240235a403eac4067e2e2113e03b6eb.tar.gz |
Implement ??= operator
??= is a lazy, conditional assignment. Whereas a ?= immediately assigns to
the variable if the variable has not yet been set, ??= does not apply the
default assignment until the end of the parse. As a result, the final ??= for
a given variable is used, as opposed to the first as in ?=.
Note that the initial implementation relies upon finalise() to apply the
defaults, so a "bitbake -e" without specifying a recipe will not show the
defaults as set by ??=. Moving application of the default into getVar adds
too large a performance hit. We may want to revisit this later.
(Bitbake rev: 74f50fbca194c9c72bd2a540f4b9de458cb08e2d)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/doc/manual/usermanual.xml | 8 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/ast.py | 11 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/ConfHandler.py | 2 |
3 files changed, 19 insertions, 2 deletions
diff --git a/bitbake/doc/manual/usermanual.xml b/bitbake/doc/manual/usermanual.xml index c3403449fe..450ac77d7a 100644 --- a/bitbake/doc/manual/usermanual.xml +++ b/bitbake/doc/manual/usermanual.xml | |||
@@ -91,7 +91,13 @@ share common metadata between many packages.</para></listitem> | |||
91 | <section> | 91 | <section> |
92 | <title>Setting a default value (?=)</title> | 92 | <title>Setting a default value (?=)</title> |
93 | <para><screen><varname>A</varname> ?= "aval"</screen></para> | 93 | <para><screen><varname>A</varname> ?= "aval"</screen></para> |
94 | <para>If <varname>A</varname> is set before the above is called, it will retain it's previous value. If <varname>A</varname> is unset prior to the above call, <varname>A</varname> will be set to <literal>aval</literal>.</para> | 94 | <para>If <varname>A</varname> is set before the above is called, it will retain it's previous value. If <varname>A</varname> is unset prior to the above call, <varname>A</varname> will be set to <literal>aval</literal>. Note that this assignment is immediate, so if there are multiple ?= assignments to a single variable, the first of those will be used.</para> |
95 | </section> | ||
96 | <section> | ||
97 | <title>Setting a default value (??=)</title> | ||
98 | <para><screen><varname>A</varname> ??= "somevalue"</screen></para> | ||
99 | <para><screen><varname>A</varname> ??= "someothervalue"</screen></para> | ||
100 | <para>If <varname>A</varname> is set before the above, it will retain that value. If <varname>A</varname> is unset prior to the above, <varname>A</varname> will be set to <literal>someothervalue</literal>. This is a lazy version of ??=, in that the assignment does not occur until the end of the parsing process, so that the last, rather than the first, ??= assignment to a given variable will be used.</para> | ||
95 | </section> | 101 | </section> |
96 | <section> | 102 | <section> |
97 | <title>Immediate variable expansion (:=)</title> | 103 | <title>Immediate variable expansion (:=)</title> |
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py index e0b795fa68..70a69b8d14 100644 --- a/bitbake/lib/bb/parse/ast.py +++ b/bitbake/lib/bb/parse/ast.py | |||
@@ -99,9 +99,15 @@ class DataNode(AstNode): | |||
99 | val = "%s%s" % (groupd["value"], (self.getFunc(key, data) or "")) | 99 | val = "%s%s" % (groupd["value"], (self.getFunc(key, data) or "")) |
100 | else: | 100 | else: |
101 | val = groupd["value"] | 101 | val = groupd["value"] |
102 | |||
102 | if 'flag' in groupd and groupd['flag'] != None: | 103 | if 'flag' in groupd and groupd['flag'] != None: |
103 | bb.msg.debug(3, bb.msg.domain.Parsing, "setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val)) | 104 | bb.msg.debug(3, bb.msg.domain.Parsing, "setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val)) |
104 | bb.data.setVarFlag(key, groupd['flag'], val, data) | 105 | bb.data.setVarFlag(key, groupd['flag'], val, data) |
106 | elif groupd["lazyques"]: | ||
107 | assigned = bb.data.getVar("__lazy_assigned", data) or [] | ||
108 | assigned.append(key) | ||
109 | bb.data.setVar("__lazy_assigned", assigned, data) | ||
110 | bb.data.setVarFlag(key, "defaultval", val, data) | ||
105 | else: | 111 | else: |
106 | bb.data.setVar(key, val, data) | 112 | bb.data.setVar(key, val, data) |
107 | 113 | ||
@@ -286,6 +292,11 @@ def handleInherit(statements, m): | |||
286 | statements.append(InheritNode(m.group(1))) | 292 | statements.append(InheritNode(m.group(1))) |
287 | 293 | ||
288 | def finalise(fn, d): | 294 | def finalise(fn, d): |
295 | for lazykey in bb.data.getVar("__lazy_assigned", d) or (): | ||
296 | if bb.data.getVar(lazykey, d) is None: | ||
297 | val = bb.data.getVarFlag(lazykey, "defaultval", d) | ||
298 | bb.data.setVar(lazykey, val, d) | ||
299 | |||
289 | bb.data.expandKeys(d) | 300 | bb.data.expandKeys(d) |
290 | bb.data.update_data(d) | 301 | bb.data.update_data(d) |
291 | anonqueue = bb.data.getVar("__anonqueue", d, 1) or [] | 302 | anonqueue = bb.data.getVar("__anonqueue", d, 1) or [] |
diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py index a1eaf317ac..f4f85de245 100644 --- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py +++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py | |||
@@ -28,7 +28,7 @@ import re, bb.data, os, sys | |||
28 | from bb.parse import ParseError, resolve_file, ast | 28 | from bb.parse import ParseError, resolve_file, ast |
29 | 29 | ||
30 | #__config_regexp__ = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${}]+)\s*(?P<colon>:)?(?P<ques>\?)?=\s*(?P<apo>['\"]?)(?P<value>.*)(?P=apo)$") | 30 | #__config_regexp__ = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${}]+)\s*(?P<colon>:)?(?P<ques>\?)?=\s*(?P<apo>['\"]?)(?P<value>.*)(?P=apo)$") |
31 | __config_regexp__ = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${}/]+)(\[(?P<flag>[a-zA-Z0-9\-_+.]+)\])?\s*((?P<colon>:=)|(?P<ques>\?=)|(?P<append>\+=)|(?P<prepend>=\+)|(?P<predot>=\.)|(?P<postdot>\.=)|=)\s*(?P<apo>['\"]?)(?P<value>.*)(?P=apo)$") | 31 | __config_regexp__ = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${}/]+)(\[(?P<flag>[a-zA-Z0-9\-_+.]+)\])?\s*((?P<colon>:=)|(?P<lazyques>\?\?=)|(?P<ques>\?=)|(?P<append>\+=)|(?P<prepend>=\+)|(?P<predot>=\.)|(?P<postdot>\.=)|=)\s*(?P<apo>['\"]?)(?P<value>.*)(?P=apo)$") |
32 | __include_regexp__ = re.compile( r"include\s+(.+)" ) | 32 | __include_regexp__ = re.compile( r"include\s+(.+)" ) |
33 | __require_regexp__ = re.compile( r"require\s+(.+)" ) | 33 | __require_regexp__ = re.compile( r"require\s+(.+)" ) |
34 | __export_regexp__ = re.compile( r"export\s+(.+)" ) | 34 | __export_regexp__ = re.compile( r"export\s+(.+)" ) |