Commit Graph

498 Commits

Author SHA1 Message Date
Xavier Claessens 5e2a47e768 Interpreter: Using executable in run_command/configure_file is not a
bug

Fixes: #11382
2023-06-15 14:45:24 -04:00
Eli Schwartz 0ea28fa637
convert some FeatureDeprecated for totally broken stuff, to FeatureBroken
We now warn everyone equally that totally ignored sources are bad and
should not be used.
2023-06-14 23:12:09 -04:00
Eli Schwartz f93f443a53
detect and warn on non-commutative int/bool operations
an int only accepts operations on other ints, just like other primitive
types only accept operations on values of the same type.

But due to using isinstance in baseobjects "operator_call", an int
primitive allowed operations on a bool, even though reversing the
operator and having a bool perform operations on an int, would fail with
a type error.

Really, we should fail with a type error in both directions. But for
stability reasons, make this a loud warning and break --fatal-meson-warnings
builds.
2023-06-14 23:12:09 -04:00
Eli Schwartz d558291abe
add new FeatureBroken check class for annotating features that are really broken
This is useful for totally terrible stuff that we really dislike, but
for some reason we are afraid to just use `mlog.deprecation()` and
unconditionally tell people so.

Apparently this is because it is totally absolutely vital that, when
telling people something is so broken they should never ever ever use it
no matter what, ever... we can't actually tell them that unless they
bump the minimum version of Meson, because that's our standard way of
introducing a **version number** to tell them when we first started
warning about this.

Sigh. We really want to warn people if they are doing totally broken
stuff no matter what version of Meson they support, because it's not
like fixing the thing that never worked is going to suddenly break old
versions of meson.

So. Here's some new functionality that always warns you, but also tells
you when we started warning.
2023-06-14 22:53:50 -04:00
Xavier Claessens d8cb62bf2b Allow targetting Meson 1.2.0 when version is 1.1.99
When a project targets a dev version of Meson (e.g. 1.1.99) for
experimenting, this allows to use:

  project(..., meson_version: '>=1.2.0')

It avoids getting warnings when using FeatureNew for features introduced
in 1.2.0.
2023-06-13 10:32:48 -04:00
Tristan Partin 58aa301acc Override find_program('meson')
This override transparently upgrades anyone using it to this better
functionality.

Fixes #8511
2023-06-06 10:07:36 -04:00
Dylan Baker ada2a976f0
mlog: use a hidden class for state
This is a pretty common pattern in python (the standard library uses it
a ton): A class is created, with a single private instance in the
module, and then it's methods are exposed as public API. This removes
the need for the global statement, and is generally a little easier to
reason about thanks to encapsulation.
2023-05-31 17:20:44 -04:00
Dylan Baker 73c054ced6
mlog: remove direct calls to log_once
This was never meant to be public API, log(once=True) is for that.
2023-05-31 17:19:45 -04:00
Eli Schwartz 95b03f7930 avoid clearing the dependency cache unnecessarily based on wrap-mode
We actually do not and should not care about wrap-mode at all for this.
We want to cache dependency lookups whenever humanly possible, but only
use them in cases where we would anyways be using them -- which in
particular means if we said to force a subproject fallback for this dep,
we want to bypass the cache.

Currently, we handle this by always looking up the cache for all
dependencies, but clearing the cache at startup if a reconfigure means
we are changing our resolution strategy. This is bad -- we might have
many dependencies that are worth caching, and only one dependency that
should stop being cached and use a subproject instead.

The simple solution is to handle the forcefallback case when doing a
cache lookup, and not do a cache lookup at all. Now we don't have to
nuke the entire cache. In fact, if a future reconfigure changes the
forcefallback state back to not being forced, we can reuse the original
cached dependency, which is still there.

Closes #11828
2023-05-29 15:04:34 -04:00
Eli Schwartz 2c806099c7
repair install_mode support for uid/gid effectively everywhere
We silently dropped all integer values to install_mode since the
original implementation of doing this in KwargInfo, in commit
596c8d4af5.

This happened because install_mode is supposed to convert False
(exactly) to None, and otherwise pass all arguments in place. But a
generator is homogeneous and attempting to do this correctly produced a
mypy error that FileMode arguments were allowed to be ints -- well of
course they are -- so that resulted in the convertor... treating ints
like False instead, to make mypy happy.

Fixes #11538
2023-05-24 19:05:06 -04:00
Eli Schwartz 1ff996ea67
remove inaccurate comment
This convertor was initially implemented doing all the things the TODO
says it doesn't yet do. The freestanding interpreter function is what
doesn't do this.
2023-05-24 19:05:06 -04:00
Eli Schwartz e37394fe1d
deprecate the buildtarget.get_id() method
This has never been undocumented and there's no obvious value to having
it or using it. We're not even sure anyone ever has used it.

Closes #6061
2023-05-23 19:23:48 -04:00
Xavier Claessens 9d64143a4f summary: Add from which subproject each subproject have been called 2023-05-17 10:32:47 -04:00
Volker Weißmann 2699fd4b8a During reconfigure, show that no compiler was found, if compiler fails sanity check. 2023-05-13 11:06:24 +03:00
Sebastian Dröge 01420bf8fc rust: Add new `rust_dependency_map` target configuration
This allows changing the crate name with which a library ends up being
available inside the Rust code, similar to cargo's dependency renaming
feature or `extern crate foo as bar` inside Rust code.
2023-04-21 15:35:06 -04:00
Charles Brunet fbab1488ae extra_files keyword in declare_dependency() 2023-04-20 18:31:39 +03:00
Josh Soref cf9fd56bc9 fix various spelling issues
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-11 19:21:05 -04:00
Xavier Claessens b30cd5d2d5 Make --vsenv a readonly builtin option
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-29 09:33:41 -04:00
Dylan Baker 4a014d1724 Add support for meson.options as a replacement for meson_options.txt
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-28 15:01:10 +03:00
Xavier Claessens 567d1fec9b Make backend option read-only 2023-03-28 00:36:37 +03:00
Eli Schwartz a024d75e15
backends: add a new "none" backend
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-20 17:22:50 -04:00
Volker Weißmann bb27341cd0 Better error message when custom_targets has duplicates in the output kwarg 2023-03-17 18:04:05 -04:00
Eli Schwartz a410bbdf12 configure_file: emit FeatureNew when a cmake-formatted file has too many tokens
In commit 97a72a1c53 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-09 21:32:14 -08:00
Eli Schwartz 83b4f14fce emit FeatureNew warning for compiler.preprocess used multiple times
In commit c2a55bfe43 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-09 22:04:38 -05:00
Eli Schwartz d897c300f1 compiler.preprocess should only update the private name per directory
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-09 22:04:38 -05:00
Dylan Baker 162ac25beb build: fully type CompileTarget
Which is pretty trivial
2023-03-09 15:03:03 -05:00
Dylan Baker 853c16cbed interpreter: Add missing Union annotation 2023-03-09 15:03:03 -05:00
Xavier Claessens 0f67913dee typed_kwargs: Extend since_values and deprecated_values for types 2023-03-04 14:19:27 -05:00
Eli Schwartz a3f4f6c88f
interpreter: report FeatureNew for kwargs to project()
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-01 23:37:55 -05:00
Eli Schwartz 878c1604e6
handle meson_version even when the build file fails to parse
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-01 23:30:49 -05:00
Xavier Claessens f0dc61a764 interpreter: Add testcase..endtestcase clause support
This is currently only enabled when running unit tests to facilitate
writing failing unit tests.

Fixes: #11394
2023-03-01 20:13:34 -05:00
Andres Freund 808d5934dd Use caching in Compiler.sizeof() and Compiler.alignment() 2023-02-27 20:09:32 -05:00
Andres Freund ba72fc7f40 interpreter: bolden result of compiler.alignment(), compiler.sizeof()
This is more in line with other tests. It also looks better when introducing
caching, as a subsequent commit will.
2023-02-27 20:09:32 -05:00
L. E. Segovia 088727164d interpreter/mesonmain: Add build_options method
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-20 11:05:06 -05:00
Xavier Claessens ba1737cb66 interpreter: Do not ignore all exceptions when adding compiler
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-20 09:58:34 -05:00
Dylan Baker b2473b61cc interpreter: add FeatureOption.enable_if and .disable_if
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-15 22:58:50 -05:00
Dylan Baker 3589815eb9 interpreter: add a feature.enable_auto_if
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-15 22:58:50 -05:00
Xavier Claessens d21b64487e preprocess: Add dependencies kwarg 2023-02-15 15:12:34 -05:00
Xavier Claessens c2a55bfe43 preprocess: Allow custom_tgt, custom_idx and generated_list
It was documented to be supported but only File and str were actually
working.
2023-02-15 15:12:34 -05:00
Charles Brunet 04f233a80d allow install script to run in dry-run mode 2023-02-14 10:50:10 -05:00
Charles Brunet ce62190b17 Fix displaying outputs with add_*_script
#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-13 13:13:04 -05:00
Eli Schwartz a846fa3352
respect the machine file binary overrides, even if it doesn't exist
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-09 23:51:42 -05:00
Eli Schwartz 4c55947c47
pylint 2.16: raise a more intentional exception
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-01 17:01:31 -05:00
Eli Schwartz a21af43200
micro-optimize: define typing-only objects in TYPE_CHECKING
Union types that exist solely for use as annotations don't need to be
created in normal runs.
2023-02-01 17:01:30 -05:00
Eli Schwartz 680b5ff819
treewide: add future annotations import 2023-02-01 17:01:30 -05:00
Eli Schwartz 08e722d44c
log running commands a bit better by doing proper shell quoting 2023-01-31 00:25:43 -05:00
Dylan Baker c49552ffb2 interpreter: use typed_pos_args for build_targets
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-18 17:55:41 -05:00
Paolo Bonzini b3fc3cd6b5 add objects keyword argument to declare_dependencies 2023-01-04 09:44:32 -08:00
Dylan Baker b9ef662926 reformat some warnings for better code readability 2023-01-03 14:49:02 -05:00
Eli Schwartz 2fa0749175
add license_files kwarg to project
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-27 20:29:46 -05:00