diff options
| author | Sam James <sam@gentoo.org> | 2025-11-23 20:52:21 +0000 |
|---|---|---|
| committer | Jussi Pakkanen <jussi.pakkanen@mailbox.org> | 2025-12-01 16:55:18 +0200 |
| commit | aed2444f75d2089872d37ad8c608321e39b2aa78 (patch) | |
| tree | 17f3cf7be97f506faa9e629040849e24b0ace2fe | |
| parent | 176edafdd6dd5549525223539dbc7f4a1f74ee24 (diff) | |
| download | meson-aed2444f75d2089872d37ad8c608321e39b2aa78.tar.gz | |
templates: fix remaining languages for source file discovery too
I missed this in 9104bb616766bd9a05f0b2f280359463d32e227d 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: https://github.com/mesonbuild/meson/issues/15286
| -rw-r--r-- | mesonbuild/templates/cstemplates.py | 12 | ||||
| -rw-r--r-- | mesonbuild/templates/cudatemplates.py | 12 | ||||
| -rw-r--r-- | mesonbuild/templates/fortrantemplates.py | 12 | ||||
| -rw-r--r-- | mesonbuild/templates/objcpptemplates.py | 12 | ||||
| -rw-r--r-- | mesonbuild/templates/objctemplates.py | 12 | ||||
| -rw-r--r-- | mesonbuild/templates/rusttemplates.py | 12 | ||||
| -rw-r--r-- | mesonbuild/templates/valatemplates.py | 11 | ||||
| -rw-r--r-- | unittests/allplatformstests.py | 61 |
8 files changed, 93 insertions, 51 deletions
diff --git a/mesonbuild/templates/cstemplates.py b/mesonbuild/templates/cstemplates.py index 59c718953..297d9b1d4 100644 --- a/mesonbuild/templates/cstemplates.py +++ b/mesonbuild/templates/cstemplates.py @@ -35,9 +35,13 @@ hello_cs_meson_template = '''project( dependencies = [{dependencies} ] +sources = [{source_files} + +] + exe = executable( '{exe_name}', - '{source_name}', + [sources], install : true, dependencies : dependencies, ) @@ -83,9 +87,13 @@ lib_cs_meson_template = '''project( dependencies = [{dependencies} ] +sources = [{source_files} + +] + stlib = shared_library( '{lib_name}', - '{source_file}', + [sources], dependencies : dependencies, install : true, ) diff --git a/mesonbuild/templates/cudatemplates.py b/mesonbuild/templates/cudatemplates.py index 252f44a27..45cd155f9 100644 --- a/mesonbuild/templates/cudatemplates.py +++ b/mesonbuild/templates/cudatemplates.py @@ -36,9 +36,13 @@ hello_cuda_meson_template = '''project( dependencies = [{dependencies} ] +sources = [{source_files} + +] + exe = executable( '{exe_name}', - '{source_name}', + [sources], dependencies : dependencies, install : true, ) @@ -122,9 +126,13 @@ lib_args = ['-DBUILDING_{utoken}'] dependencies = [{dependencies} ] +sources = [{source_files} + +] + lib = library( '{lib_name}', - '{source_file}', + [sources], install : true, cpp_shared_args : lib_args, gnu_symbol_visibility : 'hidden', diff --git a/mesonbuild/templates/fortrantemplates.py b/mesonbuild/templates/fortrantemplates.py index 7aaa9d39c..7d97c58f6 100644 --- a/mesonbuild/templates/fortrantemplates.py +++ b/mesonbuild/templates/fortrantemplates.py @@ -56,9 +56,13 @@ lib_args = ['-DBUILDING_{utoken}'] dependencies = [{dependencies} ] +sources = [{source_files} + +] + lib = library( '{lib_name}', - '{source_file}', + [sources], install : true, fortran_shared_args : lib_args, gnu_symbol_visibility : 'hidden', @@ -110,9 +114,13 @@ hello_fortran_meson_template = '''project( dependencies = [{dependencies} ] +sources = [{source_files} + +] + exe = executable( '{exe_name}', - '{source_name}', + [sources], dependencies : dependencies, install : true, ) diff --git a/mesonbuild/templates/objcpptemplates.py b/mesonbuild/templates/objcpptemplates.py index 1f4bef431..c6eddd646 100644 --- a/mesonbuild/templates/objcpptemplates.py +++ b/mesonbuild/templates/objcpptemplates.py @@ -73,13 +73,17 @@ lib_objcpp_meson_template = '''project( dependencies = [{dependencies} ] +sources = [{source_files} + +] + # These arguments are only used to build the shared library # not the executables that use the library. lib_args = ['-DBUILDING_{utoken}'] lib = library( '{lib_name}', - '{source_file}', + [sources], install : true, objcpp_shared_args : lib_args, dependencies : dependencies, @@ -139,9 +143,13 @@ hello_objcpp_meson_template = '''project( dependencies = [{dependencies} ] +sources = [{source_files} + +] + exe = executable( '{exe_name}', - '{source_name}', + [sources], dependencies : dependencies, install : true, ) diff --git a/mesonbuild/templates/objctemplates.py b/mesonbuild/templates/objctemplates.py index 8708d78e3..8b73b365f 100644 --- a/mesonbuild/templates/objctemplates.py +++ b/mesonbuild/templates/objctemplates.py @@ -73,13 +73,17 @@ lib_objc_meson_template = '''project( dependencies = [{dependencies} ] +sources = [{source_files} + +] + # These arguments are only used to build the shared library # not the executables that use the library. lib_args = ['-DBUILDING_{utoken}'] lib = library( '{lib_name}', - '{source_file}', + [sources], install : true, objc_shared_args : lib_args, dependencies : dependencies, @@ -138,9 +142,13 @@ hello_objc_meson_template = '''project( dependencies = [{dependencies} ] +sources = [{source_files} + +] + exe = executable( '{exe_name}', - '{source_name}', + [sources], dependencies : dependencies, install : true, ) diff --git a/mesonbuild/templates/rusttemplates.py b/mesonbuild/templates/rusttemplates.py index ee1f0081d..4c10cdd99 100644 --- a/mesonbuild/templates/rusttemplates.py +++ b/mesonbuild/templates/rusttemplates.py @@ -50,9 +50,13 @@ rust = import('rust') dependencies = [{dependencies} ] +sources = [{source_files} + +] + lib = static_library( '{lib_name}', - '{source_file}', + [sources], dependencies : dependencies, install : true, ) @@ -86,9 +90,13 @@ hello_rust_meson_template = '''project( dependencies = [{dependencies} ] +sources = [{source_files} + +] + exe = executable( '{exe_name}', - '{source_name}', + [sources], dependencies : dependencies, install : true, ) diff --git a/mesonbuild/templates/valatemplates.py b/mesonbuild/templates/valatemplates.py index b2aab3f31..4e867d49a 100644 --- a/mesonbuild/templates/valatemplates.py +++ b/mesonbuild/templates/valatemplates.py @@ -24,9 +24,12 @@ dependencies = [ dependency('gobject-2.0'),{dependencies} ] +sources = [{source_files} +] + exe = executable( '{exe_name}', - '{source_name}', + [sources], dependencies : dependencies, install : true, ) @@ -67,11 +70,15 @@ dependencies = [ dependency('gobject-2.0'),{dependencies} ] +sources = [{source_files} + +] + # These arguments are only used to build the shared library # not the executables that use the library. lib = shared_library( 'foo', - '{source_file}', + [sources], dependencies : dependencies, install : true, install_dir : [true, true, true], diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index 93fde1824..1304658da 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -47,7 +47,7 @@ from mesonbuild.compilers.c import VisualStudioCCompiler, ClangClCCompiler from mesonbuild.compilers.cpp import VisualStudioCPPCompiler, ClangClCPPCompiler from mesonbuild.compilers import ( detect_static_linker, detect_c_compiler, compiler_from_language, - detect_compiler_for + detect_compiler_for, lang_suffixes ) from mesonbuild.linkers import linkers @@ -2536,20 +2536,17 @@ class AllPlatformTests(BasePlatformTests): with tempfile.TemporaryDirectory() as tmpdir: self._run(self.meson_command + ['init', '--language', lang, '--type', target_type], workdir=tmpdir) - self._run(self.setup_command + ['--backend=ninja', 'builddir'], - workdir=tmpdir) - self._run(ninja, - workdir=os.path.join(tmpdir, 'builddir')) + self._run(self.setup_command + ['--backend=ninja', 'builddir'], workdir=tmpdir) + self._run(ninja, workdir=os.path.join(tmpdir, 'builddir')) # custom executable name if target_type == 'executable': with tempfile.TemporaryDirectory() as tmpdir: self._run(self.meson_command + ['init', '--language', lang, '--type', target_type, - '--executable', 'foobar'], workdir=tmpdir) - self._run(self.setup_command + ['--backend=ninja', 'builddir'], - workdir=tmpdir) - self._run(ninja, - workdir=os.path.join(tmpdir, 'builddir')) + '--executable', 'foobar'], + workdir=tmpdir) + self._run(self.setup_command + ['--backend=ninja', 'builddir'], workdir=tmpdir) + self._run(ninja, workdir=os.path.join(tmpdir, 'builddir')) if lang not in {'cs', 'java'}: exe = os.path.join(tmpdir, 'builddir', 'foobar' + exe_suffix) @@ -2566,10 +2563,24 @@ class AllPlatformTests(BasePlatformTests): # test empty directory with tempfile.TemporaryDirectory() as tmpdir: self._run(self.meson_command + ['init', '--language', lang, '--type', target_type], - workdir=tmpdir) + workdir=tmpdir) + self._run(self.setup_command + ['--backend=ninja', 'builddir'], workdir=tmpdir) + self._run(ninja, workdir=os.path.join(tmpdir, 'builddir')) + + # Check for whether we're doing source collection by repeating + # with a bogus file we should pick up (and then fail to compile). + with tempfile.TemporaryDirectory() as tmpdir: + suffix = lang_suffixes[lang][0] + # Assume that this is a good enough string to error out + # in all languages. + with open(os.path.join(tmpdir, 'bar.' + suffix), 'w', encoding='utf-8') as f: + f.write('error bar') + self._run(self.meson_command + ['init', '--language', lang, '--type', target_type], + workdir=tmpdir) self._run(self.setup_command + ['--backend=ninja', 'builddir'], - workdir=tmpdir) - self._run(ninja, + workdir=tmpdir) + with self.assertRaises(subprocess.CalledProcessError): + self._run(ninja, workdir=os.path.join(tmpdir, 'builddir')) # test directory with existing code file @@ -2579,36 +2590,12 @@ class AllPlatformTests(BasePlatformTests): f.write('int main(void) {}') self._run(self.meson_command + ['init', '-b'], workdir=tmpdir) - # Check for whether we're doing source collection by repeating - # with a bogus file we should pick up (and then fail to compile). - with tempfile.TemporaryDirectory() as tmpdir: - with open(os.path.join(tmpdir, 'bar.' + lang), 'w', encoding='utf-8') as f: - f.write('#error bar') - self._run(self.meson_command + ['init'], workdir=tmpdir) - self._run(self.setup_command + ['--backend=ninja', 'builddir'], - workdir=tmpdir) - with self.assertRaises(subprocess.CalledProcessError): - self._run(ninja, - workdir=os.path.join(tmpdir, 'builddir')) - elif lang in {'java'}: with tempfile.TemporaryDirectory() as tmpdir: with open(os.path.join(tmpdir, 'Foo.' + lang), 'w', encoding='utf-8') as f: f.write('public class Foo { public static void main() {} }') self._run(self.meson_command + ['init', '-b'], workdir=tmpdir) - # Check for whether we're doing source collection by repeating - # with a bogus file we should pick up (and then fail to compile). - with tempfile.TemporaryDirectory() as tmpdir: - with open(os.path.join(tmpdir, 'Bar.' + lang), 'w', encoding='utf-8') as f: - f.write('public class Bar { public private static void main() {} }') - self._run(self.meson_command + ['init'], workdir=tmpdir) - self._run(self.setup_command + ['--backend=ninja', 'builddir'], - workdir=tmpdir) - with self.assertRaises(subprocess.CalledProcessError): - self._run(ninja, - workdir=os.path.join(tmpdir, 'builddir')) - for lang, target_type, fresh in itertools.product(langs, ('executable', 'library'), (True, False)): with self.subTest(f'Language: {lang}; type: {target_type}; fresh: {fresh}'): _template_test_fresh(lang, target_type) if fresh else _template_test_dirty(lang, target_type) |
