Skip to content

Commit f5aa3c7

Browse files
bonzinieli-schwartz
authored andcommitted
options: process project options before machine options
Restore the behavior from before commit d37d649 ("Make all Meson level options overridable per subproject.", 2025-02-13). The old code was: options: T.MutableMapping[OptionKey, T.Any] = OrderedDict() # process project default options for k, v in default_options.items(): if not subproject or k.subproject == subproject: options[k] = v # override them with machine default and command line options options.update(env.options) env.options = options Fixes: #14608 Signed-off-by: Paolo Bonzini <[email protected]> (cherry picked from commit 82fca50) # Conflicts: # mesonbuild/options.py
1 parent 15d3bdb commit f5aa3c7

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

mesonbuild/options.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,28 +1310,6 @@ def initialize_from_top_level_project_call(self,
13101310
project_default_options = self.optlist2optdict(project_default_options) # type: ignore [assignment]
13111311
if project_default_options is None:
13121312
project_default_options = {}
1313-
assert isinstance(machine_file_options, dict)
1314-
for keystr, valstr in machine_file_options.items():
1315-
if isinstance(keystr, str):
1316-
# FIXME, standardise on Key or string.
1317-
key = OptionKey.from_string(keystr)
1318-
else:
1319-
key = keystr
1320-
# Due to backwards compatibility we ignore all build-machine options
1321-
# when building natively.
1322-
if not self.is_cross and key.is_for_build():
1323-
continue
1324-
if key.subproject:
1325-
augstr = str(key)
1326-
self.augments[augstr] = valstr
1327-
elif key in self.options:
1328-
self.set_option(key, valstr, first_invocation)
1329-
else:
1330-
proj_key = key.as_root()
1331-
if proj_key in self.options:
1332-
self.set_option(proj_key, valstr, first_invocation)
1333-
else:
1334-
self.pending_options[key] = valstr
13351313
assert isinstance(project_default_options, dict)
13361314
for keystr, valstr in project_default_options.items():
13371315
# Ths is complicated by the fact that a string can have two meanings:
@@ -1368,6 +1346,28 @@ def initialize_from_top_level_project_call(self,
13681346
self.set_option(proj_key, valstr)
13691347
else:
13701348
self.pending_options[key] = valstr
1349+
assert isinstance(machine_file_options, dict)
1350+
for keystr, valstr in machine_file_options.items():
1351+
if isinstance(keystr, str):
1352+
# FIXME, standardise on Key or string.
1353+
key = OptionKey.from_string(keystr)
1354+
else:
1355+
key = keystr
1356+
# Due to backwards compatibility we ignore all build-machine options
1357+
# when building natively.
1358+
if not self.is_cross and key.is_for_build():
1359+
continue
1360+
if key.subproject:
1361+
augstr = str(key)
1362+
self.augments[augstr] = valstr
1363+
elif key in self.options:
1364+
self.set_option(key, valstr, first_invocation)
1365+
else:
1366+
proj_key = key.as_root()
1367+
if proj_key in self.options:
1368+
self.set_option(proj_key, valstr, first_invocation)
1369+
else:
1370+
self.pending_options[key] = valstr
13711371
assert isinstance(cmd_line_options, dict)
13721372
for keystr, valstr in cmd_line_options.items():
13731373
if isinstance(keystr, str):

unittests/optiontests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ def test_toplevel_project(self):
3535
optstore.initialize_from_top_level_project_call({OptionKey('someoption'): new_value}, {}, {})
3636
self.assertEqual(optstore.get_value_for(k), new_value)
3737

38+
def test_machine_vs_project(self):
39+
optstore = OptionStore(False)
40+
name = 'backend'
41+
default_value = 'ninja'
42+
proj_value = 'xcode'
43+
mfile_value = 'vs2010'
44+
k = OptionKey(name)
45+
prefix = UserStringOption('prefix', 'This is needed by OptionStore', '/usr')
46+
optstore.add_system_option('prefix', prefix)
47+
vo = UserStringOption(k.name, 'You know what this is', default_value)
48+
optstore.add_system_option(k.name, vo)
49+
self.assertEqual(optstore.get_value_for(k), default_value)
50+
optstore.initialize_from_top_level_project_call({OptionKey(name): proj_value}, {},
51+
{OptionKey(name): mfile_value})
52+
self.assertEqual(optstore.get_value_for(k), mfile_value)
53+
3854
def test_subproject_system_option(self):
3955
"""Test that subproject system options get their default value from the global
4056
option (e.g. "sub:b_lto" can be initialized from "b_lto")."""

0 commit comments

Comments
 (0)