summaryrefslogtreecommitdiff
path: root/mesonbuild/ast
AgeCommit message (Collapse)Author
2025-12-22ast: printer: give a precedence to all kinds of functionsPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
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-15build: Add a TypedDict for BuildTarget keyword argumentsDylan Baker
This has the "processed" keyword arguments that the interpreter is supposed to create for us, or that we expect internal users to build by build. This requires some hacking around in the rust module for the moment because we suddenly have a type.
2025-10-15Add local_program() functionXavier Claessens
2025-10-06interpreter: unify and specialize code to set backend optionsPaolo Bonzini
Avoid different but equivalent code between ast and regular interpreter, and avoid using coredata.set_options since all options are known to be backend options. Move to environment since it uses environment.options. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-06introspection: remove dead codePaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
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-07-07ast, interpreter: look up default_library and default_both_libraries by ↵Paolo Bonzini
subproject This is already done most of the time for default_library but not in these cases. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
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-29rewriter: Remove apparently useless code.Volker Weißmann
Without this commit, something like this crashes the static introspection/rewrite tool: ``` default_options : ['warning_level=' + run_command(['echo', '3']).stdout().strip()], ``` This commit does not reintroduce #14382.
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-05-29AstPrinter: Add parenthesis where neccessaryVolker Weißmann
2025-05-29AstPrinter: Use str.translate instead of str.replaceVolker Weißmann
2025-05-29rewriter: Don't ignore the `name_prefix` kwargVolker Weißmann
2025-05-15coredata: remove unused argumentsPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-15introspection: do not reinvent process_compiler_optionsPaolo Bonzini
Let add_compiler_options and process_compiler_options handle subprojects, and also run it for the main project to ensure that pending_options are properly processed. This exposes a bug because "comp" could have been None, so fix that. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-07options: support non-string data types in more placesPaolo Bonzini
Allow OptionStringLikeDict to use non-string data types, and use it as much as possible instead of string-valued dictionaries. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-07ast: clean up handling of default optionsPaolo Bonzini
Do not go through string first and OptionKey second. Just pass the OptionKeys down. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-08coredata: delete set_default_optionsDylan Baker
This was only being used by the introspection interpreter, which meant the two interpreters had different behavior. They still do, which is really bad because the IntrospectionInterpreter doesn't have the command line options or project_default_options. I have a plan to fix that later, and I don't want to spend time on it here, as it's not a regression of this patch, it's just the status quo. This also fixes an issue caused by dead code being left, and hit, due to the option refactor branch. Fixes: #14382
2025-03-14Move options loading to InterpreterBaseCharles Brunet
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
2025-03-10coredata: replace get_option with optstore.get_value_forDylan Baker
This is an old method, that is now just a wrapper around the OptionStore method, that doesn't add any value. It's also an option related method attached to the CoreData instead of the OptionStore, so useless and a layering violation.
2025-02-13Make all Meson level options overridable per subproject.Jussi Pakkanen
2024-12-19introspect: add machine to target_sourcesPaolo Bonzini
Even though the "targets" introspection info already includes the command line arguments used to invoke the compiler, this is not enough to correlated with the "compilers" introspection info and get extra information from there. Together with the existing "language" key, adding a "machine" key is enough to identify completely an entry in the compilers info. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-11-15ast/introspection: Drop duplicate None checkDylan Baker
The AstInterpreter does this check as well, so don't do it twice.
2024-10-13mintro: Add license and license_files to project introspection dataDaniele Nicolodi
2024-07-30flake8: move unused typing-only imports to TYPE_CHECKINGEli Schwartz
2024-07-11Move OptionKey in the option source file.Jussi Pakkanen
2024-07-11Move backend option check into OptionStore.Jussi Pakkanen
2024-07-11Move project option detection into OptionStore.Jussi Pakkanen