summaryrefslogtreecommitdiffstats
path: root/wscript
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2022-06-27 15:07:50 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2022-07-04 08:29:52 +0200
commit0bb7b84698e380b86896a3163371648e88f2af21 (patch)
tree9043dc080ea00b45da50d59db2acc3d0fd5e5e91 /wscript
parentbuild: Fix identifier pattern (diff)
downloadrtems-0bb7b84698e380b86896a3163371648e88f2af21.tar.bz2
build: Improve value substitution
The waf build system uses lists for tool flags. The build items may use variable substitution. Add the ability to use the variable substitution in lists. For example: MORE_FLAGS = ['-more', '-flags'] flags: - -some-flag - ${MORE_FLAGS} Before this change, the ${MORE_FLAGS} was substituted to "-more -flags". This would be passed by waf as a single command line argument to the tool. After this change, the ${MORE_FLAGS} list extends the flags list: flags = ['-some-flag', '-more', '-flags'] This list extension is performed if a list element consists of exactly one variable. Update #4670.
Diffstat (limited to 'wscript')
-rwxr-xr-xwscript25
1 files changed, 16 insertions, 9 deletions
diff --git a/wscript b/wscript
index 731d1402ff..6ad230aca5 100755
--- a/wscript
+++ b/wscript
@@ -115,6 +115,9 @@ class Template(string.Template):
idpattern = "[_A-Za-z][_A-Za-z0-9:#]*"
+_VAR_PATTERN = re.compile("\$\{?(" + Template.idpattern + ")\}?$")
+
+
def _is_enabled_op_and(enabled, enabled_by):
for next_enabled_by in enabled_by:
if not _is_enabled(enabled, next_enabled_by):
@@ -249,18 +252,22 @@ class Item(object):
)
)
if isinstance(value, list):
- return [self.substitute(ctx, subvalue) for subvalue in value]
+ more = []
+ for item in value:
+ if isinstance(item, str):
+ m = _VAR_PATTERN.match(item)
+ else:
+ m = None
+ if m:
+ more.extend(ctx.env[m.group(1).strip("{}")])
+ else:
+ more.append(self.substitute(ctx, item))
+ return more
return value
def get(self, ctx, name):
return self.substitute(ctx, self.data[name])
- def get_values(self, ctx, name):
- more = []
- for value in self.data[name]:
- more.extend(self.substitute(ctx, value).split())
- return more
-
def install_target(self, bld):
install_path = self.data["install-path"]
if install_path:
@@ -512,12 +519,12 @@ class GroupItem(Item):
def prepare_build(self, bld, bic):
return BuildItemContext(
- bic.includes + self.get_values(bld, "includes"),
+ bic.includes + self.substitute(bld, self.data["includes"]),
bic.cppflags,
bic.cflags,
bic.cxxflags,
self.data["use-before"] + bic.use + self.data["use-after"],
- bic.ldflags + self.get_values(bld, "ldflags"),
+ bic.ldflags + self.substitute(bld, self.data["ldflags"]),
bic.objects,
)