diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2025-02-22 14:40:08 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2025-02-22 14:40:08 +0200 |
commit | 1a7a326d12bf3d43245e8eb45d405da68440b9f5 (patch) | |
tree | a60c92c08f5de34371a7c70de618aec51442b7ad | |
parent | 4386e2afe17f8a399d7c202476261c760cdce1e3 (diff) | |
download | meson-fixyielding.zip meson-fixyielding.tar.gz meson-fixyielding.tar.bz2 |
Fix yielding when top project does not define the option.fixyielding
Closes #14281.
-rw-r--r-- | mesonbuild/options.py | 8 | ||||
-rw-r--r-- | unittests/optiontests.py | 16 |
2 files changed, 23 insertions, 1 deletions
diff --git a/mesonbuild/options.py b/mesonbuild/options.py index 838ccb7..8cad1d1 100644 --- a/mesonbuild/options.py +++ b/mesonbuild/options.py @@ -810,7 +810,13 @@ class OptionStore: assert key.subproject is not None if potential is not None and potential.yielding: parent_key = key.evolve(subproject='') - parent_option = self.options[parent_key] + try: + parent_option = self.options[parent_key] + except KeyError: + # Subproject is set to yield, but top level + # project does not have an option of the same + # name. Return the subproject option. + return potential # If parent object has different type, do not yield. # This should probably be an error. if type(parent_option) is type(potential): diff --git a/unittests/optiontests.py b/unittests/optiontests.py index bbf9c0e..94d52ae 100644 --- a/unittests/optiontests.py +++ b/unittests/optiontests.py @@ -100,6 +100,22 @@ class OptionTests(unittest.TestCase): self.assertEqual(optstore.get_value_for(name, 'sub'), top_value) self.assertEqual(optstore.num_options(), 2) + def test_project_yielding_not_defined_in_top_project(self): + optstore = OptionStore(False) + top_name = 'a_name' + top_value = 'top' + sub_name = 'different_name' + sub_value = 'sub' + vo = UserStringOption(top_name, 'A top level option', top_value) + optstore.add_project_option(OptionKey(top_name, ''), vo) + self.assertEqual(optstore.get_value_for(top_name, ''), top_value) + self.assertEqual(optstore.num_options(), 1) + vo2 = UserStringOption(sub_name, 'A subproject option', sub_value, True) + optstore.add_project_option(OptionKey(sub_name, 'sub'), vo2) + self.assertEqual(optstore.get_value_for(top_name, ''), top_value) + self.assertEqual(optstore.get_value_for(sub_name, 'sub'), sub_value) + self.assertEqual(optstore.num_options(), 2) + def test_augments(self): optstore = OptionStore(False) name = 'cpp_std' |