aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase
AgeCommit message (Collapse)AuthorFilesLines
2023-04-04propagate the most accurate node to error messagesEli Schwartz1-3/+6
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-09re-deduplicate feature warnings printed at the end of setupEli Schwartz1-1/+1
In commit eaf365cb3ef4f1c2ba66e07237d86a44089aff4f we explicitly sorted them for neatness, with the rationale that we were restoring intentional behavior and we only need a set for stylistic purposes. This actually wasn't true, because we never sorted them to begin with (we did sort the version numbers), but sorting them is fine. The bigger issue is that we actually used a set to avoid printing the same feature type multiple times. Now we do print them multiple times -- because each registered feature includes the unique node. Fix this by using both sorted and a set. Fix tests that should in retrospect have flagged this as an issue, but were added later on in the same series to check something else entirely, happen to cover this too, and were presumably copied directly from stdout as-is...
2023-03-04typed_kwargs: Remove feature_validator as it's not currently usedXavier Claessens1-9/+0
2023-03-04typed_kwargs: Extend since_values and deprecated_values for typesXavier Claessens1-18/+33
2023-03-01handle meson_version after parsing but before invalid project() kwargsEli Schwartz1-0/+1
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 Schwartz1-3/+10
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 Claessens3-0/+20
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 Brunet1-9/+47
For instance, when writing `-subdir('a')` or `not subdir('a')`. Fixes #11225.
2023-02-01micro-optimize: define typing-only objects in TYPE_CHECKINGEli Schwartz1-20/+18
Union types that exist solely for use as annotations don't need to be created in normal runs.
2023-02-01treewide: add future annotations importEli Schwartz2-0/+2
2023-01-20decorators: don't unsort sorted values for printingDylan Baker1-2/+3
Currently in our deprecated/new feature printing we carefully sort all of the values, then put them in a set to print them. Which unsorts them. I'm assuming this was done because a set looks nice when printed (which is true). Let's keep the formatting, but print them in a stable order.
2022-12-05interpreter: add a feature_validator to KwargInfoDylan Baker1-0/+9
Because sometimes we simply need to open code FeatureNew and FeatureDeprecated checks, but in a re-usable way.
2022-11-29pylint: enable useless-returnDylan Baker1-1/+0
2022-10-24add option to typed_kwargs that allows unknown kwargs throughEli Schwartz1-6/+7
Some functions cannot be fully type checked, because our API allows fully arbitrary kwargs and treats them as data to pass through to the underlying feature. For example, hotdoc command line arguments. This change allows us to type check some kwargs with known types and possibly required status, and make their values consistent(ly defaultable), while preserving the optional nature of the additional kwargs.
2022-08-30fix obscure crash on unbound variableEli Schwartz1-4/+5
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-08-18interpreterbase: fix type annotations for KwargInfo::since_valuesDylan Baker1-4/+4
These are now allowed to be `Dict[_T | Type[list] | Type[dict], str]`, but the type annotations weren't updated
2022-06-17typed_kwargs: support dict/list as "new since" typesEli Schwartz1-6/+12
Given a kwarg value that is itself a dict/list, we would only check if the since_values was present within that container. If the since_values is itself the dict or list type, then we aren't looking for recursive structures, we just want to know when the function began to accept that type. This is relevant in cases where a function accepted a dict, and at one point began accepting a list (of strings in the form 'key=value'), or vice versa.
2022-05-23move various imports into TYPE_CHECKING blocks for neatnessEli Schwartz1-1/+7
2022-05-23typing: use forward reference for types defined later in fileEli Schwartz1-2/+2
2022-05-19Reword message in warningZbigniew Jędrzejewski-Szmek1-2/+2
"targetting" is verb-derived adjective, which sort-of-works here, but makes the whole sentence awkward, because there's no verb. Let's just use present simple.
2022-05-19Reword misleading warningZbigniew Jędrzejewski-Szmek1-2/+2
"tried to use" implies that the attempt was not successful, i.e. that meson ignored the feature. But that is not what happens, apart from the warning the feature works just fine. The new message is also shorter ;)
2022-05-01Add support for multiline f-stringsPeter Lesslie1-1/+8
+ 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 Schwartz3-7/+11
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-03-07treewide: string-quote the first argument to T.castEli Schwartz1-11/+11
Using future annotations, type annotations become strings at runtime and don't impact performance. This is not possible to do with T.cast though, because it is a function argument instead of an annotation. Quote the type argument everywhere in order to have the same effect as future annotations. This also allows linters to better detect in some cases that a given import is typing-only.
2022-03-07merge various TYPE_CHECKING blocks into oneEli Schwartz2-18/+18
A bunch of files have several T.TYPE_CHECKING blocks that each do some things which could just as well be done once, with a single `if` statement. Make them do so.
2022-03-01clean up FeatureCheck signature to move location to use timeEli Schwartz1-13/+11
The point of a .use() function is because we don't always have the information we need to use a feature check, so we allow creating the feature and then storing it for later use. When implementing location checks, although it is optional, actually using it violated that design. Move the location out of the init method for FeatureCheck itself. It remains compatible with all cases of .single_use(), but fix the rest up.
2022-03-01remove useless kwarg that was never usedEli Schwartz1-2/+1
I am not sure why it ever got added. It looks superficially similar to FeatureCheck itself, but doesn't need to.
2022-02-16flake8: use plain strings instead of f-strings when no variables usedEli Schwartz1-1/+1
2022-02-14FeatureNew: add mypy type annotations for subproject argEli Schwartz4-6/+15
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 Schwartz1-1/+1
2022-01-10first pass at migrating to dataclassesEli Schwartz1-3/+5
In some cases, init variables that accept None as a sentinel and immediately overwrite with [], are migrated to dataclass field factories. \o/ Note: dataclasses by default cannot provide eq methods, as they then become unhashable. In the future we may wish to opt into declaring them frozen, instead/additionally.
2021-12-06decorators: fold some duplicated code into a closureDylan Baker1-26/+17
2021-12-06add message option to since_values and deprecated_valuesDylan Baker1-6/+15
This allows these two arguments to take a tuple of (version, message), where the message will be passed to Feature*'s message parameter
2021-12-06Add deprecated_message and since_message to KwargInfoDylan Baker1-6/+17
For passing an extra message to Feature* This allows providing a more detailed message.
2021-12-06interpreterbase/decorators: Fix types of deprecated_values and since_valuesDylan Baker1-2/+3
Which shouldn't be Dict[str, str], they should be Dict[_T, str], as nay value that can be passed to types is valid here.
2021-12-05fix stray typoEli Schwartz1-1/+1
2021-12-05clean up function signatures in preparation for dataclassesEli Schwartz1-4/+4
FeatureCheck always immediately sets extra_message to '' if it isn't explicitly passed, so there is really no point in using None as a sentinel that is never used. Names used in init functions are sometimes pointlessly different from the class instance attributes they are immediately assigned to. They would make more sense if defined properly.
2021-11-22typed_kwargs: use | for type unions, not ,Dylan Baker1-4/+4
Python uses this syntax now, as does typescript and other languages
2021-11-22typed_kwargs: provide better error messages for wrong container typesDylan Baker1-1/+13
Currently, if you pass a `[]string`, but the argument expects `[]number`, then you get a message like `expected list[str] but got list`. That isn't helpful. With this patch arrays and dictionaries will both print messages with the types provided.
2021-11-22typed_kwargs: move some closures around to increase code clarityDylan Baker1-21/+24
The inner closure of the typed_kwargs function is already complicated enough without defining closures in the middle of a loop. Let's just pass the types_tuple as an argument to both avoid redefining the function over and over, and also make the whole thing easier to read.
2021-11-20FeatureDeprecated: add a notice summary of future deprecationsEli Schwartz1-5/+30
Since these aren't warnings, per se, we don't note every single call site that has one. And we raise mlog.notice in non-fatal mode to avoid either: - being too threatening - making builds fail with --fatal-meson-warnings Nevertheless, it is useful to give people a heads-up that there is an upgrade opportunity, rather than waiting until they upgrade and then causing projects to begin printing fatal warnings.
2021-11-20Feature kwargs decorator: automatically report the nodes which trigger an issueEli Schwartz1-9/+11
2021-11-20add location support to feature checksEli Schwartz1-11/+14
mlog can already print location info, and we use this often -- including for custom feature warnings already. Make this work everywhere, so that it is feasible to move such custom warnings to globally tracked Features.
2021-11-01various manual conversion of percent-formatted strings to f-stringsEli Schwartz1-5/+5
2021-11-01migrate python 3.5 compatible superclass variable annotations to 3.6Eli Schwartz1-3/+1
As we now require python 3.6, we can declare their types without initializing them.
2021-10-27Revert "mark a couple of typing-only imports as noqa, to appease pyflakes"Eli Schwartz1-3/+1
This reverts commit 6cc1b8441c0cf7428e52bdf1cd541ea830a4eb83. The latest version of pyflakes learned to detect that correctly.
2021-10-27fix various flake8 whitespace errorsEli Schwartz2-2/+3
2021-10-24interpreter: Fix missing featuer check (fixes #9425)Daniel Mensinger1-0/+6
2021-10-10Fix typos discovered by codespellChristian Clauss3-7/+7
2021-10-09typed_kwargs: Fix when ContainerTypeInfo is used in a tupleXavier Claessens1-35/+52
info.types could be a tuple like (str, ContainerTypeInfo()). That means we have to check types one by one and only print error if none of them matched. Also fix the case when default value is None for a container type, it should leave the value to None to be able to distinguish between unset and empty list.