From a2111ccd2e9810ec146a8f3050983801db844a95 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 26 Aug 2025 10:09:17 +0200 Subject: options: put back in place 1.7 ordering of opt=value vs subp:opt=value Signed-off-by: Paolo Bonzini --- docs/markdown/Builtin-options.md | 4 ++-- mesonbuild/options.py | 16 ++++++++-------- unittests/machinefiletests.py | 13 +++---------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/docs/markdown/Builtin-options.md b/docs/markdown/Builtin-options.md index e52ba3f5d..27efbf2ae 100644 --- a/docs/markdown/Builtin-options.md +++ b/docs/markdown/Builtin-options.md @@ -384,10 +384,10 @@ command line: `-Dfoo:default_library=static`. The value is overridden in this order: - `opt=value` from parent project's `default_options` - `opt=value` from subproject's `default_options` -- `subp:opt=value` from parent project's default options -- `opt=value` from `subproject()` `default_options` - `opt=value` from machine file - `opt=value` from command line +- `subp:opt=value` from parent project's default options +- `opt=value` from `subproject()` `default_options` - `subp:opt=value` from machine file - `subp:opt=value` from command line diff --git a/mesonbuild/options.py b/mesonbuild/options.py index 1b2bfc64e..0ada8432c 100644 --- a/mesonbuild/options.py +++ b/mesonbuild/options.py @@ -1380,6 +1380,14 @@ class OptionStore: key = key.evolve(subproject=subproject) options[key] = valstr + # then global settings from machine file and command line + # **but not if they are toplevel project options** + for key, valstr in itertools.chain(machine_file_options.items(), cmd_line_options.items()): + if key.subproject is None and not self.is_project_option(key.as_root()): + subp_key = key.evolve(subproject=subproject) + # just leave in place the value that was set for the toplevel project + options.pop(subp_key, None) + # augments from the toplevel project() default_options for key, valstr in self.pending_subproject_options.items(): if key.subproject == subproject: @@ -1395,14 +1403,6 @@ class OptionStore: key = key.evolve(subproject=subproject) options[key] = valstr - # then global settings from machine file and command line - # **but not if they are toplevel project options** - for key, valstr in itertools.chain(machine_file_options.items(), cmd_line_options.items()): - if key.subproject is None and not self.is_project_option(key.as_root()): - subp_key = key.evolve(subproject=subproject) - self.pending_subproject_options.pop(subp_key, None) - options.pop(subp_key, None) - # then finally per project augments from machine file and command line for key, valstr in itertools.chain(machine_file_options.items(), cmd_line_options.items()): if key.subproject == subproject: diff --git a/unittests/machinefiletests.py b/unittests/machinefiletests.py index 7f88a54bf..15c0e5728 100644 --- a/unittests/machinefiletests.py +++ b/unittests/machinefiletests.py @@ -563,18 +563,11 @@ class NativeFileTests(BasePlatformTests): check = cm.exception.stdout self.assertIn(check, 'Parent should override default_library') - def test_builtin_options_machinefile_global_overrides_subproject(self): - # The buildfile says subproject(... default_library: static), ensure that's overridden + def test_builtin_options_machinefile_global_loses_over_subproject(self): + # The buildfile says subproject(... default_library: static), ensure that it overrides the machinefile testcase = os.path.join(self.common_test_dir, '223 persubproject options') config = self.helper_create_native_file({'built-in options': {'default_library': 'both'}}) - - with self.assertRaises((RuntimeError, subprocess.CalledProcessError)) as cm: - self.init(testcase, extra_args=['--native-file', config]) - if isinstance(cm, RuntimeError): - check = str(cm.exception) - else: - check = cm.exception.stdout - self.assertIn(check, 'Parent should override default_library') + self.init(testcase, extra_args=['--native-file', config]) def test_builtin_options_compiler_properties(self): # the properties section can have lang_args, and those need to be -- cgit v1.2.3