From ceea746222cf77b2919a05a0f48ca20dd2c6e012 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Thu, 20 Jul 2017 19:57:33 +0200 Subject: [PATCH] configure_file: warn in case a variable to subsitute is not present in the passed configuration. Fixes #2090 --- mesonbuild/interpreter.py | 9 ++++++++- mesonbuild/mesonlib.py | 9 +++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 359dd17f5..d05bed5b7 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2512,7 +2512,14 @@ class Interpreter(InterpreterBase): 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() diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 4760e04a2..d48625fb5 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -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: @@ -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() @@ -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: