summaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase/interpreterbase.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-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-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-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-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-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-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-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-04-11fix various spelling issuesJosh Soref
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-04propagate the most accurate node to error messagesEli Schwartz
During evaluation of codeblocks, we start off with an iteration of nodes, and then while evaluating them we may update the global self.current_node context. When catching and formatting errors, we didn't take into account that the node might be updated from the original top-level iteration. Switch to formatting errors using self.current_node instead, to ensure we can point at the likely most-accurate actual cause of an error. Also update the current node in a few more places, so that function calls always see the function call as the current node, even if the most recently parsed node was an argument to the function call. Fixes #11643
2023-03-01handle meson_version after parsing but before invalid project() kwargsEli Schwartz
If we add new kwargs to a function invoked on the first line, we also need to validate the meson_version before erroring out due to unknown kwargs. Even if the AST was successfully built. Amusingly, we also get to improve the error message a bit. By passing the AST node instead of an interpreter node, we get not just line numbers, but also column offsets of the issueful meson_version. That broke the stdout of another failing test; adapt it.
2023-03-01handle meson_version even when the build file fails to parseEli Schwartz
If the meson.build file is sufficiently "broken", even attempting to lex and parse it will totally fail, and we error out without getting the opportunity to evalaute the project() function. This can fairly easily happen if we add new grammar to the syntax, which old versions of meson cannot understand. Setting a minimum meson_version doesn't help, because people with a too-old version of meson get parser errors instead of advice about upgrading meson. Examples of this include adding dict support to meson. There are two general approaches to solving this issue, one of which projects are empowered to do: - refactor the project to place too-new syntax in a subdir() loaded build file, so the root file can be interpreted - teach meson to catch errors in building the initial AST, and just load enough of the AST to check for meson_version advice This implements the latter, allowing to future-proof the build grammar.
2023-03-01interpreter: Add testcase..endtestcase clause supportXavier Claessens
This is currently only enabled when running unit tests to facilitate writing failing unit tests. Fixes: #11394
2023-02-27prevent unhandled exception for operations on NoneCharles Brunet
For instance, when writing `-subdir('a')` or `not subdir('a')`. Fixes #11225.
2023-02-01micro-optimize: define typing-only objects in TYPE_CHECKINGEli Schwartz
Union types that exist solely for use as annotations don't need to be created in normal runs.
2022-11-29pylint: enable useless-returnDylan Baker
2022-08-30fix obscure crash on unbound variableEli Schwartz
This can be triggered if someone tries to call a non-ID. The example reproducer was: ``` if (var = dependency(...)).found() ``` This produced a traceback ending in ``` raise InvalidArguments(f'Variable "{object_name}" is not callable.') UnboundLocalError: local variable 'object_name' referenced before assignment ``` After this commit, the error is reported as: ``` ERROR: AssignmentNode is not callable. ```
2022-05-01Add support for multiline f-stringsPeter Lesslie
+ Extend the parser to recognize the multiline f-strings, which the documentation already implies will work. The syntax is like: ``` x = 'hello' y = 'world' msg = f'''This is a multiline string. Sending a message: '@x@ @y@' ''' ``` which produces: ``` This is a multiline string. Sending a message: 'hello world' ``` + Added some f-string tests cases to "62 string arithmetic" to exercise the new behavior.
2022-03-07move a bunch of imports into TYPE_CHECKING blocksEli Schwartz
These are only used for type checking, so don't bother importing them at runtime. Generally add future annotations at the same time, to make sure that existing uses of these imports don't need to be quoted.
2022-02-16flake8: use plain strings instead of f-strings when no variables usedEli Schwartz
2022-02-14FeatureNew: add mypy type annotations for subproject argEli Schwartz
Use a derived type when passing `subproject` around, so that mypy knows it's actually a SubProject, not a str. This means that passing anything other than a handle to the interpreter state's subproject attribute becomes a type violation, specifically when the order of the *four* different str arguments is typoed.
2022-01-27flake8: fix indentation styleEli Schwartz
2021-11-01various manual conversion of percent-formatted strings to f-stringsEli Schwartz
2021-10-27Revert "mark a couple of typing-only imports as noqa, to appease pyflakes"Eli Schwartz
This reverts commit 6cc1b8441c0cf7428e52bdf1cd541ea830a4eb83. The latest version of pyflakes learned to detect that correctly.
2021-10-24interpreter: Fix missing featuer check (fixes #9425)Daniel Mensinger
2021-10-06interpreter: Holderify arrays and dictsDaniel Mensinger
This is the final refactoring for extracting the bultin object logic out of Interpreterbase. I decided to do both arrays and dicts in one go since splitting it would have been a lot more confusing.
2021-09-25Remove helpers.check_stringlist()Daniel Mensinger
2021-09-25interpreter: Introduce StringHolderDaniel Mensinger
Another commit in my quest to rid InterpreterBase from all higher level object processing logic. Additionally, there is a a logic change here, since `str.join` now uses varargs and can now accept more than one argument (and supports list flattening).
2021-09-14mark a couple of typing-only imports as noqa, to appease pyflakesEli Schwartz
Since it cannot resolve `import typing as T` in order to figure out that T.* is doing annotation-worthy stuff. Since T.cast('Foo') is not actually using Foo except in an annotation context (due to being a string) it requires extra work to resolve, and the only thing that would currently work is actually using 'typing.cast'. However, we have decided to not use it except as T... Since this import is only imported during mypy it's not so bad to noqa it.
2021-09-01interpreter: Introduce BooleanHolder for the bool primitiveDaniel Mensinger