Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mesonbuild/mesonmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
1 change: 1 addition & 0 deletions test cases/unit/128 long opt vs D/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project('empty test')
1 change: 1 addition & 0 deletions test cases/unit/128 long opt vs D/meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('sysconfdir2', type: 'string', value: '')
30 changes: 30 additions & 0 deletions unittests/allplatformstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading