Skip to content

Commit d34d87a

Browse files
committed
templates: fix remaining languages for source file discovery too
I missed this in 9104bb6 as we were only testing whitelisted languages for source file discovery. Tests now handle all of these by using the map we have in compilers, as we need to know the suffix to use for the invalid source files we inject. Note that for tests, we mix explicit --lang in some cases and not others, which we could probably do better with. For these 'must fail' tests, I've stuck with explicit `--lang` to make sure we're testing what we want, but the others are perhaps up for debate. Bug: #15286
1 parent ac1dabc commit d34d87a

File tree

8 files changed

+86
-39
lines changed

8 files changed

+86
-39
lines changed

mesonbuild/templates/cstemplates.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@
3535
dependencies = [{dependencies}
3636
]
3737
38+
sources = [{source_files}
39+
40+
]
41+
3842
exe = executable(
3943
'{exe_name}',
40-
'{source_name}',
44+
[sources],
4145
install : true,
4246
dependencies : dependencies,
4347
)
@@ -83,9 +87,13 @@
8387
dependencies = [{dependencies}
8488
]
8589
90+
sources = [{source_files}
91+
92+
]
93+
8694
stlib = shared_library(
8795
'{lib_name}',
88-
'{source_file}',
96+
[sources],
8997
dependencies : dependencies,
9098
install : true,
9199
)

mesonbuild/templates/cudatemplates.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@
3636
dependencies = [{dependencies}
3737
]
3838
39+
sources = [{source_files}
40+
41+
]
42+
3943
exe = executable(
4044
'{exe_name}',
41-
'{source_name}',
45+
[sources],
4246
dependencies : dependencies,
4347
install : true,
4448
)
@@ -122,9 +126,13 @@ class {utoken}_PUBLIC {class_name} {{
122126
dependencies = [{dependencies}
123127
]
124128
129+
sources = [{source_files}
130+
131+
]
132+
125133
lib = library(
126134
'{lib_name}',
127-
'{source_file}',
135+
[sources],
128136
install : true,
129137
cpp_shared_args : lib_args,
130138
gnu_symbol_visibility : 'hidden',

mesonbuild/templates/fortrantemplates.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@
5656
dependencies = [{dependencies}
5757
]
5858
59+
sources = [{source_files}
60+
61+
]
62+
5963
lib = library(
6064
'{lib_name}',
61-
'{source_file}',
65+
[sources],
6266
install : true,
6367
fortran_shared_args : lib_args,
6468
gnu_symbol_visibility : 'hidden',
@@ -110,9 +114,13 @@
110114
dependencies = [{dependencies}
111115
]
112116
117+
sources = [{source_files}
118+
119+
]
120+
113121
exe = executable(
114122
'{exe_name}',
115-
'{source_name}',
123+
[sources],
116124
dependencies : dependencies,
117125
install : true,
118126
)

mesonbuild/templates/objcpptemplates.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,17 @@
6767
dependencies = [{dependencies}
6868
]
6969
70+
sources = [{source_files}
71+
72+
]
73+
7074
# These arguments are only used to build the shared library
7175
# not the executables that use the library.
7276
lib_args = ['-DBUILDING_{utoken}']
7377
7478
lib = library(
7579
'{lib_name}',
76-
'{source_file}',
80+
[sources],
7781
install : true,
7882
objcpp_shared_args : lib_args,
7983
dependencies : dependencies,
@@ -133,9 +137,13 @@
133137
dependencies = [{dependencies}
134138
]
135139
140+
sources = [{source_files}
141+
142+
]
143+
136144
exe = executable(
137145
'{exe_name}',
138-
'{source_name}',
146+
[sources],
139147
dependencies : dependencies,
140148
install : true,
141149
)

mesonbuild/templates/objctemplates.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,17 @@
6767
dependencies = [{dependencies}
6868
]
6969
70+
sources = [{source_files}
71+
72+
]
73+
7074
# These arguments are only used to build the shared library
7175
# not the executables that use the library.
7276
lib_args = ['-DBUILDING_{utoken}']
7377
7478
lib = library(
7579
'{lib_name}',
76-
'{source_file}',
80+
[sources],
7781
install : true,
7882
objc_shared_args : lib_args,
7983
dependencies : dependencies,
@@ -132,9 +136,13 @@
132136
dependencies = [{dependencies}
133137
]
134138
139+
sources = [{source_files}
140+
141+
]
142+
135143
exe = executable(
136144
'{exe_name}',
137-
'{source_name}',
145+
[sources],
138146
dependencies : dependencies,
139147
install : true,
140148
)

mesonbuild/templates/rusttemplates.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@
5050
dependencies = [{dependencies}
5151
]
5252
53+
sources = [{source_files}
54+
55+
]
56+
5357
lib = static_library(
5458
'{lib_name}',
55-
'{source_file}',
59+
[sources],
5660
dependencies : dependencies,
5761
install : true,
5862
)
@@ -86,9 +90,13 @@
8690
dependencies = [{dependencies}
8791
]
8892
93+
sources = [{source_files}
94+
95+
]
96+
8997
exe = executable(
9098
'{exe_name}',
91-
'{source_name}',
99+
[sources],
92100
dependencies : dependencies,
93101
install : true,
94102
)

mesonbuild/templates/valatemplates.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
dependency('gobject-2.0'),{dependencies}
2525
]
2626
27+
sources = [{source_files}
28+
]
29+
2730
exe = executable(
2831
'{exe_name}',
29-
'{source_name}',
32+
[sources],
3033
dependencies : dependencies,
3134
install : true,
3235
)
@@ -67,11 +70,15 @@
6770
dependency('gobject-2.0'),{dependencies}
6871
]
6972
73+
sources = [{source_files}
74+
75+
]
76+
7077
# These arguments are only used to build the shared library
7178
# not the executables that use the library.
7279
lib = shared_library(
7380
'foo',
74-
'{source_file}',
81+
[sources],
7582
dependencies : dependencies,
7683
install : true,
7784
install_dir : [true, true, true],

unittests/allplatformstests.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from mesonbuild.compilers.cpp import VisualStudioCPPCompiler, ClangClCPPCompiler
4848
from mesonbuild.compilers import (
4949
detect_static_linker, detect_c_compiler, compiler_from_language,
50-
detect_compiler_for
50+
detect_compiler_for, lang_suffixes
5151
)
5252
from mesonbuild.linkers import linkers
5353

@@ -2569,43 +2569,35 @@ def _template_test_dirty(lang, target_type):
25692569
self._run(ninja,
25702570
workdir=os.path.join(tmpdir, 'builddir'))
25712571

2572+
# Check for whether we're doing source collection by repeating
2573+
# with a bogus file we should pick up (and then fail to compile).
2574+
with tempfile.TemporaryDirectory() as tmpdir:
2575+
suffix = lang_suffixes[lang][0]
2576+
# Assume that this is a good enough string to error out
2577+
# in all languages.
2578+
with open(os.path.join(tmpdir, 'bar.' + suffix), 'w', encoding='utf-8') as f:
2579+
f.write('error bar')
2580+
self._run(self.meson_command + ['init', '--language', lang, '--type', target_type],
2581+
workdir=tmpdir)
2582+
self._run(self.setup_command + ['--backend=ninja', 'builddir'],
2583+
workdir=tmpdir)
2584+
with self.assertRaises(subprocess.CalledProcessError):
2585+
self._run(ninja,
2586+
workdir=os.path.join(tmpdir, 'builddir'))
2587+
25722588
# test directory with existing code file
25732589
if lang in {'c', 'cpp', 'd'}:
25742590
with tempfile.TemporaryDirectory() as tmpdir:
25752591
with open(os.path.join(tmpdir, 'foo.' + lang), 'w', encoding='utf-8') as f:
25762592
f.write('int main(void) {}')
25772593
self._run(self.meson_command + ['init', '-b'], workdir=tmpdir)
25782594

2579-
# Check for whether we're doing source collection by repeating
2580-
# with a bogus file we should pick up (and then fail to compile).
2581-
with tempfile.TemporaryDirectory() as tmpdir:
2582-
with open(os.path.join(tmpdir, 'bar.' + lang), 'w', encoding='utf-8') as f:
2583-
f.write('#error bar')
2584-
self._run(self.meson_command + ['init'], workdir=tmpdir)
2585-
self._run(self.setup_command + ['--backend=ninja', 'builddir'],
2586-
workdir=tmpdir)
2587-
with self.assertRaises(subprocess.CalledProcessError):
2588-
self._run(ninja,
2589-
workdir=os.path.join(tmpdir, 'builddir'))
2590-
25912595
elif lang in {'java'}:
25922596
with tempfile.TemporaryDirectory() as tmpdir:
25932597
with open(os.path.join(tmpdir, 'Foo.' + lang), 'w', encoding='utf-8') as f:
25942598
f.write('public class Foo { public static void main() {} }')
25952599
self._run(self.meson_command + ['init', '-b'], workdir=tmpdir)
25962600

2597-
# Check for whether we're doing source collection by repeating
2598-
# with a bogus file we should pick up (and then fail to compile).
2599-
with tempfile.TemporaryDirectory() as tmpdir:
2600-
with open(os.path.join(tmpdir, 'Bar.' + lang), 'w', encoding='utf-8') as f:
2601-
f.write('public class Bar { public private static void main() {} }')
2602-
self._run(self.meson_command + ['init'], workdir=tmpdir)
2603-
self._run(self.setup_command + ['--backend=ninja', 'builddir'],
2604-
workdir=tmpdir)
2605-
with self.assertRaises(subprocess.CalledProcessError):
2606-
self._run(ninja,
2607-
workdir=os.path.join(tmpdir, 'builddir'))
2608-
26092601
for lang, target_type, fresh in itertools.product(langs, ('executable', 'library'), (True, False)):
26102602
with self.subTest(f'Language: {lang}; type: {target_type}; fresh: {fresh}'):
26112603
_template_test_fresh(lang, target_type) if fresh else _template_test_dirty(lang, target_type)

0 commit comments

Comments
 (0)