diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-11-19 19:50:28 +0100 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-11-21 11:21:21 -0800 |
| commit | 03a09266b59dabe437b1b8a3927adf266ce65890 (patch) | |
| tree | fcea1d963ff026d1149f62f75e48f3f1e41e1490 | |
| parent | e38b2e83e64391790397dc71f6e27d57385fe767 (diff) | |
| download | meson-03a09266b59dabe437b1b8a3927adf266ce65890.tar.gz | |
rewrite: fix duplicate objects for predefined globals
Global objects are treated as UnknownValue(), but unlike other variables
their object is created on every call to get_cur_value_if_defined()
instead of coming from a dictionary. This causes the dataflow DAG
to have multiple objects from the same object. Fix this by building
the UnknownValues at interpreter construction time.
Fixes: #15261
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
| -rw-r--r-- | mesonbuild/ast/interpreter.py | 10 | ||||
| -rw-r--r-- | test cases/rewrite/10 duplicate globals/info.json | 8 | ||||
| -rw-r--r-- | test cases/rewrite/10 duplicate globals/meson.build | 5 | ||||
| -rw-r--r-- | unittests/rewritetests.py | 10 |
4 files changed, 31 insertions, 2 deletions
diff --git a/mesonbuild/ast/interpreter.py b/mesonbuild/ast/interpreter.py index 2f82a4a84..8a7386a4f 100644 --- a/mesonbuild/ast/interpreter.py +++ b/mesonbuild/ast/interpreter.py @@ -188,6 +188,12 @@ class AstInterpreter(InterpreterBase): self.dataflow_dag = DataflowDAG() self.funcvals: T.Dict[BaseNode, T.Any] = {} self.tainted = False + self.predefined_vars = { + 'meson': UnknownValue(), + 'host_machine': UnknownValue(), + 'build_machine': UnknownValue(), + 'target_machine': UnknownValue() + } self.funcs.update({'project': self.func_do_nothing, 'test': self.func_do_nothing, 'benchmark': self.func_do_nothing, @@ -486,8 +492,8 @@ class AstInterpreter(InterpreterBase): return ret def get_cur_value_if_defined(self, var_name: str) -> T.Union[BaseNode, UnknownValue, UndefinedVariable]: - if var_name in {'meson', 'host_machine', 'build_machine', 'target_machine'}: - return UnknownValue() + if var_name in self.predefined_vars: + return self.predefined_vars[var_name] ret: T.Union[BaseNode, UnknownValue, UndefinedVariable] = UndefinedVariable() for nesting, value in reversed(self.cur_assignments[var_name]): if len(self.nesting) >= len(nesting) and self.nesting[:len(nesting)] == nesting: diff --git a/test cases/rewrite/10 duplicate globals/info.json b/test cases/rewrite/10 duplicate globals/info.json new file mode 100644 index 000000000..3d15f0403 --- /dev/null +++ b/test cases/rewrite/10 duplicate globals/info.json @@ -0,0 +1,8 @@ +[ + { + "type": "kwargs", + "function": "project", + "id": "/", + "operation": "info" + } +] diff --git a/test cases/rewrite/10 duplicate globals/meson.build b/test cases/rewrite/10 duplicate globals/meson.build new file mode 100644 index 000000000..a9ebf969c --- /dev/null +++ b/test cases/rewrite/10 duplicate globals/meson.build @@ -0,0 +1,5 @@ +project('a', 'c', license: 'MIT') +set_variable( + 'z', + '-Wl,--version-script,@0@/src/lib.sym'.format(meson.current_source_dir()) +) diff --git a/unittests/rewritetests.py b/unittests/rewritetests.py index 84a6baf56..f2af8f64a 100644 --- a/unittests/rewritetests.py +++ b/unittests/rewritetests.py @@ -445,6 +445,16 @@ class RewriterTests(BasePlatformTests): out = self.rewrite(self.builddir, os.path.join(self.builddir, 'info.json')) self.assertEqualIgnoreOrder(out, expected) + def test_duplicate_globals(self): + self.prime('10 duplicate globals') + out = self.rewrite(self.builddir, os.path.join(self.builddir, 'info.json')) + expected = { + 'kwargs': { + 'project#/': {'license': 'MIT'} + } + } + self.assertEqualIgnoreOrder(out, expected) + def test_tricky_dataflow(self): self.prime('8 tricky dataflow') out = self.rewrite(self.builddir, os.path.join(self.builddir, 'addSrc.json')) |
