summaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter/primitives/string.py
AgeCommit message (Collapse)Author
2025-12-04interpreter: validate argument to string.split() for empty stringDylan Baker
The underlying Python implementation throws in this case, and I'm not sure what the correct result here would be if we allowed it. Convert to None and don't split? Split every character? I've gone with throwing InvalidArguments, which maintains the current behavior of "doesn't work" but with a nicer output. Any other change would require a FeatureNew anyway, and can wait till 1.11. Fixes: #15335
2025-11-14make str and meson.version() API align again.Eli Schwartz
Regression in commit 6ee583e119b432fee03f908547729d5da030397e. str.version_compare() accepts varargs unless the str was defined via meson.version(), which isn't supposed to be a visible end user distinction. That being said, it makes no sense to support the special casing here. - FeatureNew only compares conditions with min, not with max - Having multiple min conditions is illogical and there's no need to support it. So we allow varargs for parity, but debug log that we can't handle it specially and refrain from setting tmp_meson_version at all. Fixes: https://github.com/mesonbuild/meson/issues/15217
2025-11-14version_compare with meson.version() override should log when it doesn't workEli Schwartz
meson_version: '>=1.8.0' works to control FeatureNew -- but < does not. Likewise with version_compare. This may or may not surprise people. Leave a hint in the logfile.
2025-10-29Add snippets.symbol_visibility_header() methodXavier Claessens
Defining public API in a cross platform library is painful, especially on Windows. Since every library have to define pretty much the same macros, better do it in Meson.
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-01-27allow to compare multiple version with version_compareCharles Brunet
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-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-12string: Add missing FeatureNew tags to methodsMarco Trevisan (Treviño)
There are some new(er) methods that have not version reference, so add the missing ones in order to be properly notified when targetting older meson versions. Co-authored-by: Tristan Partin <tristan@partin.io>
2023-06-20add str.splitlines methodMartin Dørum
The new splitlines method on str is intended to replace usage of fs.read('whatever').strip().split('\n'). The problem with the .strip().split() approach is that it doesn't have a way to represent empty lists (an empty string becomes a list with one empty string, not an empty list), and it doesn't handle Windows-style line endings.
2022-11-08Fix since annotation for str "in" operatorXavier Claessens
2022-11-06Implement `in` operator on stringXavier Claessens
2022-08-22interpreter: add a special class to track the lifecycle of get_option() stringsEli Schwartz
2022-06-13flake8: fix various whitespace nitsEli Schwartz
2022-04-13dependencies: move DependencyVariableString handling to declare_dependencyEli Schwartz
This allows tracking which subproject it came from at the time of definition, rather than the time of use. As a result, it is no longer possible for one subproject which knows that another subproject installs some data files, to expose those data files via its own declare_dependency.
2022-04-13dependencies: allow get_variable to expose files from subprojectsEli Schwartz
There are somewhat common, reasonable and legitimate use cases for a dependency to provide data files installed to /usr which are used as command inputs. When getting a dependency from a subproject, however, the attempt to directly construct an input file from a subproject results in a sandbox violation. This means not all dependencies can be wrapped as a subproject. One example is wayland-protocols XML files which get scanned and used to produce C source files. Teach Meson to recognize when a string path is the result of fetching a dep.get_variable(), and special case this to be exempt from subproject violations. A requirement of this is that the file must be installed by install_data() or install_subdir() because otherwise it is not actually representative of what a pkg-config dependency would provide.
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-01-27fix some flake8 violations for unused importsEli Schwartz
And one undefined T.cast name in a file that isn't yet mypy-ready anyway.
2021-11-04fix regression that broke string.format with list objectsEli Schwartz
String formatting should validly assume that printing a list means printing the list itself. Instead, something like this broke: 'one is: @0@ and two is: @1@'.format(['foo', 'bar'], ['baz']) which would evaluate as: 'one is: foo and two is: bar' or: 'the value of array option foobar is: @0@'.format(get_option('foobar')) which should evaluate with '-Dfoobar=[]' as 'the value of array option foobar is: []' But instead produced: meson.build:7:0: ERROR: Format placeholder @0@ out of range. Fixes #9530
2021-10-26interpreter: Revert old path joining behavior (fixes #9450)Daniel Mensinger
2021-10-10Revert "interpreter: Add FeatureNew check"Eli Schwartz
This reverts commit c0efa7ab22f8900f6fa1dadf0d306ec375569c8d. This was a nice idea, or a beautiful hack depending on your perspective. Unfortunately, it turns out to be a lot harder than we originally thought. By operating on bare nodes, we end up triggering a FeatureNew on anything that isn't a string literal, rather than anything that isn't a string. Since no one else has come up with a better idea for implementing a FeatureNew, let's just revert it. Better to not have a warning, than have it trigger way too often.
2021-10-04fix extra whitespaceEli Schwartz
discovered via flake8 --select E303
2021-09-25interpreter: Add FeatureNew checkDaniel Mensinger
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).