Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ninja: use header dependencies for better rebuild support #3769

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow %{foo|concat:some_constant_value} in the template engine
This concatenates the static value behind the colon with the
value of the template variable. If this value is not set (aka ''),
also the static concatenated value is omitted.

Co-Authored-By: Philippe Lieser <[email protected]>
reneme and lieser committed Oct 24, 2023

Verified

This commit was signed with the committer’s verified signature.
reneme René Meusel
commit c7c67c3f067cd022054baa25fe226110d3cb308c
31 changes: 21 additions & 10 deletions configure.py
Original file line number Diff line number Diff line change
@@ -1728,23 +1728,34 @@ class SimpleTemplate:

def __init__(self, vals):
self.vals = vals
self.value_pattern = re.compile(r'%{([a-z][a-z_0-9\|]+)}')
self.value_pattern = re.compile(r'%{([a-z][a-z_0-9\|]+)(?::([^}]+))?}')
self.cond_pattern = re.compile('%{(if|unless) ([a-z][a-z_0-9]+)}')
self.for_pattern = re.compile('(.*)%{for ([a-z][a-z_0-9]+)}')
self.omitlast_pattern = re.compile('(.*)%{omitlast ([^}]*)}(.*)', re.DOTALL)
self.join_pattern = re.compile('%{join ([a-z][a-z_0-9]+)}')

def substitute(self, template):
def get_replacement(k):
if k not in self.vals:
raise KeyError(k)
return str(self.vals.get(k))

def insert_value(match):
v = match.group(1)
if v in self.vals:
return str(self.vals.get(v))
if v.endswith('|upper'):
v = v.replace('|upper', '')
if v in self.vals:
return str(self.vals.get(v)).upper()

raise KeyError(v)
k = match.group(1)
if k.endswith('|upper'):
k = k.replace('|upper', '')
v = get_replacement(k).upper()
elif k.endswith('|concat'):
k = k.replace('|concat', '')
if not match.group(2):
raise InternalError("|concat must be of the form '%{val|concat:<some static value>}'")
v = get_replacement(k)
if v:
v = f"{v}{match.group(2)}"
else:
v = get_replacement(k)

return v

def insert_join(match):
var = match.group(1)
6 changes: 6 additions & 0 deletions doc/dev_ref/configure.rst
Original file line number Diff line number Diff line change
@@ -77,6 +77,12 @@ to the output unmodified. The template elements are:
If a variable reference ends with ``|upper``, the value is uppercased before
being inserted into the template output.

Using ``|concat:<some string>`` as a suffix, it is possible to conditionally
concatenate the variable value with a static string defined in the template.
This is useful for compiler switches that require a template-defined
parameter value. If the substitution value is not set (i.e. "empty"), also
the static concatenation value is omitted.

* Iteration, ``%{for variable} block %{endfor}``. This iterates over a list and
repeats the block as many times as it is included. Variables within the block
are expanded. The two template elements ``%{for ...}`` and ``%{endfor}`` must