From 07f5a5e4901c3c5afde15b305df72a0d09f5af72 Mon Sep 17 00:00:00 2001 From: Christoph Behle Date: Sat, 30 Jun 2018 19:02:26 +0200 Subject: Add warning if configure_file overwrites output. Record the output for each call to configure_file. If a previous output is overwritten print a warning. --- mesonbuild/interpreter.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 833e982..0974691 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1862,6 +1862,7 @@ class Interpreter(InterpreterBase): self.global_args_frozen = False # implies self.project_args_frozen self.subprojects = {} self.subproject_stack = [] + self.configure_file_outputs = {} # Passed from the outside, only used in subprojects. if default_project_options: self.default_project_options = default_project_options.copy() @@ -3449,6 +3450,10 @@ root and issuing %s. output = kwargs['output'] if not isinstance(output, str): raise InterpreterException('Output file name must be a string') + if output in self.configure_file_outputs: + mlog.warning('Output file', mlog.bold(output), 'for configure_file overwritten.') + else: + self.configure_file_outputs[output] = None if ifile_abs: values = mesonlib.get_filenames_templates_dict([ifile_abs], None) outputs = mesonlib.substitute_values([output], values) -- cgit v1.1 From 620c0b07a9bd93929590b88cf9c84026bc9ca1cd Mon Sep 17 00:00:00 2001 From: Christoph Behle Date: Sat, 30 Jun 2018 19:37:04 +0200 Subject: Track line numbers for configure_file. Track line numbers of calls. Warning reports now the line number of the first and the current write to the same file. --- mesonbuild/interpreter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 0974691..e28674e 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -3451,9 +3451,9 @@ root and issuing %s. if not isinstance(output, str): raise InterpreterException('Output file name must be a string') if output in self.configure_file_outputs: - mlog.warning('Output file', mlog.bold(output), 'for configure_file overwritten.') + mlog.warning('Output file', mlog.bold(output), 'for configure_file overwritten. First time written in line', self.configure_file_outputs[output], 'now in line', self.current_lineno) else: - self.configure_file_outputs[output] = None + self.configure_file_outputs[output] = self.current_lineno if ifile_abs: values = mesonlib.get_filenames_templates_dict([ifile_abs], None) outputs = mesonlib.substitute_values([output], values) -- cgit v1.1 From 2d5e1e24a12791aa18631185b30e0ec55ae2bed6 Mon Sep 17 00:00:00 2001 From: Christoph Behle Date: Mon, 2 Jul 2018 20:28:29 +0200 Subject: Consider subdir for output files. Files will only clash if in the same subdir. Print the subdir in the warning. --- mesonbuild/interpreter.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index e28674e..a882e11 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -3448,12 +3448,16 @@ root and issuing %s. raise InterpreterException('@INPUT@ used as command argument, but no input file specified.') # Validate output output = kwargs['output'] + ofile_rpath = os.path.join(self.subdir, output) if not isinstance(output, str): raise InterpreterException('Output file name must be a string') - if output in self.configure_file_outputs: - mlog.warning('Output file', mlog.bold(output), 'for configure_file overwritten. First time written in line', self.configure_file_outputs[output], 'now in line', self.current_lineno) + if ofile_rpath in self.configure_file_outputs: + if len(self.subdir) > 0: + mlog.warning('Output file', mlog.bold(ofile_rpath), 'for configure_file overwritten. First time written in subdir', self.subdir, 'line', self.configure_file_outputs[ofile_rpath], 'now in line', self.current_lineno) + else: + mlog.warning('Output file', mlog.bold(ofile_rpath), 'for configure_file overwritten. First time written in line', self.configure_file_outputs[ofile_rpath], 'now in line', self.current_lineno) else: - self.configure_file_outputs[output] = self.current_lineno + self.configure_file_outputs[ofile_rpath] = self.current_lineno if ifile_abs: values = mesonlib.get_filenames_templates_dict([ifile_abs], None) outputs = mesonlib.substitute_values([output], values) -- cgit v1.1 From 9cf38700d8f507c40c1e46e680e42d5391a24b79 Mon Sep 17 00:00:00 2001 From: Christoph Behle Date: Thu, 5 Jul 2018 20:26:58 +0200 Subject: Add release snippet --- .../snippets/configure_file_overwrite_warning.md | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 docs/markdown/snippets/configure_file_overwrite_warning.md diff --git a/docs/markdown/snippets/configure_file_overwrite_warning.md b/docs/markdown/snippets/configure_file_overwrite_warning.md new file mode 100644 index 0000000..550407d --- /dev/null +++ b/docs/markdown/snippets/configure_file_overwrite_warning.md @@ -0,0 +1,39 @@ +## Meson warns if two calls to configure_file() write to the same file + +If two calls to [`configure_file()`](#Reference-manual.md#configure_file) +write to the same file Meson will print a `WARNING:` message during +configuration. For example: +```meson +project('configure_file', 'cpp') + +configure_file( + input: 'a.in', + output: 'out', + command: ['./foo.sh'] + ) +configure_file( + input: 'a.in', + output: 'out', + command: ['./foo.sh'] +) + +``` + +This will output: + +``` +The Meson build system +Version: 0.47.0.dev1 +Source dir: /path/to/srctree +Build dir: /path/to/buildtree +Build type: native build +Project name: configure_file +Project version: undefined +Build machine cpu family: x86_64 +Build machine cpu: x86_64 +Configuring out with command +WARNING: Output file out for configure_file overwritten. First time written in line 3 now in line 8 +Configuring out with command +Build targets in project: 0 +Found ninja-1.8.2 at /usr/bin/ninja +``` -- cgit v1.1 From 2f494d2ccf798a1a1684ccece4f8b5d35b828bf0 Mon Sep 17 00:00:00 2001 From: Christoph Behle Date: Sat, 7 Jul 2018 21:13:39 +0200 Subject: Simplified and cleaned up warning. --- mesonbuild/interpreter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index a882e11..8b83e86 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -3452,10 +3452,10 @@ root and issuing %s. if not isinstance(output, str): raise InterpreterException('Output file name must be a string') if ofile_rpath in self.configure_file_outputs: - if len(self.subdir) > 0: - mlog.warning('Output file', mlog.bold(ofile_rpath), 'for configure_file overwritten. First time written in subdir', self.subdir, 'line', self.configure_file_outputs[ofile_rpath], 'now in line', self.current_lineno) - else: - mlog.warning('Output file', mlog.bold(ofile_rpath), 'for configure_file overwritten. First time written in line', self.configure_file_outputs[ofile_rpath], 'now in line', self.current_lineno) + mesonbuildfile = os.path.join(self.subdir, 'meson.build') + current_call = "{}:{}".format(mesonbuildfile, self.current_lineno) + first_call = "{}:{}".format(mesonbuildfile, self.configure_file_outputs[ofile_rpath]) + mlog.warning('Output file', mlog.bold("'{}'".format(ofile_rpath)), 'for configure_file() at', current_call, 'overwrites configure_file() output at', first_call) else: self.configure_file_outputs[ofile_rpath] = self.current_lineno if ifile_abs: -- cgit v1.1 From dffa7f35649185c1a8e096f9efa03631ef52d194 Mon Sep 17 00:00:00 2001 From: Christoph Behle Date: Sun, 8 Jul 2018 16:25:05 +0200 Subject: Add tests for warnings in configure_file() Add tests to run_unittests.py to assert warnings are printed and not printed where appropriate. --- run_unittests.py | 4 ++++ test cases/common/16 configure file/meson.build | 25 +++++++++++++++++++--- .../common/16 configure file/subdir/meson.build | 19 ++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/run_unittests.py b/run_unittests.py index b3bc271..9a71937 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -2293,6 +2293,10 @@ recommended as it is not supported on some platforms''') self.assertRegex(out, "WARNING:.*'FOO_BAR'.*nosubst-nocopy2.txt.in.*not present.*") self.assertRegex(out, "WARNING:.*'empty'.*config.h.in.*not present.*") self.assertRegex(out, "WARNING:.*empty configuration_data.*test.py.in") + # Warnings for configuration files that are overwritten. + self.assertRegex(out, "WARNING:.*double_output.txt.*overwrites") + self.assertRegex(out, "WARNING:.*subdir/double_output2.txt.*overwrites") + self.assertNotRegex(out, "WARNING:.*no_write_conflict.txt.*overwrites") # No warnings about empty configuration data objects passed to files with substitutions self.assertNotRegex(out, "WARNING:.*empty configuration_data.*nosubst-nocopy1.txt.in") self.assertNotRegex(out, "WARNING:.*empty configuration_data.*nosubst-nocopy2.txt.in") diff --git a/test cases/common/16 configure file/meson.build b/test cases/common/16 configure file/meson.build index 8c375c1..d7beeb1 100644 --- a/test cases/common/16 configure file/meson.build +++ b/test cases/common/16 configure file/meson.build @@ -193,15 +193,15 @@ configure_file( configuration : configuration_data() ) -# Test that passing an empty configuration_data() object to a file with -# @FOO@ substitutions does not print the warning. +# test that passing an empty configuration_data() object to a file with +# @foo@ substitutions does not print the warning. configure_file( input: 'nosubst-nocopy2.txt.in', output: 'nosubst-nocopy2.txt', configuration : configuration_data() ) -# Test that passing a configured file object to test() works, and that passing +# test that passing a configured file object to test() works, and that passing # an empty configuration_data() object to a file that leads to no substitutions # prints a warning (see unit tests) test_file = configure_file( @@ -210,6 +210,25 @@ test_file = configure_file( configuration: configuration_data() ) +# Test that overwriting an existing file creates a warning. +configure_file( + input: 'test.py.in', + output: 'double_output.txt', + configuration: conf +) +configure_file( + input: 'test.py.in', + output: 'double_output.txt', + configuration: conf +) + +# Test that the same file name in a different subdir will not create a warning +configure_file( + input: 'test.py.in', + output: 'no_write_conflict.txt', + configuration: conf +) + test('configure-file', test_file) cdata = configuration_data() diff --git a/test cases/common/16 configure file/subdir/meson.build b/test cases/common/16 configure file/subdir/meson.build index d802c1d..146b7b6 100644 --- a/test cases/common/16 configure file/subdir/meson.build +++ b/test cases/common/16 configure file/subdir/meson.build @@ -17,3 +17,22 @@ configure_file(input : '../dummy.dat', output : 'config2-3.h', command : [found_script, '@INPUT@', '@OUTPUT@']) run_command(check_file, join_paths(meson.current_build_dir(), 'config2-3.h')) + +# Test that overwriting an existing file creates a warning. +configure_file( + input: '../test.py.in', + output: 'double_output2.txt', + configuration: conf +) +configure_file( + input: '../test.py.in', + output: 'double_output2.txt', + configuration: conf +) + +# Test that the same file name in a different subdir will not create a warning +configure_file( + input: '../test.py.in', + output: 'no_write_conflict.txt', + configuration: conf +) -- cgit v1.1 From 430506f814847044b0e3f6e2084dfa1cfc5ec614 Mon Sep 17 00:00:00 2001 From: Christoph Behle Date: Sun, 8 Jul 2018 19:46:36 +0200 Subject: Use mlog.bold to add quotes --- mesonbuild/interpreter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 8b83e86..5cadbe9 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -3455,7 +3455,7 @@ root and issuing %s. mesonbuildfile = os.path.join(self.subdir, 'meson.build') current_call = "{}:{}".format(mesonbuildfile, self.current_lineno) first_call = "{}:{}".format(mesonbuildfile, self.configure_file_outputs[ofile_rpath]) - mlog.warning('Output file', mlog.bold("'{}'".format(ofile_rpath)), 'for configure_file() at', current_call, 'overwrites configure_file() output at', first_call) + mlog.warning('Output file', mlog.bold(ofile_rpath, True), 'for configure_file() at', current_call, 'overwrites configure_file() output at', first_call) else: self.configure_file_outputs[ofile_rpath] = self.current_lineno if ifile_abs: -- cgit v1.1 From 0f15d7982cf0bbed9bb6845d4d4784a5754594ed Mon Sep 17 00:00:00 2001 From: Christoph Behle Date: Mon, 9 Jul 2018 17:05:57 +0200 Subject: Fix regexp for warning --- run_unittests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run_unittests.py b/run_unittests.py index 9a71937..52e7780 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -2294,8 +2294,8 @@ recommended as it is not supported on some platforms''') self.assertRegex(out, "WARNING:.*'empty'.*config.h.in.*not present.*") self.assertRegex(out, "WARNING:.*empty configuration_data.*test.py.in") # Warnings for configuration files that are overwritten. - self.assertRegex(out, "WARNING:.*double_output.txt.*overwrites") - self.assertRegex(out, "WARNING:.*subdir/double_output2.txt.*overwrites") + self.assertRegex(out, "WARNING:.*\"double_output.txt\".*overwrites") + self.assertRegex(out, "WARNING:.*\"subdir.double_output2.txt\".*overwrites") self.assertNotRegex(out, "WARNING:.*no_write_conflict.txt.*overwrites") # No warnings about empty configuration data objects passed to files with substitutions self.assertNotRegex(out, "WARNING:.*empty configuration_data.*nosubst-nocopy1.txt.in") -- cgit v1.1