Skip to content

Commit

Permalink
do @ variable substitution when parsing cmake format
Browse files Browse the repository at this point in the history
the upstream behavior of configure_file in cmake parses both @var@ and ${VAR} and only supports disabling the bracket variables through the `@ONLY` argument, meson needs to follow this behavior for compatibility
  • Loading branch information
Jan200101 committed Dec 10, 2024
1 parent 83253cd commit 5c75876
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mesonbuild/utils/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,9 @@ def variable_replace(match: T.Match[str]) -> str:
else:
# Template variable to be replaced
varname = match.group('variable')
if not varname:
varname = match.group('cmake_variable')

var_str = ''
if varname in confdata:
var, _ = confdata.get(varname)
Expand Down Expand Up @@ -1280,11 +1283,15 @@ def get_variable_regex(variable_format: Literal['meson', 'cmake', 'cmake@'] = 'm
''', re.VERBOSE)
else:
regex = re.compile(r'''
(?:\\\\)+(?=\\?\$) # Match multiple backslashes followed by a dollar sign
(?:\\\\)+(?=\\?(\$|@)) # Match multiple backslashes followed by a dollar sign or an @ symbol
| # OR
\\\${ # Match a backslash followed by a dollar sign and an opening curly brace
| # OR
\${(?P<variable>[-a-zA-Z0-9_]+)} # Match a variable enclosed in curly braces and capture the variable name
\${(?P<cmake_variable>[-a-zA-Z0-9_]+)} # Match a variable enclosed in curly braces and capture the variable name
| # OR
(?<!\\)@(?P<variable>[-a-zA-Z0-9_]+)@ # Match a variable enclosed in @ symbols and capture the variable name; no matches beginning with '\@'
| # OR
(?P<escaped>\\@[-a-zA-Z0-9_]+\\@) # Match an escaped variable enclosed in @ symbols
''', re.VERBOSE)
return regex

Expand Down

0 comments on commit 5c75876

Please sign in to comment.