Skip to content

Commit

Permalink
configure_file: warn in case a variable to subsitute is not present i…
Browse files Browse the repository at this point in the history
…n the passed configuration. Fixes #2090
  • Loading branch information
lazka committed Jul 21, 2017
1 parent e89b6cd commit 99206b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 8 additions & 1 deletion mesonbuild/interpreter.py
Expand Up @@ -2512,7 +2512,14 @@ def func_configure_file(self, node, args, kwargs):
if conffile not in self.build_def_files:
self.build_def_files.append(conffile)
os.makedirs(os.path.join(self.environment.build_dir, self.subdir), exist_ok=True)
mesonlib.do_conf_file(ifile_abs, ofile_abs, conf.held_object)
missing_variables = mesonlib.do_conf_file(ifile_abs, ofile_abs,
conf.held_object)
if missing_variables:
var_list = ", ".join(map(repr, sorted(missing_variables)))
mlog.warning(
"The variable(s) %s in the input file %r are not "
"present in the given configuration data" % (
var_list, inputfile))
else:
mesonlib.dump_conf_header(ofile_abs, conf.held_object)
conf.mark_used()
Expand Down
9 changes: 7 additions & 2 deletions mesonbuild/mesonlib.py
Expand Up @@ -375,6 +375,7 @@ def get_library_dirs():

def do_replacement(regex, line, confdata):
match = re.search(regex, line)
missing_variables = set()
while match:
varname = match.group(1)
if varname in confdata:
Expand All @@ -386,10 +387,11 @@ def do_replacement(regex, line, confdata):
else:
raise RuntimeError('Tried to replace a variable with something other than a string or int.')
else:
missing_variables.add(varname)
var = ''
line = line.replace('@' + varname + '@', var)
match = re.search(regex, line)
return line
return line, missing_variables

def do_mesondefine(line, confdata):
arr = line.split()
Expand Down Expand Up @@ -423,17 +425,20 @@ def do_conf_file(src, dst, confdata):
# Also allow escaping '@' with '\@'
regex = re.compile(r'[^\\]?@([-a-zA-Z0-9_]+)@')
result = []
missing_variables = set()
for line in data:
if line.startswith('#mesondefine'):
line = do_mesondefine(line, confdata)
else:
line = do_replacement(regex, line, confdata)
line, missing = do_replacement(regex, line, confdata)
missing_variables.update(missing)
result.append(line)
dst_tmp = dst + '~'
with open(dst_tmp, 'w', encoding='utf-8') as f:
f.writelines(result)
shutil.copymode(src, dst_tmp)
replace_if_different(dst, dst_tmp)
return missing_variables

def dump_conf_header(ofilename, cdata):
with open(ofilename, 'w', encoding='utf-8') as ofile:
Expand Down

0 comments on commit 99206b6

Please sign in to comment.