summaryrefslogtreecommitdiff
path: root/mesonbuild/ast/interpreter.py
AgeCommit message (Collapse)Author
2025-12-08interpreterbase: make ArithmeticNode and MesonOperator both use operator namesPaolo Bonzini
This avoids creating a dictionary every time an arithmetic operator is evaluated. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-08make ctype the same as the printed ASTPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-11-21rewrite: fix duplicate objects for predefined globalsPaolo Bonzini
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>
2025-10-15revert local_program()Eli Schwartz
This reverts https://github.com/mesonbuild/meson/pull/15107 Explicit objections regarding the design were raised and not answered, so it shouldn't have been merged. It needs to be discussed and revisited.
2025-10-15Add local_program() functionXavier Claessens
2025-09-25mypy: enable allow-redefinition-new and fix falloutEli Schwartz
Reduces 3 errors that show up in newer mypy versions than pinned in CI. It is new since 1.16 and a likely future default for mypy 2.0. It allows things like: ``` for i in ['one', 'two', 'three']: frob_a(i) for i in [1, 2, 3]: frob_b(i) ``` since "i" is obviously used as a loop holder and its type can be freely reinvented. Note: allow-redefinition-new isn't actually about this at all, it has greater scope than loop holders and allows redefining "unannotated variables" of all kinds. No granularity in what to accept redefinition of. :P To enable this, we must also opt in to local-partial-types, which has some overlap with None-safety. Specifically: > the most common cases for partial types are variables initialized > using None, but without explicit X | None annotations. By default, mypy > won’t check partial types spanning module top level or class top level. > This flag changes the behavior to only allow partial types at local > level, therefore it disallows inferring variable type for None from two > assignments in different scopes. So with this, we also fix a couple of actual type errors this revealed. Where possible, stop None-initializing at all -- it's not strictly needed for global variables, anyway, and it's a coding error if it is possible to hit these variables without defining them first. Bug: https://github.com/python/mypy/issues/19280
2025-09-24ast/introspection: remove keyword arguments from build targets that are ↵Dylan Baker
UnknownValue It is not the build layer's job to handle ast types, so instead filter out UnknownValues before passing them to the build layer, then fix up any special values we need in the ast layer. This reveals that some of what we were previously doing only works because the build layer is pretty much untyped, if it was typed it would have screamed loudly.
2025-08-10rewriter: Accept UnknownValue() in more placesVolker Weißmann
Fixes #14840
2025-06-09AstInterpreter: Fix dead-code-crashVolker Weißmann
Without this commit, the rewriter and the static introspection tool crash if `meson.build` contains something like ```meson if false foo = not_defined endif ``` or ```meson if false message(not_defined) endif ``` While it could be argued, that you should not write stuff like this, this used to raise a `MesonBugException`, which we have to fix. Fixes #14667
2025-05-29rewriter: Rewrite how we add/remove source filesVolker Weißmann
Change the semantics of IntrospectionBuildTarget.source_nodes and IntrospectionBuildTarget.extra_files . The rewriter and the static introspection tool used to be very broken, now it is *less* broken, hence we add some tests in this commit. Fixes #11763
2025-05-29rewriter: Improve find_target and find_dependencyVolker Weißmann
2025-05-29mesonbuild/ast: make mypy safeVolker Weißmann
2025-05-29Add AstInterpreter.funcvalsVolker Weißmann
`AstInterpreter.node_to_runtime_value` can now resolve function calls.
2025-05-29AstInterpreter: Replace resolve_node with node_to_runtime_valueVolker Weißmann
`resolve_node` is simply a half-broken, worse implementation of `node_to_runtime_value` that we recently introduced. In the example below, the static introspection tool/rewriter now understands that the name of the executable is foo instead of bar: ``` var = 'foo' name = var var = 'bar' executable(name, 'foo.c') ```
2025-05-29Add AstInterpreter.dataflow_dagVolker Weißmann
Make the AstInterpreter create a directed acyclic graph (called `dataflow_dag`) that stores the how the data flowes from one node in the AST to another. Add `AstInterpreter.node_to_runtime_value` which uses `dataflow_dag` to find what value a variable at runtime will have. We don't use dataflow_dag or node_to_runtime_value anywhere yet, but it will prove useful in future commits.
2025-05-29AstInterpreter: Fix evaluate_* functionsVolker Weißmann
Some of the evaluate_* functions in AstInterpreter seem very broken and do not even evaluate all of the AST. I do not know what the original author thought, so I just fixed it.
2025-05-29rewriter: Refactoring of assignment trackingVolker Weißmann
Replace `AstInterpreter.reverse_assignment` with `AstInterpreter.all_assignment_nodes`. This does not give us an immediate advantage but will be useful in future commits.
2025-05-29rewriter: Replace assignments with cur_assignmentsVolker Weißmann
Replace the variable tracking of `AstInterpreter.assignments` with a slightly better variable tracking called `AstInterpreter.cur_assignments`. We now have a class `UnknownValue` for more explicit handling of situations that are too complex/impossible.
2025-05-29Add AstInterpreter.nestingVolker Weißmann
The AstInterpreter now stores how deep into if/elif/else we are. This is currently dead code, but it will be read in future commits.
2025-05-29rewriter.py: make type safeVolker Weißmann
2025-05-29rewriter: Add IntrospectionDependencyVolker Weißmann
To improve type-safety and readability we replace a dictionary with a new class `IntrospectionDependency`.
2025-05-29rewriter: Add IntrospectionBuildTargetVolker Weißmann
To improve type-safety and readability we replace a dictionary with a new class `IntrospectionBuildTarget`.
2025-05-29Refactoring and removal of dead codeVolker Weißmann
2025-03-14Move variables to InterpreterBaseCharles Brunet
subproject_dir, environment, and coredata
2025-03-14Extract common func_subdir functions to InterpreterBaseCharles Brunet
2025-03-14Move flatten_kwargs to IntrospectionInterpreterCharles Brunet
It is not used elsewhere
2024-07-30flake8: move unused typing-only imports to TYPE_CHECKINGEli Schwartz
2024-04-28catch build files that cannot be opened in utf8 mode and emit useful errorEli Schwartz
Previously, if a junked meson.build or native.ini was used we got a lengthy traceback ending in UnicodeDecodeError. Fixes: #13154 Fixes: #13156
2024-04-08parser: revert to single StringNode typeCharles Brunet
this will allow transforming string types in the formater
2024-01-08ast/interpreter: fix some low hanging type issuesDylan Baker
2024-01-08ast/introspection: make mypy cleanDylan Baker
2023-12-13Use SPDX-License-Identifier consistentlyDylan Baker
This replaces all of the Apache blurbs at the start of each file with an `# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing uses to be consistent in capitalization, and to be placed above any copyright notices. This removes nearly 3000 lines of boilerplate from the project (only python files), which no developer cares to look at. SPDX is in common use, particularly in the Linux kernel, and is the recommended format for Meson's own `project(license: )` field
2023-09-13Allow unit test to parse testcase blocksCharles Brunet
When a unittest introspect a meson.build file from a test case, the file may contain a testcase block. We should ignore this block.
2023-09-11ast: fully resolve nodes for add operationCharles Brunet
Otherwise, string + stringmethod results in a list of two strings instead of the concatenation of the strings
2023-09-11parser: add ElseNodeCharles Brunet
2023-09-11parser: use IdNode for function name and assignment nameCharles Brunet
2023-09-11parser: preserve escape chars in stringsCharles Brunet
use separate Node for multiline strings
2023-09-07syntax-highlighting: vim: update builtin function listLiam Beguin
Update builtin function list using the refman python docs/genrefman.py \ -g vim \ -o data/syntax-highlighting/vim/syntax/ This also drops gettext() and find_library() from the list of builtin functions that have been deprecated since 2016. Changes are squashed here because test_vim_syntax_highlighting() would validate the file against the list of builtin functions that no longer matches the yaml documentation. Signed-off-by: Liam Beguin <liambeguin@gmail.com>
2023-08-11treewide: automatic rewriting of all comment-style type annotationsEli Schwartz
Performed using https://github.com/ilevkivskyi/com2ann This has no actual effect on the codebase as type checkers (still) support both and negligible effect on runtime performance since __future__ annotations ameliorates that. Technically, the bytecode would be bigger for non function-local annotations, of which we have many either way. So if it doesn't really matter, why do a large-scale refactor? Simple: because people keep wanting to, but it's getting nickle-and-dimed. If we're going to do this we might as well do it consistently in one shot, using tooling that guarantees repeatability and correctness. Repeat with: ``` com2ann mesonbuild/ ```
2023-04-11fix various spelling issuesJosh Soref
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-10-03pylint: enable unnecessary-comprehensionDylan Baker
2022-07-03move various unused typing-only imports into type-checking blocksEli Schwartz
2022-07-03sort imports for neatnessEli Schwartz
2022-05-03interpreter: new function add_project_dependencies()Paolo Bonzini
This function can be used to add fundamental dependencies such as glib to all build products in one fell swoop. This can be useful whenever, due to a project's coding conventions, it is not really possible to compile any source file without including the dependency. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2022-03-30Add new debug() functionMarvin Scholz
Adds a new debug() function that can be used in the meson.build to log messages to the meson-log.txt that will not be printed to stdout when configuring the project.
2022-03-13Merge pull request #9339 from dcbaker/submit/structured_sourcesJussi Pakkanen
Structured Sources
2022-03-07treewide: string-quote the first argument to T.castEli Schwartz
Using future annotations, type annotations become strings at runtime and don't impact performance. This is not possible to do with T.cast though, because it is a function argument instead of an annotation. Quote the type argument everywhere in order to have the same effect as future annotations. This also allows linters to better detect in some cases that a given import is typing-only.
2022-03-07interpreter: add an implementation for structured_sourcesDylan Baker
2021-12-01add install_symlink functionPablo Correa Gómez
Allows installing symlinks directly from meson, which can become useful in multiple scenarios. Current main use is to help moving forward #9557
2021-10-08add install_emptydir functionEli Schwartz
This replaces the absolute hack of using ``` install_subdir('nonexisting', install_dir: 'share') ``` which requires you to make sure you don't accidentally or deliberately have a completely different directory with the same name in your source tree that is full of files you don't want installed. It also avoids splitting the name in two and listing them in the wrong order. You can also set the install mode of each directory component by listing them one at a time in order, and in fact create nested structures at all. Fixes #1604 Properly fixes #2904