From 6419b22f6183d87c92d42bd3a99aa2787cb13e08 Mon Sep 17 00:00:00 2001 From: Sam James Date: Sun, 23 Nov 2025 20:14:42 +0000 Subject: templates: fix --executable * In 1.7.1, the behaviour of --executable was to just ignore it. * After my recent 9104bb616766bd9a05f0b2f280359463d32e227d, the behaviour was that we'd require, for --executable xyz, xyz.c to exist or we'd fail to generate. Neither are good! Instead, create the sample source file w/ the project name, but call the executable whatever the user passed with `--executable`. Bug: https://github.com/mesonbuild/meson/issues/15286 --- mesonbuild/templates/sampleimpl.py | 2 +- unittests/allplatformstests.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mesonbuild/templates/sampleimpl.py b/mesonbuild/templates/sampleimpl.py index 00735c498..46f9a70aa 100644 --- a/mesonbuild/templates/sampleimpl.py +++ b/mesonbuild/templates/sampleimpl.py @@ -133,7 +133,7 @@ class FileImpl(SampleImpl): def __init__(self, args: Arguments): super().__init__(args) - self.sources = args.srcfiles if args.srcfiles else [Path(f'{self.executable_name}.{self.source_ext}')] + self.sources = args.srcfiles if args.srcfiles else [Path(f'{self.name}.{self.source_ext}')] def create_executable(self) -> None: source_name = f'{self.lowercase_token}.{self.source_ext}' diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index 2c5123281..554217043 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -2541,6 +2541,20 @@ class AllPlatformTests(BasePlatformTests): 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')) + + if lang not in {'cs', 'java'}: + exe = os.path.join(tmpdir, 'builddir', 'foobar' + exe_suffix) + self.assertTrue(os.path.exists(exe)) + def _template_test_dirty(lang, target_type): if is_windows() and lang == 'fortran' and target_type == 'library': # non-Gfortran Windows Fortran compilers do not do shared libraries in a Fortran standard way -- cgit v1.2.3