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

do @ variable substitution when parsing cmake format #13987

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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
4 changes: 4 additions & 0 deletions test cases/common/14 configure file/config10.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Should both be the same */
#define MESSAGE1 "@var@"
#define MESSAGE2 "${var}"

10 changes: 10 additions & 0 deletions test cases/common/14 configure file/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ configure_file(output : 'config9b.h',

test('test9', executable('prog9', 'prog9.c'))

# Test @ and curly braces at the same time with cmake format
conf10 = configuration_data()
conf10.set('var', 'foo')
configure_file(
input : 'config10.h.in',
output : '@BASENAME@',
format : 'cmake',
configuration : conf10)
test('test10', executable('prog10', 'prog10.c'))

check_inputs = find_program('check_inputs.py')
configure_file(output : 'check_inputs.txt',
input : ['prog.c', files('prog2.c', 'prog4.c')],
Expand Down
7 changes: 7 additions & 0 deletions test cases/common/14 configure file/prog10.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <string.h>
#include <config10.h>

int main(void) {
return strcmp(MESSAGE1, "foo")
|| strcmp(MESSAGE2, "foo");
}
5 changes: 1 addition & 4 deletions test cases/frameworks/7 gnome/mkenums/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,9 @@ test('enum test 5', enumexe5)

# Generate template then use as input to mkenums

# Simple trick to copy the file without substitutions, can be
# removed when https://github.com/mesonbuild/meson/pull/3383 is fixed
gen_h_template = configure_file(input: 'enums.h.in',
output: 'enums6.h.in',
configuration: configuration_data(),
format: 'cmake')
copy: true)

enums_h6 = gnome.mkenums('enums6',
sources : 'meson-sample.h',
Expand Down
Loading