Skip to content

Commit 0a52792

Browse files
committed
ninja backend: Fix usage of same constants file for native and cross
For example: ``` meson builddir \ --native-file vs2019-paths.txt \ --native-file vs2019-win-x64.txt \ --cross-file vs2019-paths.txt \ --cross-file vs2019-win-arm64.txt ``` This was causing the error: > ERROR: Multiple producers for Ninja target "/path/to/vs2019-paths.txt". Please rename your targets. Fix it by using a set() when generating the list of regen files, and add a test for it too.
1 parent a75a837 commit 0a52792

File tree

5 files changed

+39
-32
lines changed

5 files changed

+39
-32
lines changed

mesonbuild/backend/backends.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,14 +1206,14 @@ def generate_depmf_install(self, d: InstallData) -> None:
12061206
def get_regen_filelist(self) -> T.List[str]:
12071207
'''List of all files whose alteration means that the build
12081208
definition needs to be regenerated.'''
1209-
deps = [str(Path(self.build_to_src) / df)
1210-
for df in self.interpreter.get_build_def_files()]
1209+
deps = OrderedSet([str(Path(self.build_to_src) / df)
1210+
for df in self.interpreter.get_build_def_files()])
12111211
if self.environment.is_cross_build():
1212-
deps.extend(self.environment.coredata.cross_files)
1213-
deps.extend(self.environment.coredata.config_files)
1214-
deps.append('meson-private/coredata.dat')
1212+
deps.update(self.environment.coredata.cross_files)
1213+
deps.update(self.environment.coredata.config_files)
1214+
deps.add('meson-private/coredata.dat')
12151215
self.check_clock_skew(deps)
1216-
return deps
1216+
return list(deps)
12171217

12181218
def generate_regen_info(self) -> None:
12191219
deps = self.get_regen_filelist()
@@ -1225,7 +1225,7 @@ def generate_regen_info(self) -> None:
12251225
with open(filename, 'wb') as f:
12261226
pickle.dump(regeninfo, f)
12271227

1228-
def check_clock_skew(self, file_list: T.List[str]) -> None:
1228+
def check_clock_skew(self, file_list: T.Iterable[str]) -> None:
12291229
# If a file that leads to reconfiguration has a time
12301230
# stamp in the future, it will trigger an eternal reconfigure
12311231
# loop.

unittests/allplatformstests.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,7 +2369,7 @@ def test_native_dep_pkgconfig(self):
23692369
endian = 'little'
23702370
'''.format(os.path.join(testdir, 'cross_pkgconfig.py'))))
23712371
crossfile.flush()
2372-
self.meson_cross_file = crossfile.name
2372+
self.meson_cross_files = [crossfile.name]
23732373

23742374
env = {'PKG_CONFIG_LIBDIR': os.path.join(testdir,
23752375
'native_pkgconfig')}
@@ -2397,7 +2397,7 @@ def test_pkg_config_libdir(self):
23972397
endian = 'little'
23982398
'''.format(os.path.join(testdir, 'cross_pkgconfig'))))
23992399
crossfile.flush()
2400-
self.meson_cross_file = crossfile.name
2400+
self.meson_cross_files = [crossfile.name]
24012401

24022402
env = {'PKG_CONFIG_LIBDIR': os.path.join(testdir,
24032403
'native_pkgconfig')}
@@ -2631,8 +2631,8 @@ def test_identity_cross(self):
26312631
testdir = os.path.join(self.unit_test_dir, '70 cross')
26322632
# Do a build to generate a cross file where the host is this target
26332633
self.init(testdir, extra_args=['-Dgenerate=true'])
2634-
self.meson_cross_file = os.path.join(self.builddir, "crossfile")
2635-
self.assertTrue(os.path.exists(self.meson_cross_file))
2634+
self.meson_cross_files = [os.path.join(self.builddir, "crossfile")]
2635+
self.assertTrue(os.path.exists(self.meson_cross_files[0]))
26362636
# Now verify that this is detected as cross
26372637
self.new_builddir()
26382638
self.init(testdir)
@@ -3601,14 +3601,14 @@ def test_nostdlib(self):
36013601
'''))
36023602

36033603
# Test native C stdlib
3604-
self.meson_native_file = machinefile
3604+
self.meson_native_files = [machinefile]
36053605
self.init(testdir)
36063606
self.build()
36073607

36083608
# Test cross C stdlib
36093609
self.new_builddir()
3610-
self.meson_native_file = None
3611-
self.meson_cross_file = machinefile
3610+
self.meson_native_files = []
3611+
self.meson_cross_files = [machinefile]
36123612
self.init(testdir)
36133613
self.build()
36143614

unittests/baseplatformtests.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def setUp(self):
5656
# Get the backend
5757
self.backend = getattr(Backend, os.environ['MESON_UNIT_TEST_BACKEND'])
5858
self.meson_args = ['--backend=' + self.backend.name]
59-
self.meson_native_file = None
60-
self.meson_cross_file = None
59+
self.meson_native_files = []
60+
self.meson_cross_files = []
6161
self.meson_command = python_command + [get_meson_script()]
6262
self.setup_command = self.meson_command + self.meson_args
6363
self.mconf_command = self.meson_command + ['configure']
@@ -192,10 +192,10 @@ def init(self, srcdir, *,
192192
args += ['--prefix', self.prefix]
193193
if self.libdir:
194194
args += ['--libdir', self.libdir]
195-
if self.meson_native_file:
196-
args += ['--native-file', self.meson_native_file]
197-
if self.meson_cross_file:
198-
args += ['--cross-file', self.meson_cross_file]
195+
for f in self.meson_native_files:
196+
args += ['--native-file', f]
197+
for f in self.meson_cross_files:
198+
args += ['--cross-file', f]
199199
self.privatedir = os.path.join(self.builddir, 'meson-private')
200200
if inprocess:
201201
try:

unittests/linuxcrosstests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class LinuxCrossArmTests(BaseLinuxCrossTests):
4444

4545
def setUp(self):
4646
super().setUp()
47-
self.meson_cross_file = os.path.join(self.src_root, 'cross', 'ubuntu-armhf.txt')
47+
self.meson_cross_files = [os.path.join(self.src_root, 'cross', 'ubuntu-armhf.txt')]
4848

4949
def test_cflags_cross_environment_pollution(self):
5050
'''
@@ -66,7 +66,7 @@ def test_cross_file_overrides_always_args(self):
6666
https://github.com/mesonbuild/meson/issues/3089
6767
'''
6868
testdir = os.path.join(self.unit_test_dir, '33 cross file overrides always args')
69-
self.meson_cross_file = os.path.join(testdir, 'ubuntu-armhf-overrides.txt')
69+
self.meson_cross_files = [os.path.join(testdir, 'ubuntu-armhf-overrides.txt')]
7070
self.init(testdir)
7171
compdb = self.get_compdb()
7272
self.assertRegex(compdb[0]['command'], '-D_FILE_OFFSET_BITS=64.*-U_FILE_OFFSET_BITS')
@@ -137,7 +137,7 @@ class LinuxCrossMingwTests(BaseLinuxCrossTests):
137137

138138
def setUp(self):
139139
super().setUp()
140-
self.meson_cross_file = os.path.join(self.src_root, 'cross', 'linux-mingw-w64-64bit.txt')
140+
self.meson_cross_files = [os.path.join(self.src_root, 'cross', 'linux-mingw-w64-64bit.txt')]
141141

142142
def test_exe_wrapper_behaviour(self):
143143
'''
@@ -154,7 +154,7 @@ def test_exe_wrapper_behaviour(self):
154154
self.wipe()
155155
os.mkdir(self.builddir)
156156
# Change cross file to use a non-existing exe_wrapper and it should fail
157-
self.meson_cross_file = os.path.join(testdir, 'broken-cross.txt')
157+
self.meson_cross_files = [os.path.join(testdir, 'broken-cross.txt')]
158158
# Force tracebacks so we can detect them properly
159159
env = {'MESON_FORCE_BACKTRACE': '1'}
160160
error_message = "An exe_wrapper is needed but was not found. Please define one in cross file and check the command and/or add it to PATH."

unittests/linuxliketests.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ def test_cross_find_program(self):
10301030
endian = 'little'
10311031
'''))
10321032
crossfile.flush()
1033-
self.meson_cross_file = crossfile.name
1033+
self.meson_cross_files = [crossfile.name]
10341034
self.init(testdir)
10351035

10361036
def test_reconfigure(self):
@@ -1501,21 +1501,28 @@ def test_noncross_options(self):
15011501
def test_identity_cross(self):
15021502
testdir = os.path.join(self.unit_test_dir, '61 identity cross')
15031503

1504+
constantsfile = tempfile.NamedTemporaryFile(mode='w')
1505+
constantsfile.write(textwrap.dedent('''\
1506+
[constants]
1507+
py_ext = '.py'
1508+
'''))
1509+
constantsfile.flush()
1510+
15041511
nativefile = tempfile.NamedTemporaryFile(mode='w')
15051512
nativefile.write(textwrap.dedent('''\
15061513
[binaries]
1507-
c = ['{}']
1508-
'''.format(os.path.join(testdir, 'build_wrapper.py'))))
1514+
c = ['{}' + py_ext]
1515+
'''.format(os.path.join(testdir, 'build_wrapper'))))
15091516
nativefile.flush()
1510-
self.meson_native_file = nativefile.name
1517+
self.meson_native_files = [constantsfile.name, nativefile.name]
15111518

15121519
crossfile = tempfile.NamedTemporaryFile(mode='w')
15131520
crossfile.write(textwrap.dedent('''\
15141521
[binaries]
1515-
c = ['{}']
1516-
'''.format(os.path.join(testdir, 'host_wrapper.py'))))
1522+
c = ['{}' + py_ext]
1523+
'''.format(os.path.join(testdir, 'host_wrapper'))))
15171524
crossfile.flush()
1518-
self.meson_cross_file = crossfile.name
1525+
self.meson_cross_files = [constantsfile.name, crossfile.name]
15191526

15201527
# TODO should someday be explicit about build platform only here
15211528
self.init(testdir)
@@ -1531,7 +1538,7 @@ def test_identity_cross_env(self):
15311538
c = ['{}']
15321539
'''.format(os.path.join(testdir, 'host_wrapper.py'))))
15331540
crossfile.flush()
1534-
self.meson_cross_file = crossfile.name
1541+
self.meson_cross_files = [crossfile.name]
15351542
# TODO should someday be explicit about build platform only here
15361543
self.init(testdir, override_envvars=env)
15371544

0 commit comments

Comments
 (0)