Substitute output file then check for conflict.

Fixes Issue #4323.
The check to see if a call to configure_file() overwrites the output of
a preceding call should perform the substitution for the output file
before doing the check.

Added tests to ensure the proper behaviour.
pull/4341/head
Christoph Behle 7 years ago committed by Jussi Pakkanen
parent 646a073e36
commit c0236e10f3
  1. 10
      mesonbuild/interpreter.py
  2. 2
      run_unittests.py
  3. 0
      test cases/common/14 configure file/differentafterbasename1.in
  4. 0
      test cases/common/14 configure file/differentafterbasename2.in
  5. 24
      test cases/common/14 configure file/meson.build
  6. 0
      test cases/common/14 configure file/sameafterbasename.in
  7. 0
      test cases/common/14 configure file/sameafterbasename.in2

@ -3540,9 +3540,13 @@ 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 ifile_abs:
values = mesonlib.get_filenames_templates_dict([ifile_abs], None)
outputs = mesonlib.substitute_values([output], values)
output = outputs[0]
ofile_rpath = os.path.join(self.subdir, output)
if ofile_rpath in self.configure_file_outputs:
mesonbuildfile = os.path.join(self.subdir, 'meson.build')
current_call = "{}:{}".format(mesonbuildfile, self.current_lineno)
@ -3550,10 +3554,6 @@ root and issuing %s.
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:
values = mesonlib.get_filenames_templates_dict([ifile_abs], None)
outputs = mesonlib.substitute_values([output], values)
output = outputs[0]
if os.path.dirname(output) != '':
raise InterpreterException('Output file name must not contain a subdirectory.')
(ofile_path, ofile_fname) = os.path.split(os.path.join(self.subdir, output))

@ -2682,6 +2682,8 @@ recommended as it is not supported on some platforms''')
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")
self.assertNotRegex(out, "WARNING:.*@BASENAME@.*overwrites")
self.assertRegex(out, "WARNING:.*\"sameafterbasename\".*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")

@ -218,6 +218,30 @@ configure_file(
output: 'no_write_conflict.txt',
configuration: conf)
# Test that @BASENAME@ is substituted before checking and does not create a warning.
configure_file(
input: 'differentafterbasename1.in',
output: '@BASENAME@',
configuration: conf
)
configure_file(
input: 'differentafterbasename2.in',
output: '@BASENAME@',
configuration: conf
)
# Test that @BASENAME@ is substituted before checking and does create a warning on conflict.
configure_file(
input: 'sameafterbasename.in',
output: '@BASENAME@',
configuration: conf
)
configure_file(
input: 'sameafterbasename.in2',
output: '@BASENAME@',
configuration: conf
)
test('configure-file', test_file)
cdata = configuration_data()

Loading…
Cancel
Save