Skip to content

Commit 8389be0

Browse files
committed
Fix yielding when top project does not define the option.
Closes mesonbuild#14281.
1 parent 4386e2a commit 8389be0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

mesonbuild/options.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,13 @@ def get_value_object_for(self, key: 'T.Union[OptionKey, str]') -> AnyOptionType:
810810
assert key.subproject is not None
811811
if potential is not None and potential.yielding:
812812
parent_key = key.evolve(subproject='')
813-
parent_option = self.options[parent_key]
813+
try:
814+
parent_option = self.options[parent_key]
815+
except KeyError:
816+
# Subproject is set to yield, but top level
817+
# project does not have an option of the same
818+
# name. Return the subproject option.
819+
return potential
814820
# If parent object has different type, do not yield.
815821
# This should probably be an error.
816822
if type(parent_option) is type(potential):

unittests/optiontests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ def test_project_yielding(self):
100100
self.assertEqual(optstore.get_value_for(name, 'sub'), top_value)
101101
self.assertEqual(optstore.num_options(), 2)
102102

103+
def test_project_yielding_not_defined_in_top_project(self):
104+
optstore = OptionStore(False)
105+
top_name = 'a_name'
106+
top_value = 'top'
107+
sub_name = 'different_name'
108+
sub_value = 'sub'
109+
vo = UserStringOption(top_name, 'A top level option', top_value)
110+
optstore.add_project_option(OptionKey(top_name, ''), vo)
111+
self.assertEqual(optstore.get_value_for(top_name, ''), top_value)
112+
self.assertEqual(optstore.num_options(), 1)
113+
vo2 = UserStringOption(sub_name, 'A subproject option', sub_value, True)
114+
optstore.add_project_option(OptionKey(sub_name, 'sub'), vo2)
115+
self.assertEqual(optstore.get_value_for(top_name, ''), top_value)
116+
self.assertEqual(optstore.get_value_for(sub_name, 'sub'), sub_value)
117+
self.assertEqual(optstore.num_options(), 2)
118+
103119
def test_augments(self):
104120
optstore = OptionStore(False)
105121
name = 'cpp_std'

0 commit comments

Comments
 (0)