[rtems commit] build: Improve value substitution
Sebastian Huber
sebh at rtems.org
Mon Jul 4 06:24:56 UTC 2022
Module: rtems
Branch: master
Commit: 0bb7b84698e380b86896a3163371648e88f2af21
Changeset: http://git.rtems.org/rtems/commit/?id=0bb7b84698e380b86896a3163371648e88f2af21
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Mon Jun 27 15:07:50 2022 +0200
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.
---
wscript | 25 ++++++++++++++++---------
1 file 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,
)
More information about the vc
mailing list