summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/mesonmain.py2
-rw-r--r--test cases/unit/128 long opt vs D/meson.build1
-rw-r--r--test cases/unit/128 long opt vs D/meson_options.txt1
-rw-r--r--unittests/allplatformstests.py30
4 files changed, 33 insertions, 1 deletions
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py
index 6a88501d4..dd265c41b 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 000000000..e05d88d20
--- /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 000000000..255bf1576
--- /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 412723cc5..2fee06c69 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