Commit Graph

111 Commits

Author SHA1 Message Date
Charles Brunet 11f2e07071 Allow using CustomTarget as test executable
Fixes #6567
2024-02-24 09:08:20 -08:00
Charles Brunet 138e0fe984 env.unset method 2024-02-23 21:11:56 +02:00
Xavier Claessens 85e4ee5b54 File: Add full_path() method
This is needed now that str.format() is not allowing it any more. It is
also more consistent with other objects that have that method as well,
such as build targets.

Fixes: #12406
2023-11-24 22:15:14 +02:00
Eli Schwartz 398c4b2287
dependencies: allow get_variable to define multiple pkgconfig defines
It was previously impossible to do this:

```
dep.get_pkgconfig_variable(
    'foo',
    define_variable: ['prefix', '/usr', 'datadir', '/usr/share'],
)
```

since get_pkgconfig_variable mandated exactly two (if any) arguments.

However, you could do this:
```
dep.get_variable(
    'foo',
    pkgconfig_define: ['prefix', '/usr', 'datadir', '/usr/share'],
)
```

It would silently do the wrong thing, by defining "prefix" as
`/usr=datadir=/usr/share`, which might not "matter" if only datadir was
used in the "foo" variable as the unmodified value might be adequate.

The actual intention of anyone writing such a meson.build is that they
aren't sure whether the .pc file uses ${prefix} or ${datadir} (or which
one gets used, might have changed between versions of that .pc file,
even).

A recent refactor made this into a hard error, which broke some projects
that were doing this and inadvertently depending on some .pc file that
only used the second variable. (This was "fine" since the result was
essentially meaningful, and even resulted in behavior identical to the
intended behavior if both projects were installed into the same prefix
-- in which case there's nothing to remap.)

Re-allow this. There are two ways we could re-allow this:
- ignore it with a warning
- add a new feature to allow actually doing this

Since the use case which triggered this bug actually has a pretty good
reason to want to do this, it makes sense to add the new feature.

Fixes https://bugs.gentoo.org/916576
Fixes https://github.com/containers/bubblewrap/issues/609
2023-11-14 14:59:12 -05:00
Nomura 3cac6ea545 Add env kwarg in generator.process() 2023-10-05 09:59:43 -07:00
Xavier Claessens dec85c41a9 Remove get_configtool_variable()
This also makes it more consistent with get_pkgconfig_variable() which
always return empty value instead of failing when the variable does not
exist. Linking that to self.required makes no sense and was never
documented any way.
2023-09-18 13:51:27 -04:00
Xavier Claessens 30d7f506c7 Remove get_pkgconfig_variable()
Make sure that pkgconfig_define is a pair of strings and not a list with
more than 2 strings.
2023-09-18 13:51:27 -04:00
Eli Schwartz 277151450a
allow some ObjectHolder subclasses to continue to be generic
ExternalProgram and CustomTarget have some use cases for producing
subclassed interpreter holders with more specific types and methods. In
order for those subclasses to properly refer to their held_object, we
need a shared base class that is still generic, though bound.

For the derived held objects, inherit from the base class and specify
the final types as the module-specific type.
2023-08-10 13:56:39 -04:00
Eli Schwartz 7afc69254d
fix implicit_reexport issues and enforce them going forward
This detects cases where module A imports a function from B, and C
imports that same function from A instead of B. It's not part of the API
contract of A, and causes innocent refactoring to break things.
2023-07-19 18:31:37 -04:00
Jussi Pakkanen b0d2a92584 Add kernel and subsystem properties to machine objects. 2023-06-19 18:03:57 +03: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
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
Eli Schwartz 08e722d44c
log running commands a bit better by doing proper shell quoting 2023-01-31 00:25:43 -05:00
Dylan Baker d5e899c768
pylint: enable the bad_builtin checker
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-29 23:26:05 -05:00
David Robillard e85138fcc8 Fix various spelling errors
Found with codespell.
2022-11-24 15:17:23 -05:00
Xavier Claessens 9b9154017e Make a copy of auto_features options when changing its name
This fixes bogus messages "skipped: feature foo disabled" when
auto_features=disabled. It was reporting the name of the latest
get_option() call instead of the name of the current feature option.

This is especially visible in GStreamer summary where it should show a
different option name for every subproject but instead shows "tools"
everywhere:
```
  Subprojects
    gst-devtools              : NO Feature 'tools' disabled
    gst-editing-services      : NO Feature 'tools' disabled
    ...
```
2022-05-25 22:52:30 -04:00
Jussi Pakkanen bba588d8b0
Merge pull request #10039 from eli-schwartz/wayland-protocols-subproject-files
dependencies: allow get_variable to expose files from subprojects
2022-05-01 00:01:03 +03:00
Eli Schwartz ea8f4bb4ad
typo 2022-04-14 18:37:04 -04:00
Eli Schwartz df3f064c81
dependencies: move DependencyVariableString handling to declare_dependency
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-13 17:28:01 -04:00
Eli Schwartz 0e3ed2f655
dependencies: allow get_variable to expose files from subprojects
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-04-13 17:28:01 -04:00
Eli Schwartz b55349c2e9
dependencies: tighten type checking and fix cmake API violation for get_variable
dep.get_variable() only supports string values for pkg-config and
config-tool, because those interfaces use text communication, and
internal variables (from declare_dependency) operate the same way.

CMake had an oddity, where get_variable doesn't document that it allows
list values but apparently it miiiiiight work? Actually getting that
kind of result would be dangerously inconsistent though. Also, CMake
does not support lists so it's a lie. Strings that are *treated* as
lists with `;` splitting don't count...

We could do two things here:

- raise an error
- treat it as a string and return a string

It's not clear what the use case of get_variable() on a maybe-list is,
and should probably be a hard error. But that's controversial, so
instead we just return the original `;`-delimited string. It is probably
the wrong thing, but users are welcome to cope with that somehow on
their own.
2022-04-13 17:27:09 -04:00
Eli Schwartz c9938f8f60
move a bunch of imports into TYPE_CHECKING blocks
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-29 16:44:54 -04:00
Jussi Pakkanen 69ade4f4cf
Merge pull request #9339 from dcbaker/submit/structured_sources
Structured Sources
2022-03-13 01:01:55 +02:00
Eli Schwartz a009eacc65
treewide: string-quote the first argument to T.cast
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-07 19:01:04 -05:00
Dylan Baker fd55ff6a72 interpreter: Add a holder for StructuredSources
And teach the interpreter how to use it
2022-03-07 12:33:33 -08:00
Jussi Pakkanen 8434fb1409 Fix mypy CI. 2022-03-07 22:28:37 +02:00
Jussi Pakkanen ade6e3a19e
Merge pull request #10043 from dcbaker/submit/type-checking-for-subproject
Add typing for subproject()
2022-03-07 16:43:44 +02:00
Eli Schwartz 0f2f87a003
find_program: add a version() method to match the one for dependencies
It is often useful to check the found version of a program without
checking whether you can successfully find
`find_program('foo', required: false, version: '>=XXX')`
2022-03-06 19:41:21 -05:00
Dylan Baker 643b3f227e interpreter: fix mismatched type expectations 2022-03-03 10:30:31 -08:00
Dylan Baker 5787f81615 interpreter: add cm_interpreter to SubprojectHolder
This is used in the cmake module, as an extra attribute we just tack on.
Instead, let's actually define and type it.
2022-03-03 10:29:14 -08:00
Eli Schwartz d39b330075 clean up FeatureCheck signature to move location to use time
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-01 12:13:24 -08:00
Xavier Claessens 6acfe48f32 Allow setting method/separator in environment() and meson.add_devenv() 2022-02-28 09:03:27 -05:00
Eli Schwartz c0b8e02d9f
FeatureNew: add mypy type annotations for subproject arg
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-02-14 20:40:41 -05:00
Eli Schwartz 6c79e97eae
add some forgotten FeatureNew annotations
Forgotten in #8512.
2022-02-09 21:44:46 -05:00
Paolo Bonzini fc661c35a2 interpreter: support for forcibly verbose logging of some tests
Add a new keyword argument to test() and benchmark(), completing the
implementation of the feature.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2022-02-01 09:05:26 +01:00
Dylan Baker 4f40962a05 interpreterobjects: Don't warn on set10(bool)
Python inherited a really bad design from C, booleans happen to be ints.
Which is awful, but it's true.

Fixes: #9858
2022-01-23 17:21:53 -05:00
Dylan Baker 9c7ddf59fe interpreterobjects: deprecated passing a number to configuration_data.set10
This is currently allowed, and is used in at least a few projects. It
was not intended to work or documented, but it does and since it is in
use a full deprecation period must be used. A warning has also been
added for values < 0, which have surprising behavior.
2022-01-18 17:53:29 -05:00
Dylan Baker bf3fa728fa interpreterobjects: remove no-flattening from configuraiton_data.get
It's no longer required because we don't allow arrays as fallbacks
anymore.
2022-01-18 17:53:29 -05:00
Dylan Baker f16956a951 interpreterobjects: don't allow keyword arguments in configuration_data.keys
Which do nothing, and shouldn't be allowed.
2022-01-18 17:53:29 -05:00
Dylan Baker 5074e2d3b5 interpreter: replace ConfigurationDataObject with ConfigurationDataHolder
This is much cleaner, and more in line with the way we handle
interpreter objects in modern meson practice
2022-01-18 17:53:29 -05:00
Dylan Baker 5c979eb21f interpreterobjects: clean up ConfigurationData initializer 2022-01-18 17:53:29 -05:00
Dylan Baker 574525673f interpreterobjects: use typed_* for configuration_data.set*
This removes the ability to use ConfigurationData as a dict, but
restricting the inputs to `str | int | bool`. This may be a little too
soon for this, and we may want to wait on that part, it's only bee 8
months since we started warning about this.
2022-01-18 17:53:29 -05:00
Dylan Baker 7641bfd0ce interpreterobjects: use typed_* with configuration_data.merge_from 2022-01-18 17:53:29 -05:00
Dylan Baker f7cbe89a13 interpreterobjects: use typed_* with configuration_data.get_unquoted 2022-01-18 17:53:29 -05:00
Dylan Baker baa9ecb1c4 interpreterobjects: use typed_args for configuration_data.get 2022-01-18 17:53:29 -05:00
Dylan Baker 65558445ae interpreterobjects: use typed_pos_args and noKwargs for configuration.data.has 2022-01-18 17:53:29 -05:00
Dylan Baker 1ff2abcd9c interpreterobjects: use typed_kwargs for dependency.get_variable 2022-01-18 17:53:29 -05:00
Dylan Baker 1751dc4701 interpreterobjects: use typed_kwargs for dependency.get_pkgconfig_variable 2022-01-18 17:53:29 -05:00