aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Weißmann <volker.weissmann@gmx.de>2025-07-31 16:52:35 +0200
committerJussi Pakkanen <jussi.pakkanen@mailbox.org>2025-08-10 20:26:58 +0300
commit4b33c9cdb64f360c2ee19691baedfa4d0e32378f (patch)
tree672ce415e6a099d683d97b90b5c61bc04165dd6b
parentf2c851b6f0452cad8bbbc5838c9a0f91aecdf593 (diff)
downloadmeson-4b33c9cdb64f360c2ee19691baedfa4d0e32378f.zip
meson-4b33c9cdb64f360c2ee19691baedfa4d0e32378f.tar.gz
meson-4b33c9cdb64f360c2ee19691baedfa4d0e32378f.tar.bz2
rewriter: Accept UnknownValue() in more places
Fixes #14840
-rw-r--r--mesonbuild/ast/interpreter.py7
-rw-r--r--mesonbuild/ast/introspection.py8
-rw-r--r--test cases/unit/56 introspection/meson.build15
-rw-r--r--unittests/allplatformstests.py16
4 files changed, 40 insertions, 6 deletions
diff --git a/mesonbuild/ast/interpreter.py b/mesonbuild/ast/interpreter.py
index 62c4839..86b6442 100644
--- a/mesonbuild/ast/interpreter.py
+++ b/mesonbuild/ast/interpreter.py
@@ -692,8 +692,11 @@ class AstInterpreter(InterpreterBase):
def func_get_variable(self, node: BaseNode, args: T.List[TYPE_var], kwargs: T.Dict[str, TYPE_var]) -> T.Any:
assert isinstance(node, FunctionNode)
var_name = args[0]
- assert isinstance(var_name, str)
- val = self.get_cur_value(var_name)
+ if isinstance(var_name, UnknownValue):
+ val: T.Union[UnknownValue, BaseNode] = UnknownValue()
+ else:
+ assert isinstance(var_name, str)
+ val = self.get_cur_value(var_name)
self.dataflow_dag.add_edge(val, node)
return val
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py
index decce4b..6ffc6ad 100644
--- a/mesonbuild/ast/introspection.py
+++ b/mesonbuild/ast/introspection.py
@@ -203,9 +203,11 @@ class IntrospectionInterpreter(AstInterpreter):
has_fallback = 'fallback' in kwargs
required = kwargs.get('required', True)
version = kwargs.get('version', [])
- if not isinstance(version, UnknownValue):
- if not isinstance(version, list):
- version = [version]
+ if not isinstance(version, list):
+ version = [version]
+ if any(isinstance(el, UnknownValue) for el in version):
+ version = UnknownValue()
+ else:
assert all(isinstance(el, str) for el in version)
version = T.cast(T.List[str], version)
assert isinstance(required, (bool, UnknownValue))
diff --git a/test cases/unit/56 introspection/meson.build b/test cases/unit/56 introspection/meson.build
index 568d5cc..c7856fe 100644
--- a/test cases/unit/56 introspection/meson.build
+++ b/test cases/unit/56 introspection/meson.build
@@ -58,6 +58,21 @@ test('test case 1', t1)
test('test case 2', t2, depends: t3)
benchmark('benchmark 1', t3, args: [cus1, cus2, cus3])
+### BEGIN: Stuff to test the handling of `UnknownValue`
+var_1 = 1
+var_2 = 2
+unknown_var = 'var_1'
+if host_machine.system() == 'windows'
+ unknown_var = 'var_2'
+endif
+# The IntrospectionInterpreter can't know the value of unknown_var and use the `UnknownValue` class.
+
+message(get_variable(unknown_var))
+
+dependency(unknown_var, version: [unknown_var], required: false)
+dependency(unknown_var, version: unknown_var, required: false)
+### END: Stuff to test the handling of `UnknownValue`
+
### Stuff to test the AST JSON printer
foreach x : ['a', 'b', 'c']
if x == 'a'
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index f158be7..04cbfc6 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -3834,7 +3834,21 @@ class AllPlatformTests(BasePlatformTests):
'version': ['>=1.0.0', '<=99.9.9'],
'has_fallback': True,
'conditional': True
- }
+ },
+ {
+ 'conditional': False,
+ 'has_fallback': False,
+ 'name': 'unknown',
+ 'required': False,
+ 'version': 'unknown'
+ },
+ {
+ 'conditional': False,
+ 'has_fallback': False,
+ 'name': 'unknown',
+ 'required': False,
+ 'version': 'unknown'
+ },
]
self.maxDiff = None
self.assertListEqual(res_nb, expected)