Skip to content

Commit 7c54168

Browse files
committed
options: project options never act globally
Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 9e32614 commit 7c54168

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

mesonbuild/options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,8 +1378,9 @@ def initialize_from_subproject_call(self,
13781378
options[key] = valstr
13791379

13801380
# then global settings from machine file and command line
1381+
# **but not if they are toplevel project options**
13811382
for key, valstr in itertools.chain(machine_file_options.items(), cmd_line_options.items()):
1382-
if key.subproject is None:
1383+
if key.subproject is None and not self.is_project_option(key.as_root()):
13831384
subp_key = key.evolve(subproject=subproject)
13841385
self.pending_options.pop(subp_key, None)
13851386
options.pop(subp_key, None)

unittests/optiontests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,26 @@ def test_subproject_nonexistent(self):
240240
self.assertFalse(optstore.accept_as_pending_option(OptionKey('foo', subproject='found'), subprojects))
241241
self.assertTrue(optstore.accept_as_pending_option(OptionKey('foo', subproject='whatisthis'), subprojects))
242242

243+
def test_subproject_proj_opt_with_same_name(self):
244+
name = 'tests'
245+
subp = 'subp'
246+
247+
optstore = OptionStore(False)
248+
prefix = UserStringOption('prefix', 'This is needed by OptionStore', '/usr')
249+
optstore.add_system_option('prefix', prefix)
250+
o = UserBooleanOption(name, 'Tests', False)
251+
optstore.add_project_option(OptionKey(name, subproject=''), o)
252+
o = UserBooleanOption(name, 'Tests', True)
253+
optstore.add_project_option(OptionKey(name, subproject=subp), o)
254+
255+
cmd_line = {OptionKey(name): True}
256+
spcall = {OptionKey(name): False}
257+
258+
optstore.initialize_from_top_level_project_call({}, cmd_line, {})
259+
optstore.initialize_from_subproject_call(subp, spcall, {}, cmd_line, {})
260+
self.assertEqual(optstore.get_value_for(name, ''), True)
261+
self.assertEqual(optstore.get_value_for(name, subp), False)
262+
243263
def test_subproject_cmdline_override_global(self):
244264
name = 'optimization'
245265
subp = 'subp'

0 commit comments

Comments
 (0)