diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2025-04-17 17:57:58 +0200 |
---|---|---|
committer | Eli Schwartz <eschwartz93@gmail.com> | 2025-04-18 15:38:56 -0400 |
commit | b9db06b2b12a50b95185082910cfef01341fd7db (patch) | |
tree | f2a4b9629406099db07f5b73a0274ab824d25237 | |
parent | 855cf199fc950de3e764a74e7b545c2213aa601c (diff) | |
download | meson-b9db06b2b12a50b95185082910cfef01341fd7db.zip meson-b9db06b2b12a50b95185082910cfef01341fd7db.tar.gz meson-b9db06b2b12a50b95185082910cfef01341fd7db.tar.bz2 |
fix prefix computation in validate_original_args
validate_original_args only checks whether an option is prefixed with the name of a
built-in option that was also set. It does not check whether the prefix is the full
name of the option specified with -D. Adding an "=" at the end fixes the test.
Fixes: #14487
Reported-by: Alyssa Ross <hi@alyssa.is>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | mesonbuild/mesonmain.py | 2 | ||||
-rw-r--r-- | test cases/unit/128 long opt vs D/meson.build | 1 | ||||
-rw-r--r-- | test cases/unit/128 long opt vs D/meson_options.txt | 1 | ||||
-rw-r--r-- | unittests/allplatformstests.py | 30 |
4 files changed, 33 insertions, 1 deletions
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 6a88501..dd265c4 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -247,7 +247,7 @@ def validate_original_args(args): #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/test cases/unit/128 long opt vs D/meson.build b/test cases/unit/128 long opt vs D/meson.build new file mode 100644 index 0000000..e05d88d --- /dev/null +++ b/test cases/unit/128 long opt vs D/meson.build @@ -0,0 +1 @@ +project('empty test') diff --git a/test cases/unit/128 long opt vs D/meson_options.txt b/test cases/unit/128 long opt vs D/meson_options.txt new file mode 100644 index 0000000..255bf15 --- /dev/null +++ b/test cases/unit/128 long opt vs D/meson_options.txt @@ -0,0 +1 @@ +option('sysconfdir2', type: 'string', value: '') diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index 412723c..2fee06c 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -1361,6 +1361,36 @@ class AllPlatformTests(BasePlatformTests): self.utime(os.path.join(testdir, 'srcgen.py')) self.assertRebuiltTarget('basic') + def test_long_opt_vs_D(self): + ''' + Test that conflicts between -D for builtin options and the corresponding + long option are detected without false positives or negatives. + ''' + testdir = os.path.join(self.unit_test_dir, '128 long opt vs D') + + for opt in ['-Dsysconfdir=/etc', '-Dsysconfdir2=/etc']: + exception_raised = False + try: + self.init(testdir, extra_args=[opt, '--sysconfdir=/etc']) + except subprocess.CalledProcessError: + exception_raised = True + if 'sysconfdir2' in opt: + self.assertFalse(exception_raised, f'{opt} --sysconfdir raised an exception') + else: + self.assertTrue(exception_raised, f'{opt} --sysconfdir did not raise an exception') + + exception_raised = False + try: + self.init(testdir, extra_args=['--sysconfdir=/etc', opt]) + except subprocess.CalledProcessError: + exception_raised = True + if 'sysconfdir2' in opt: + self.assertFalse(exception_raised, f'--sysconfdir {opt} raised an exception') + else: + self.assertTrue(exception_raised, f'--sysconfdir {opt} did not raise an exception') + + self.wipe() + def test_static_library_lto(self): ''' Test that static libraries can be built with LTO and linked to |