Skip to content

Commit 4b33c9c

Browse files
Volker-Weissmannjpakkane
authored andcommitted
rewriter: Accept UnknownValue() in more places
Fixes #14840
1 parent f2c851b commit 4b33c9c

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

mesonbuild/ast/interpreter.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,11 @@ def func_set_variable(self, node: BaseNode, args: T.List[TYPE_var], kwargs: T.Di
692692
def func_get_variable(self, node: BaseNode, args: T.List[TYPE_var], kwargs: T.Dict[str, TYPE_var]) -> T.Any:
693693
assert isinstance(node, FunctionNode)
694694
var_name = args[0]
695-
assert isinstance(var_name, str)
696-
val = self.get_cur_value(var_name)
695+
if isinstance(var_name, UnknownValue):
696+
val: T.Union[UnknownValue, BaseNode] = UnknownValue()
697+
else:
698+
assert isinstance(var_name, str)
699+
val = self.get_cur_value(var_name)
697700
self.dataflow_dag.add_edge(val, node)
698701
return val
699702

mesonbuild/ast/introspection.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,11 @@ def func_dependency(self, node: BaseNode, args: T.List[TYPE_var], kwargs: T.Dict
203203
has_fallback = 'fallback' in kwargs
204204
required = kwargs.get('required', True)
205205
version = kwargs.get('version', [])
206-
if not isinstance(version, UnknownValue):
207-
if not isinstance(version, list):
208-
version = [version]
206+
if not isinstance(version, list):
207+
version = [version]
208+
if any(isinstance(el, UnknownValue) for el in version):
209+
version = UnknownValue()
210+
else:
209211
assert all(isinstance(el, str) for el in version)
210212
version = T.cast(T.List[str], version)
211213
assert isinstance(required, (bool, UnknownValue))

test cases/unit/56 introspection/meson.build

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ test('test case 1', t1)
5858
test('test case 2', t2, depends: t3)
5959
benchmark('benchmark 1', t3, args: [cus1, cus2, cus3])
6060

61+
### BEGIN: Stuff to test the handling of `UnknownValue`
62+
var_1 = 1
63+
var_2 = 2
64+
unknown_var = 'var_1'
65+
if host_machine.system() == 'windows'
66+
unknown_var = 'var_2'
67+
endif
68+
# The IntrospectionInterpreter can't know the value of unknown_var and use the `UnknownValue` class.
69+
70+
message(get_variable(unknown_var))
71+
72+
dependency(unknown_var, version: [unknown_var], required: false)
73+
dependency(unknown_var, version: unknown_var, required: false)
74+
### END: Stuff to test the handling of `UnknownValue`
75+
6176
### Stuff to test the AST JSON printer
6277
foreach x : ['a', 'b', 'c']
6378
if x == 'a'

unittests/allplatformstests.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3834,7 +3834,21 @@ def test_introspect_dependencies_from_source(self):
38343834
'version': ['>=1.0.0', '<=99.9.9'],
38353835
'has_fallback': True,
38363836
'conditional': True
3837-
}
3837+
},
3838+
{
3839+
'conditional': False,
3840+
'has_fallback': False,
3841+
'name': 'unknown',
3842+
'required': False,
3843+
'version': 'unknown'
3844+
},
3845+
{
3846+
'conditional': False,
3847+
'has_fallback': False,
3848+
'name': 'unknown',
3849+
'required': False,
3850+
'version': 'unknown'
3851+
},
38383852
]
38393853
self.maxDiff = None
38403854
self.assertListEqual(res_nb, expected)

0 commit comments

Comments
 (0)