diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 6a88501d4564..dd265c41b74c 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -247,7 +247,7 @@ def has_startswith(coll, target): #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 000000000000..e05d88d200d3 --- /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 000000000000..255bf1576e02 --- /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 412723cc53a2..2fee06c690fa 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -1361,6 +1361,36 @@ def test_source_generator_program_cause_rebuild(self): 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