aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter
AgeCommit message (Collapse)AuthorFilesLines
2023-03-29Make --vsenv a readonly builtin optionXavier Claessens1-3/+3
We need to remember its value when reconfiguring, but the Build object is not reused, only coredata is. This also makes CLI more consistent by allowing `-Dvsenv=true` syntax. Fixes: #11309
2023-03-28Add support for meson.options as a replacement for meson_options.txtDylan Baker1-6/+22
We will still try to load `meson_options.txt` if `meson.options` doesn't exist. Because there are some advantages to using `meson.options` even with older versions of meson (such as better text editor handling) we will not warn about the existence of a `meson.options` file if a `meson_options.txt` file or symlink also exists. The name `meson.options` was picked instead of alternative proposals, such as `meson_options.build` for a couple of reasons: 1. meson.options is shorter 2. While the syntax is the same, only the `option()` function may be called in meson.options, while, it may not be called in meson.build 3. While the two files share a syntax and elementary types (strings, arrays, etc), they have different purposes: `meson.build` declares build targets, `meson.options` declares options. This is similar to the difference between C's `.c` and `.h` extensions. As an implementation detail `Interpreter.option_file` has been removed, as it is used exactly once, in the `project()` call to read the options, and we can just calculate it there and not store it. Fixes: #11176
2023-03-28Make backend option read-onlyXavier Claessens1-1/+3
2023-03-20backends: add a new "none" backendEli Schwartz1-0/+2
It can only be used for projects that don't have any rules at all, i.e. they are purely using Meson to: - configure files - run (script?) tests - install files that exist by the end of the setup stage This can be useful e.g. for Meson itself, a pure python project.
2023-03-17Better error message when custom_targets has duplicates in the output kwargVolker Weißmann1-0/+7
2023-03-09configure_file: emit FeatureNew when a cmake-formatted file has too many tokensEli Schwartz1-1/+1
In commit 97a72a1c53e68cf53541285075b4000f7c85ccc6 we started to allow cmakedefine with 3 tokens, as cmake expects (unlike mesondefine). This would silently start working even if the declared minimum version was older than 0.54.1
2023-03-09emit FeatureNew warning for compiler.preprocess used multiple timesEli Schwartz1-0/+3
In commit c2a55bfe43fae1b44cf49a083297d6755c89e1cc multiple bugs were fixed, but a FeatureNew was only added for the one that was mentioned in the commit message. Make sure to warn users about the reliability of the one that wasn't mentioned, too.
2023-03-09compiler.preprocess should only update the private name per directoryEli Schwartz1-2/+5
We add a unique ID to each rule we create, to work around the use of an entire build target with private directory named "preprocess" per use of the preprocess() method. But this ID doesn't need to increment every time it is used anywhere -- only when it is used in the same subdir as a previous time. That is the only case where it could conflict. By making the increment counter per-subdir, we can avoid potential frivolous rebuilds when a new preprocess() is added in a different directory, the build is reconfigured, and all uses in the entire project tree suddenly get new output paths even if they haven't changed.
2023-03-09build: fully type CompileTargetDylan Baker1-7/+3
Which is pretty trivial
2023-03-09interpreter: Add missing Union annotationDylan Baker1-1/+1
2023-03-04typed_kwargs: Extend since_values and deprecated_values for typesXavier Claessens1-9/+0
2023-03-01interpreter: report FeatureNew for kwargs to project()Eli Schwartz1-1/+1
We need to know the project minimum version before evaluating the rest of the function. There's three basic approaches: - try to set it inside KwargInfo - just run a minimal version of func_project for this, then load everything after - drop down to the AST and set it before anything else In order to handle FeatureNew emitted by a FunctionNode evaluated before project() due to being inlined, such as `version: run_command()`, only option 3 suffices, the rest all happen way too late. Since we have just added AST handling support for erroring out, we can do that to set the version as well.
2023-03-01handle meson_version even when the build file fails to parseEli Schwartz1-4/+19
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 Claessens1-1/+21
This is currently only enabled when running unit tests to facilitate writing failing unit tests. Fixes: #11394
2023-02-27Use caching in Compiler.sizeof() and Compiler.alignment()Andres Freund1-7/+11
2023-02-27interpreter: bolden result of compiler.alignment(), compiler.sizeof()Andres Freund1-2/+2
This is more in line with other tests. It also looks better when introducing caching, as a subsequent commit will.
2023-02-20interpreter/mesonmain: Add build_options methodL. E. Segovia1-1/+11
This method allows meson.build to introspect on the changed options. It works by merely exposing the same set of data that is logged by MesonApp._generate. Fixes #10898
2023-02-20interpreter: Do not ignore all exceptions when adding compilerXavier Claessens1-1/+1
Suppressing all exceptions was hidding even syntax errors in compiler source code. If a compiler cannot be found, a MesonException is raised, we should only expect that type.
2023-02-15interpreter: add FeatureOption.enable_if and .disable_ifDylan Baker1-5/+39
This adds two new methods, that are conceptually related in the same way that `enable_auto_if` and `disable_auto_if` are. They are different however, in that they will always replace an `auto` value with an `enabled` or `disabled` value, or error if the feature is in the opposite state (calling `feature(disabled).enable_if(true)`, for example). This matters when the feature will be passed to dependency(required : …)`, which has different behavior when passed an enabled feature than an auto one. The `disable_if` method will be controversial, I'm sure, since it can be expressed via `feature.require()` (`feature.require(not condition) == feature.disable_if(condition)`). I have two defences of this: 1) `feature.require` is difficult to reason about, I would expect require to be equivalent to `feature.enable_if(condition)`, not to `feature.disable_if(not condition)`. 2) mixing `enable_if` and `disable_if` in the same call chain is much clearer than mixing `require` and `enable_if`: ```meson get_option('feat') \ .enable_if(foo) \ .disable_if(bar) \ .enable_if(opt) ``` vs ```meson get_option('feat') \ .enable_if(foo) \ .require(not bar) \ .enable_if(opt) ``` In the first chain it's immediately obvious what is happening, in the second, not so much, especially if you're not familiar with what `require` means.
2023-02-15interpreter: add a feature.enable_auto_ifDylan Baker1-1/+12
It's always been strange to me we don't have an opposite method of the `disable_auto_if` method, but I've been pressed to find a case where we _need_ one, because `disable_auto_if` can't be logically contorted to work. I finally found the case where they're not equivalent: when you don't want to convert to a boolean: ```meson f = get_option('feat').disable_auto_if(not foo) g = get_option('feat').enable_auto_if(foo) dep1 = dependency('foo', required : f) dep2 = dependency('foo', required : g) ```
2023-02-15preprocess: Add dependencies kwargXavier Claessens1-0/+3
2023-02-15preprocess: Allow custom_tgt, custom_idx and generated_listXavier Claessens1-3/+12
It was documented to be supported but only File and str were actually working.
2023-02-14allow install script to run in dry-run modeCharles Brunet1-0/+3
2023-02-13Fix displaying outputs with add_*_scriptCharles Brunet1-1/+1
#8259 induced a regression, causing Meson 0.57.0 and upward to stop printing outputs of scripts added using `meson.add_*_script()`. This makes _find_source_scripts() mark executables as verbose in meson_exe.
2023-02-09respect the machine file binary overrides, even if it doesn't existEli Schwartz1-1/+3
If someone specifies a binary in a machine file, but the resulting prog.found() is false because it doesn't actually exist on disk, then the user was probably trying to disable finding that program. But find_program() currently doesn't distinguish between a machine file lookup returning a not-found program, and returning a dummy program because there's no entry at all. Explicitly check for a dummy program, rather than checking if the program was found, before deciding whether to discard the lookup results and continue trying other program lookup methods.
2023-02-01pylint 2.16: raise a more intentional exceptionEli Schwartz1-1/+1
Include a frivolous error message too. We never see it, but if someone reads the code and wonders why on *earth* there's a DSL function to raise a RuntimeError, the message string will clue them in.
2023-02-01micro-optimize: define typing-only objects in TYPE_CHECKINGEli Schwartz1-5/+6
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 Schwartz3-0/+3
2023-01-31log running commands a bit better by doing proper shell quotingEli Schwartz1-3/+3
2023-01-18interpreter: use typed_pos_args for build_targetsDylan Baker1-11/+48
We have to allow through build.BuildTarget and build.ExtractedObjects, which is what our previous level of checking did, even though they are ignored. I've used FeatureDeprecated calls here, so that we have a clear time of "this was officially deprecated in 1.1.0"
2023-01-04add objects keyword argument to declare_dependenciesPaolo Bonzini1-1/+4
2023-01-03reformat some warnings for better code readabilityDylan Baker1-4/+6
2022-12-27add license_files kwarg to projectEli Schwartz2-3/+24
Hook this up to installed dependency manifests. This is often needed above and beyond just an SPDX string -- e.g. many licenses have custom copyright lines.
2022-12-24interpreter: use static_lib's already calculated pic valueDylan Baker1-9/+1
Instead of re-calculating it when building both libraries
2022-12-11typing: fix some broken Sequence annotationsEli Schwartz1-1/+1
T.Sequence is a questionable concept. The idea is to hammer out generic, maximally forgiving APIs that operate on protocols, which is a fancy way of saying "I don't care if you use tuples or lists". This is rarely needed, actually, and in exchange for this fancy behavior you get free bugs. Specifically, `somestr` is of type `T.Sequence[str]`, and also `somestr[0]` is another string of type you guessed it. It's ~~turtles~~ strings all the way down. It's worth noting that trying to code for "protocols" is a broken concept if the contents have semantic meaning, e.g. it operates on "the install tags of this object" rather than "an iterable that supports efficient element access". The other way to use T.Sequence is "I don't like that T.List is invariant, but also I don't like that T.Tuple makes you specify exact ordering". This sort of works. In fact it probably does work as long as you don't allow str in your sequences, which of course everyone allows anyway. Use of Sequence has cute side effects, such as actually passing lists around, knowing that you are going to get a list and knowing that you need to pass it on as a list, and then having to re-allocate as `list(mylist)` "because the type annotations says it could be a str or tuple". Except it cannot be a str, because if it is then the application is fatally flawed and logic errors occur to disastrous end user effects, and the type annotations: - do not enforce their promises of annotating types - fail to live up to "minimal runtime penalties" due to all the `list()` Shun this broken concept, by hardening the type annotations. As it turns out, we do not actually need any of this covariance or protocol-ism for a list of strings! The whole attempt was a slow, buggy waste of time.
2022-12-06interpreter: compiler: Allow array for the prefix kwargMarvin Scholz1-1/+7
2022-12-05when generating optional utility targets in ninja, skip existing aliases tooEli Schwartz1-3/+0
When auto-generating e.g. a `clang-format` target, we first check to see if the user has already defined one, and if so we don't bother creating our own. We check for two things: - if a ninja target already exists, skip - if a run_target was defined, skip The second check is *obviously* a duplicate of the first check. But the first check never actually worked, because all_outputs was only generated *after* generating all utility rules and actually writing out the build.ninja file. The check itself compares against nothing, and always evaluates to false no matter what. Fix this by reordering the target creation logic so we track outputs immediately, but only error about them later. Now, we no longer need to special-case run_target at all, so we can drop that whole logic from build.py and interpreter.py, and simplify the tracked state. Fixes defining an `alias_target()` for a utility, which tried to auto-generate another rule and errored out. Also fixes doing the same thing with a `custom_target()` although I cannot imagine why anyone would want to produce an output file named `clang-format` (unless clang itself decided to migrate to Meson, which would be cool but feels unlikely).
2022-12-05type_checking: add a type checking helper for strings in include_directoriesDylan Baker1-0/+9
2022-12-05interpreter: move TEST_KW from interpreter.py to type_checking.pyDylan Baker2-21/+22
Since it's also used in the rust module, it should be in a common place. Also rename from `TEST_KWARGS` to `TEST_KWS`, which is more in line with the `*_KW` naming scheme used in the type_checking module.
2022-12-04dependencies: only print not_found_message onceMichael Champanis1-1/+0
Due to an accidentally repeated line it would print twice unless required. Fixes #8150
2022-11-29pylint: enable the bad_builtin checkerDylan Baker2-2/+2
This finds uses of deny-listed functions, which defaults to map and filter. These functions should be replaced by comprehensions in idiomatic python because: 1. comprehensions are more heavily optimized and are often faster 2. They avoid the need for lambdas in some cases, which make them faster 3. you can do the equivalent in one statement rather than two, which is faster 4. They're easier to read 5. if you need a concrete instance (ie, a list) then you don't have to convert the iterator to a list afterwards
2022-11-24Fix various spelling errorsDavid Robillard3-3/+3
Found with codespell.
2022-11-16Fix deprecation message, the function name is fs.copyfile()Xavier Claessens1-1/+1
2022-11-16Change the warning generated by importing an unstable module to non-fatalTristan Partin1-1/+1
Penalizing users for helping to test unstable modules really makes no sense. As a fatal warning, users can no longer use `--fatal-meson-warnings`.
2022-11-08Fix since annotation for str "in" operatorXavier Claessens1-2/+2
2022-11-06Implement `in` operator on stringXavier Claessens1-0/+12
2022-10-31both_libraries: Make sure to select the right linker for static libXavier Claessens1-3/+2
Regression test: libccpp has both C and C++ sources. The executable only has C sources. It should still link using the C++ compiler. When using both_libraries the static has no sources and thus no compilers, resulting in the executable linking using the C compiler. https://github.com/Netflix/vmaf/issues/1107
2022-10-31emit a FeatureNew when using include_directories as a stringEli Schwartz1-0/+7
This was introduced in commit 3a6e2aeed9737f1082571e868ba50e72957f27c7 as part of 0.50.0, but did not contain a FeatureNew. As a result, people would use it without realizing that they broke support for versions of Meson included in their minimum requirements.
2022-10-24Add missing since annotations in docsElliott Sales de Andrade1-1/+1
This is based on searching for `@FeatureNew*` decorators. There is also one correction to a version in a decorators; `build_by_default` was added in #1303, which is 0.38.0, not 0.40.0.
2022-10-24Accept disablers in summary valuesElliott Sales de Andrade1-1/+4
They are commonly used as a replacement for a `dependency`, and not accepting them in `summary` breaks the last example in [1] when used as a value. [1] https://mesonbuild.com/Disabler.html#disabling-parts-of-the-build