summaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase
AgeCommit message (Collapse)Author
2025-12-17interpreterbase: Add a new field to KwargInfo for extra typesDylan Baker
We have some cases where we want to have an extra set of validators that run on specific types, and give detailed answers. However, we don't want those types to show up in the list of accepted types. This new keyword allows for that.
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-10-29replace "in d.keys()" with "in d"Paolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-20interpreter: Fix extract_object subproject validationXavier Claessens
Fixes: #12519
2025-10-17cargo: Allow a cargo subproject to subdir() into another cargo projectXavier Claessens
Cargo workspaces will use this to have a single subproject defining multiple crates.
2025-10-15Revert "typed_kwargs: Remove feature_validator as it's not currently used"Dylan Baker
This reverts commit 93c11f249495c4af4a88206cebefef3ecf0f3228. We're going to use it again in the next commit
2025-06-17interpreterbase: remove per-object method dispatchingPaolo Bonzini
Only support class-based dispatch, all objects have been converted.
2025-06-17interpreter: make methods per-class for primitivesPaolo Bonzini
Do not call update() and Enum.__hash__ a gazillion times; operators are the same for every instance of the class. In order to access the class, just mark the methods using a decorator and build METHODS later using __init_subclass__. Non-primitive objects are not converted yet to keep the patch small. They are created a lot less than other objects, especially strings and booleans. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-17interpreter: make operators per-classPaolo Bonzini
Do not call update() and Enum.__hash__ a gazillion times; operators are the same for every instance of the class. In order to access the class for non-trivial operators, the operators are first marked using a decorator, and then OPERATORS is built via __init_subclass__. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-17interpreter: make trivial_operators per-classPaolo Bonzini
Do not call update() and Enum.__hash__ a gazillion times; trivial operators are the same for every instance of the class. Introduce the infrastructure to build the MRO-resolved operators (so the outcome same as if one called super().__init__) for each subclass of InterpreterObject. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-17interpreter: make operator functions binaryPaolo Bonzini
In preparation for moving them to the class, make the operator functions binary. Adjust the lambdas for trivial operators, and store unbound methods for non-trivial ones. Note that this requires adding operators manually for every override, even subclasses. It's decidedly ugly at this temporary stage; later it will result in just an extra @InterpreterObject.operator decorator on the subclasses. 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: 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-07interpreterbase: allow any return type for convertorsPaolo Bonzini
A convertor will *accept* something that is definitely a TYPE_var; but the output can be any Python object that the evaluation function desires. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-08coredata: move update_project_options to the optstoreDylan Baker
2025-03-14Move Interpreter.read_buildfile to base classCharles Brunet
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-01-21Revert "interpreterbase: Add disabler exception for `get_variable` method"Jussi Pakkanen
This reverts commit 82fedf04033305e2b28db1eea2346018c237d167.
2025-01-19interpreterbase: Add disabler exception for `get_variable` methodAndrew McNulty
Add an exception to the disabler check to allow objects with a `get_variable` method to not always pick a disabler if their arguments contain one. This mimics the behaviour already in place for calls to function, which has a set of excepted functions. Closes #13717 Signed-off-by: Andrew McNulty <amcn102@gmail.com>
2025-01-08optimize variable assignmentsPaolo Bonzini
Except for set_variable(), the variable name is certainly an identifier because it comes from the parser; thus, the check is unnecessary. Move the regular expression match to func_set_variable(). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-11-15interpreter: remove current_linenoDylan Baker
This was only used in a couple of places, and requires extra tracking to ensure it is correct, while we already have `current_node.lineno`, which is always accurate and up to date. I have also fixed a potential strict-null issue by using a sentinel node for `current_node`
2024-10-01interpreterbase/decorators: delete now unused stringArgsDylan Baker
2024-09-08interpreterbase: Use explicit `TypeAlias` annotation to allow recursive typesDylan Baker
And fix all of the issues that pop up once we remove the use of `Any`, which hides so many problems.
2024-08-30Feature checks: fall back to reporting insufficiently portable featuresEli Schwartz
When projects do not specify a minimum meson version, we used to avoid giving them the benefit of the Feature checks framework. Instead: - warn for features that were added after the most recent semver bump, since they aren't portable to the range of versions people might use these days - warn for features that were deprecated before the upcoming semver bump, i.e. all deprecated features, since they aren't portable to upcoming semver-compatible versions people might be imminently upgrading to
2024-07-05Revert "Clarify mutable objects usage"Eli Schwartz
This reverts commit 9f02d0a3e5a5ffc82256391c244b1af38e41ef78. It turns out that this does introduce a behavioral change in existing users of ConfigurationData, which it wasn't supposed to (it was supposed to preserve behavior there, and add a new *warning* for EnvironmentVariables). This breaks projects such as pulseaudio, libvirt, and probably more. Roll back the change and try again after 1.5.0 is released. Fixes: #13372
2024-05-23Refactor option classes to their own file.Jussi Pakkanen
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-14Clarify mutable objects usageXavier Claessens
Only Environment and ConfigurationData are mutable. However, only ConfigurationData becomes immutable after first use which is inconsistent. This deprecates modification after first use of Environment object and clarify documentation.
2024-04-08parser: revert to single StringNode typeCharles Brunet
this will allow transforming string types in the formater
2024-02-23Detect utf8 bom from meson build filesCharles Brunet
Some text editors on Windows may use utf8bom encoding by default. Prevent crash and properly report misencoded files. Fixes #12766.
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-11-04Fine-tune the error message when trying to build outside the project rootEli Schwartz
We try to backtrack through the filesystem to find the correct directory to build in, and suggest this as a possible diagnostic. However, our current heuristic relies on parsing the raw file with string matching to see if it starts with `project(`, and this may or may not actually work. Instead, do a bit of recursion and parse each candidate with mparser, then check if the first node of *that* file is a project() function. This makes us resilient to a common case: where the root meson.build is entirely valid, but, the first line is a comment containing e.g. SPDX license headers and a simple string comparison simply does not cut it. Fixes the bad error message from #12441, which was supposed to provide more guidance but did not.
2023-10-04Remove unused code in interpreterbaseTristan Partin
2023-09-11parser: simplify Assignment and PlusAssignment nodesCharles Brunet
2023-09-11parser: add ElseNodeCharles Brunet
2023-09-11parser: use IdNode for foreach varnamesCharles 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-11Add ParenthesizedNodeJCWasmx86
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-08-11remove useless type annotationsEli Schwartz
These annotations all had a default initializer of the correct type, or a parent class annotation.
2023-08-02Unify message(), format() and fstring formattingXavier Claessens
Share a common function to convert objects to display strings for consistency. While at it, also add support for formatting user options.
2023-07-31fix lint errors revealed by pycodestyle 2.11Eli Schwartz
When performing isinstance checks, an identity comparison is automatically done, but we don't use isinstance here because we need strict identity equality *without allowing subtypes*. Comparing type() == type() is a value comparison, but could produce effectively the same results as an identity comparison, usually, despite being semantically off. pycodestyle learned to detect this and warn you to do strict identity comparison.
2023-07-24force interpreter functions to actually receive tuple from typed posargsEli Schwartz
We always expect the args parameter in the wrapped function to eventually receive a tuple due to reasons. But in one specific optargs condition we passed it along without any fixup at all.
2023-07-19move various bits of type-checking only code to TYPE_CHECKING blocksEli Schwartz
Mostly detected with flake8-type-checking. Also quote T.cast() first arguments, since those are not affected by future annotations.
2023-07-19fix implicit_reexport issues and enforce them going forwardEli Schwartz
This detects cases where module A imports a function from B, and C imports that same function from A instead of B. It's not part of the API contract of A, and causes innocent refactoring to break things.
2023-06-14remove unnecessary typing commentsEli Schwartz
Although they could be moved to annotations, the truth is that they are unneeded because they get inherited from the parent class.