diff options
| author | Tobias Stoeckmann <tobias@stoeckmann.org> | 2025-10-04 11:25:18 +0200 |
|---|---|---|
| committer | Jussi Pakkanen <jussi.pakkanen@mailbox.org> | 2025-10-17 15:30:52 +0300 |
| commit | 7b4c799650629b080032caa374daccf325d33cc2 (patch) | |
| tree | 8b54bb2fe4f19439e7e5f7c1c83fcab9566240d1 | |
| parent | 78ffa5392394a62f7a50f54a2277f40bdb450907 (diff) | |
| download | meson-7b4c799650629b080032caa374daccf325d33cc2.tar.gz | |
options: Fix long/short option mixture detection
Take the key/value separator `=` into account when comparing long and
short option names to avoid invalid matches.
| -rw-r--r-- | mesonbuild/mesonmain.py | 4 | ||||
| -rw-r--r-- | unittests/platformagnostictests.py | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index dd265c41b..ca7a18414 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -240,14 +240,14 @@ def validate_original_args(args): def has_startswith(coll, target): for entry in coll: - if entry.startswith(target): + if entry.startswith(target + '=') or entry == target: return True return False #ds = [x for x in args if x.startswith('-D')] #longs = [x for x in args if x.startswith('--')] for optionkey in itertools.chain(mesonbuild.options.BUILTIN_DIR_OPTIONS, mesonbuild.options.BUILTIN_CORE_OPTIONS): longarg = mesonbuild.options.argparse_name_to_arg(optionkey.name) - shortarg = f'-D{optionkey.name}=' + shortarg = f'-D{optionkey.name}' if has_startswith(args, longarg) and has_startswith(args, shortarg): sys.exit( f'Got argument {optionkey.name} as both {shortarg} and {longarg}. Pick one.') diff --git a/unittests/platformagnostictests.py b/unittests/platformagnostictests.py index 6a1ea38be..37ac7ad7a 100644 --- a/unittests/platformagnostictests.py +++ b/unittests/platformagnostictests.py @@ -560,3 +560,8 @@ class PlatformAgnosticTests(BasePlatformTests): self.clean() self._run(self.mtest_command + ['runner-with-exedep']) + + def test_setup_mixed_long_short_options(self) -> None: + """Mixing unity and unity_size as long and short options should work.""" + testdir = self.copy_srcdir(os.path.join(self.common_test_dir, '1 trivial')) + self.init(testdir, extra_args=['-Dunity=on', '--unity-size=123']) |
