summaryrefslogtreecommitdiff
path: root/mesonbuild/rewriter.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-11-25Rewriter: Handle unknown write targetsEyal Itkin
Add error checks for cases in which the write target is unknown and ensure all error cases indeed abort the execution to avoid internal crash. Resolves #13502. Signed-off-by: Eyal Itkin <eyal.itkin@gmail.com>
2025-11-18rewriter: fix kwargs info for dict-valued kwargsBenjamin Gilbert
We can't modify dict-valued kwargs (#14739) but this lets us at least read them.
2025-11-18rewriter: drop unused command-line arguments for def/kwargs deleteBenjamin Gilbert
The `default-options delete` and `kwargs delete` subcommands required key/value pairs, where the key was deleted and the specified value was ignored. This matches the JSON script mode interface but is unpleasant as a CLI. Have the CLI `delete` commands accept a list of keys instead. We can make this change because the UI is documented to be unstable. However, to allow scripts to work with both old and new Meson, ignore even-numbered arguments if they're all equal to the empty string. Fixes: #13234
2025-11-18rewriter: fix backtrace if command-line kwargs length is oddBenjamin Gilbert
Many rewriter subcommands expect key/value pairs as adjacent arguments. If the last value is missing, show a user-friendly error instead of a backtrace. For: #13234
2025-11-18rewriter: support project(license_files: )Benjamin Gilbert
2025-11-18rewriter: don't unpack the same values five timesBenjamin Gilbert
Fixes: e81acbd606 ("Use a single coredata dictionary for options")
2025-11-18rewriter: fix CLI help recommending invalid function IDs for projectBenjamin Gilbert
The project ID must be "/" and cannot be an arbitrary string.
2025-05-29rewriter: Bugfix concerning `UnknownValue`Volker Weißmann
Without this commit, the static introspection tool crashes when introspecting systemd since certain values are `UnknownValue` which was unexpected. (I tested sytemd's commit hash fefcb935cd.)
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 refactoring: Add rm_src_or_extraVolker Weißmann
De-duplicate some code by extracting the common code into the new `rm_src_or_extra` function.
2025-05-29rewriter: Improve find_target and find_dependencyVolker Weißmann
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: 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-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`.
2024-09-20rewriter: don't output target info to stderrBenoit Pierre
Send the info to stdout, where it belongs.
2024-06-14Rename option variable to optstore to make it unique.Jussi Pakkanen
2024-04-08parser: revert to single StringNode typeCharles Brunet
this will allow transforming string types in the formater
2024-02-26rewriter: allow setting values regardless of the previous typeJouke Witteveen
Alterations to kwargs come in two flavors: 1. Remove/replace values (delete/set) 2. Modify values (add/remove) Only for the second flavor do we care about the type of any existing value.
2024-02-12add type annotations to mesonmainEli Schwartz
An oddity: sys.stdout is statically defined as type TextIO instead of TextIOWrapper, and thus doesn't have a .reconfigure method. This is because they expect people to override sys.stdout with other objects, which we do not do. Instead, assume it is always correct. There are two final errors due to metaprogramming: ``` mesonbuild/mesonmain.py:196:13: error: Returning Any from function declared to return "int" [no-any-return] mesonbuild/mesonmain.py:225:9: error: Returning Any from function declared to return "int" [no-any-return] ```
2024-02-12rewriter: remove never-used default None when parsing argumentsEli Schwartz
The add_arguments function is always called with a formatter in mesonmain.py, and if it were not, then it would be incorrect when calling argparse itself -- because formatter_class cannot be None, and defaults to its own builtin one. This violates None-safety.
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-16Remove shebang from rewriter.pyMarcel Telka
2023-11-01Add comments suggesting to keep shell completion scripts up-to-date near cmd ↵Luke Elliott
line argument code
2023-09-11parser: simplify other node constructorsCharles Brunet
2023-09-11parser: simplify Assignment and PlusAssignment nodesCharles Brunet
2023-09-11parser: add SymbolNode to preserve operatorsCharles 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-04-11fix various spelling issuesJosh Soref
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-03-14rewriter: fix indentation of kwargsCharles Brunet
2023-03-14rewriter: add missing command aliasesCharles Brunet
2023-03-14rewriter: activate vsenvCharles Brunet
2023-02-01simplify instantiation of builtin type using builtins instead of functionsEli Schwartz
2022-11-30pylint: enable the set_membership pluginDylan Baker
Which adds the `use-set-for-membership` check. It's generally faster in python to use a set with the `in` keyword, because it's a hash check instead of a linear walk, this is especially true with strings, where it's actually O(n^2), one loop over the container, and an inner loop of the strings (as string comparison works by checking that `a[n] == b[n]`, in a loop). Also, I'm tired of complaining about this in reviews, let the tools do it for me :)
2022-09-19pylint: enable consider-using-inDylan Baker
2022-06-01ast: rename module constant to match PEP8 styleDylan Baker
2022-05-23move various imports into TYPE_CHECKING blocks for neatnessEli Schwartz
2021-12-15rewriter: create {add,rm}_extra_files commandsCeleste Wouters
Add ability to mutate a target's `extra_files` list through the rewriter. The logic is copied from sources add/rm, but changes the `extra_files` kwarg instead of the sources positional argument. Has additional logic to handle creating the `extra_files` list if it doesn't exist.
2021-08-31pylint: turn on superflous-parensDylan Baker
We have a lot of these. Some of them are harmless, if unidiomatic, such as `if (condition)`, others are potentially dangerous `assert(...)`, as `assert(condtion)` works as expected, but `assert(condition, message)` will result in an assertion that never triggers, as what you're actually asserting is `bool(tuple[2])`, which will always be true.
2021-08-31pylint: turn on superfluous parens warningDylan Baker
Which is really useful for catching parens used with keywords like assert. Don't use parens with assert, it's bad.
2021-06-29fix: Always explicitly set encoding for text files (fixes #8263)Daniel Mensinger
2021-03-04mass rewrite of string formatting to use f-strings everywhereEli Schwartz
performed by running "pyupgrade --py36-plus" and committing the results
2021-03-04various python neatness cleanupsEli Schwartz
All changes were created by running "pyupgrade --py3-only --keep-percent-format" and committing the results. I have not touched string formatting for now. - use set literals - simplify .format() parameter naming - remove __future__ - remove default "r" mode for open() - use OSError rather than compatibility aliases - remove stray parentheses in function(generator) scopes
2021-01-12Allow '//' as project function id due to git bash path conversion.Luke Elliott
See https://stackoverflow.com/questions/54258996/git-bash-string-parameter-with-at-start-is-being-expanded-to-a-file-path
2021-01-04Use a single coredata dictionary for optionsDylan Baker
This patches takes the options work to it's logical conclusion: A single flat dictionary of OptionKey: UserOptions. This allows us to simplify a large number of cases, as we don't need to check if an option is in this dict or that one (or any of 5 or 6, actually).
2021-01-04use OptionKey for builtin and base optionsDylan Baker
I would have prefered to do these seperatately, but they are combined in some cases, so it was much easier to convert them together. this eliminates the builtins_per_machine dict, as it's duplicated with the OptionKey's machine parameter.