From 65dfa428d511f09343c64dcf47997263c86f2f13 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Wed, 20 Sep 2017 14:24:33 +0530 Subject: [PATCH 1/2] tests/common/144: Add a test for #1865 Ninja goes into an infinite loop when you build this. --- .../common/114 multiple dir configure file/meson.build | 4 ++++ .../common/114 multiple dir configure file/subdir/foo.txt | 0 .../114 multiple dir configure file/subdir/meson.build | 7 +++++++ 3 files changed, 11 insertions(+) create mode 100644 test cases/common/114 multiple dir configure file/subdir/foo.txt diff --git a/test cases/common/114 multiple dir configure file/meson.build b/test cases/common/114 multiple dir configure file/meson.build index 180227c15..c76c6b496 100644 --- a/test cases/common/114 multiple dir configure file/meson.build +++ b/test cases/common/114 multiple dir configure file/meson.build @@ -5,3 +5,7 @@ subdir('subdir') configure_file(input : 'subdir/someinput.in', output : 'outputhere', configuration : configuration_data()) + +configure_file(input : cfile1, + output : '@BASENAME@', + configuration : configuration_data()) diff --git a/test cases/common/114 multiple dir configure file/subdir/foo.txt b/test cases/common/114 multiple dir configure file/subdir/foo.txt new file mode 100644 index 000000000..e69de29bb diff --git a/test cases/common/114 multiple dir configure file/subdir/meson.build b/test cases/common/114 multiple dir configure file/subdir/meson.build index a8f731d94..9c72bf985 100644 --- a/test cases/common/114 multiple dir configure file/subdir/meson.build +++ b/test cases/common/114 multiple dir configure file/subdir/meson.build @@ -2,3 +2,10 @@ configure_file(input : 'someinput.in', output : 'outputsubdir', install : false, configuration : configuration_data()) + +py3 = import('python3').find_python() + +cfile1 = configure_file(input : 'foo.txt', + output : 'foo.h.in', + capture : true, + command : [py3, '-c', 'print("#mesondefine FOO_BAR")']) From 87327d414aef2dfe1caf6994d911e0bc82aa0ca7 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Wed, 20 Sep 2017 14:40:43 +0530 Subject: [PATCH 2/2] configure_file: Fix infinite loop in some cases We were adding built files to the list of source files to check for regen. We were also not adding sources files to regen when `command:` was used. Fixes #1865 --- mesonbuild/interpreter.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 6e37dc2c9..69c49c210 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2549,12 +2549,10 @@ class Interpreter(InterpreterBase): if not isinstance(inputfile, (str, mesonlib.File)): raise InterpreterException('Input must be a string or a file') if isinstance(inputfile, str): - inputfile = os.path.join(self.subdir, inputfile) - ifile_abs = os.path.join(self.environment.source_dir, inputfile) - else: - ifile_abs = inputfile.absolute_path(self.environment.source_dir, - self.environment.build_dir) - inputfile = inputfile.relative_name() + inputfile = mesonlib.File.from_source_file(self.environment.source_dir, + self.subdir, inputfile) + ifile_abs = inputfile.absolute_path(self.environment.source_dir, + self.environment.build_dir) elif 'command' in kwargs and '@INPUT@' in kwargs['command']: raise InterpreterException('@INPUT@ used as command argument, but no input file specified.') # Validate output @@ -2575,18 +2573,13 @@ class Interpreter(InterpreterBase): raise InterpreterException('Argument "configuration" is not of type configuration_data') mlog.log('Configuring', mlog.bold(output), 'using configuration') if inputfile is not None: - # Normalize the path of the conffile to avoid duplicates - # This is especially important to convert '/' to '\' on Windows - conffile = os.path.normpath(inputfile) - 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) 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 " + "The variable(s) %s in the input file %s are not " "present in the given configuration data" % ( var_list, inputfile)) else: @@ -2616,6 +2609,17 @@ class Interpreter(InterpreterBase): mesonlib.replace_if_different(ofile_abs, dst_tmp) else: raise InterpreterException('Configure_file must have either "configuration" or "command".') + # If the input is a source file, add it to the list of files that we + # need to reconfigure on when they change. FIXME: Do the same for + # files() objects in the command: kwarg. + if inputfile and not inputfile.is_built: + # Normalize the path of the conffile (relative to the + # source root) to avoid duplicates. This is especially + # important to convert '/' to '\' on Windows + conffile = os.path.normpath(inputfile.relative_name()) + if conffile not in self.build_def_files: + self.build_def_files.append(conffile) + # Install file if requested idir = kwargs.get('install_dir', None) if isinstance(idir, str): cfile = mesonlib.File.from_built_file(ofile_path, ofile_fname)