Commit Graph

670 Commits

Author SHA1 Message Date
Eli Schwartz aa0450adda
fix a couple misuses of textwrap.dedent
A backslash-escape of the last newline before a run of whitespace
leading to the indented string ending and function termination `)` does
not actually escape the entire line and make it do nothing. In fact what
it does is cause all that whitespace to be part of the preceding line,
and get printed.

Meanwhile the textwrap.dedent documentation states that lines with only
whitespace get normalized. When you *don't* mess with that final line,
dedent actually does the right thing and makes the output message end
with a single newline after the important text.
2022-02-16 22:59:48 -05:00
Nirbheek Chauhan 2d56ff135e shared module: Allow linking on Android
Android requires shared modules that use symbols from other shared
modules to be linked before they can be dlopen()ed in the correct
order. Not doing so leads to a missing symbol error:
https://github.com/android/ndk/issues/201

We need to always allow linking for this. Also add a soname, although
it's not confirmed that it's needed, and it doesn't really hurt if it
isn't needed.
2022-02-14 23:30:24 -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
William Toohey b4d9b2551c Genericise TI compiler and add MSP430 support 2022-02-02 16:45:05 +02:00
Dylan Baker 11f9638035 build: replace kwargs in CustomTarget initializer
Because we don't want to pass the Interpreter kwargs into the build
layer. This turned out to be a mega commit, as there's really on elegant
way to make this change in an incremental way. On the nice side, mypy
made this change super easy, as nearly all of the calls to
`CustomTarget` are fully type checked!

It also turns out that we're not handling install_tags in custom_target
correctly, since we're not converting the boolean values into Optional
values!
2022-01-28 15:53:20 -05:00
Dylan Baker 214ce0dc8b build: Fix return types of a couple of methods
These don't return `Target`, they return `BuildTarget | CustomTarget |
CustomTargetIndex`
2022-01-18 21:58:24 -05:00
Dylan Baker ce5f56f266 build: Fix annotations to RunTarget and AliasTarget
RunTargets and AliasTargets may depend on RunTargets, so annotate them
that way. The Gnome module relies on this internally.
2022-01-18 21:58:24 -05:00
Dylan Baker 23af9e4c1a build: move configuration_data initial value handling to build.ConfigurationData
It really belongs here, not in the interpreter
2022-01-18 17:53:29 -05:00
Eli Schwartz 4b351aef26
first pass at migrating to dataclasses
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.
2022-01-10 18:36:57 -05:00
Jussi Pakkanen 251d6f0f5d
Merge pull request #9739 from mathstuf/armclang-support
Armclang support
2022-01-10 19:01:11 +02:00
Xavier Claessens 95a4c6a62a pkgconfig: Fix linking to a custom target
When generating pkgconfig file for a library that links to an
uninstalled static library built by custom_target() Meson was crashing
when trying to access some attributes that does not exist on that class.

Also fix is_internal() implementation, it only really make sense on a
CustomTargetIndex or if CustomTarget has only a single output.
2021-12-22 08:04:08 +05:30
Daniel Mensinger c5ce9744b2 Fix mypy errors 2021-12-17 14:00:28 -05:00
Ben Boeckel 786d437982 armclang: extend the prefix detection for Keil armclang
This will avoid false positives with the ARM Ltd. `armclang` compiler.
2021-12-16 17:08:26 -05:00
Paolo Bonzini 901f444ea5 interpreter: allow extract_objects to receive generated sources
Fixes: #8333
2021-12-06 13:27:12 -08:00
Eli Schwartz 4b2c54569d
clean up function signatures in preparation for dataclasses
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-12-05 11:39:20 -05:00
Pablo Correa Gómez 4f882ff8ec add install_symlink function
Allows installing symlinks directly from meson, which can
become useful in multiple scenarios. Current main use is to
help moving forward #9557
2021-12-01 13:59:54 -05:00
Jussi Pakkanen bd509d11a5
Merge pull request #9531 from dcbaker/submit/interpreter-more-typing
More use of typed_* in the interpreter module
2021-11-27 21:44:41 +02:00
Mike Gilbert 91a099f3a7 Remove premature return in BuildTarget.check_module_linking()
We want to loop over all link_targets to update
backwards_compat_want_soname if necessary.

Fixes: ec9bdc6edb17d1d9da5df2d6525025242c119f3a
2021-11-27 20:16:34 +02:00
Nirbheek Chauhan af5993fffd shared_module: Add soname when used as a link target
Emit a detailed deprecation warning that explains what to do instead.
Also add a unittest.

```
DEPRECATION: target prog links against shared module mymod, which is incorrect.
             This will be an error in the future, so please use shared_library() for mymod instead.
             If shared_module() was used for mymod because it has references to undefined symbols,
             use shared_libary() with `override_options: ['b_lundef=false']` instead.
```

Fixes https://github.com/mesonbuild/meson/issues/9492
2021-11-24 23:18:53 +05:30
Dylan Baker f29b54dfe4 build|backend: Fix some type annotations
These currently say the take `Target`, but the really take
`BuildTarget | CustomTarget | CustomTargetIndex`.
2021-11-24 02:23:57 +05:30
Dylan Baker 75d163f56d build: TestSetup.exe_wrapper doesn't need to be optional
It works fine as-is with an empty list, and since that's easier to get
using our typed_kwargs, and thus is what we're passing, go ahead and
simplify the class to only take a list of strings.
2021-11-22 11:28:43 -08:00
Eli Schwartz dbb109703e
convert more mlog.deprecation into FeatureDeprecated 2021-11-20 20:48:29 -05:00
Eli Schwartz 1104b82137 fix custom_target with install: true and no install_dir, crashing
It's supposed to emit an error message, but instead it did a traceback.
It used to be, if no install_dir was specified then it was simply not in
kwargs, but due to typed_kwargs it will now be there, but not have
viable contents, so the dict membership check got skipped.

Fixes #9522
2021-11-02 19:56:10 -07:00
Dylan Baker 526b6b763a build: Add type annotations to BuildTarget.get_all_link_deps 2021-11-01 12:24:25 -07:00
Dylan Baker ac02521954 build: Add annotations to CustomTarget.extra_depends 2021-11-01 12:24:25 -07:00
Dylan Baker b572a7980e build: Add a get_command method to Executable
Since Executable can be used in places where ExternalProgram is, simply
having a wrapper that gives them the same API is pretty useful.
2021-11-01 12:24:25 -07:00
Dylan Baker 68c1669ae6 build: IncludeDirs extend `to_string_list` method to handle builddir 2021-11-01 12:24:25 -07:00
Dylan Baker 6472f013a1 build: Add type annotations for BuildTarget.include_dirs
The gnome module uses these, so to be able to fully type that we need
this.
2021-11-01 12:24:25 -07:00
Jussi Pakkanen c1b686e395 Make environment objects hash deterministically. 2021-10-29 22:47:06 +03:00
Jussi Pakkanen af85738daf
Merge pull request #9375 from dcbaker/submit/windows-module-typing
Typing for the Windows module
2021-10-29 22:45:04 +03:00
Eli Schwartz 8947352889 fix various flake8 whitespace errors 2021-10-27 09:51:52 -04:00
Xavier Claessens 928078982c Add --vsenv command line option and active VS only when needed 2021-10-10 23:15:18 +03:00
Christian Clauss a5020857f3 Fix typos discovered by codespell 2021-10-10 16:12:25 -04:00
Dylan Baker 0d52a6161a build: Add missing type annotation 2021-10-09 21:34:54 -07:00
Xavier Claessens 2628ce576c Add support for module options 2021-10-08 17:47:35 -04:00
Eli Schwartz 108bd996ee
add install_emptydir function
This replaces the absolute hack of using

```
install_subdir('nonexisting', install_dir: 'share')
```

which requires you to make sure you don't accidentally or deliberately
have a completely different directory with the same name in your source
tree that is full of files you don't want installed. It also avoids
splitting the name in two and listing them in the wrong order.

You can also set the install mode of each directory component by listing
them one at a time in order, and in fact create nested structures at
all.

Fixes #1604
Properly fixes #2904
2021-10-08 14:35:00 -04:00
Andres Freund 6b8f10cf6b backend/vs: Generate dependencies for CustomTargetIndex for a CustomTarget.
Test & fix.
2021-10-04 22:42:27 -04:00
Andres Freund a1542720f4 Record build in BuildTarget.link_depends, not just output of targets.
To be able to handle link_depends in backends that do not just operate on a
file basis like ninja, information about the targets, not just their output is
required.
2021-10-04 22:34:57 -04:00
Eli Schwartz e8a85fa8a2
various python neatness cleanups
All changes were created by running

"pyupgrade --py3-only"

and committing the results. Although this has been performed in the
past, newer versions of pyupgrade can automatically catch more
opportunities, notably list comprehensions can use generators instead,
in the following cases:
- unpacking into function arguments as function(*generator)
- unpacking into assignments of the form x, y = generator
- as the argument to some builtin functions such as min/max/sorted

Also catch a few creeping cases of new code added using older styles.
2021-10-04 16:29:30 -04:00
Dylan Baker c3c30d4b06 interpreter: Use typed_kwargs for func_custom_target
This does not convert the build side, or remove any of the checking it
does. We still need that for other callers of custom target. What we'll
do for those is add an internal interface that defaults things, then
we'll be able to have those callers do their own validation, and the
CustomTarget validation machinary can be removed.

Fixes #9096
2021-09-30 21:01:38 +02:00
Dylan Baker bb706231bd build: Prepare CustomTarget.process_kwargs to co-exist
We still need this to co-exist as long as there are interfaces for
CustomTarget other than `func_custom_target`, this gets us there.
2021-09-30 21:01:38 +02:00
Dylan Baker 7e417ac0fa build: Allow `Dict[OptionKey, str` in parse_overrides
We really want to move all of this option handling into the interpreter
through the typed_kwargs, this is the first step to that
2021-09-30 21:01:38 +02:00
Dylan Baker d25349e8cf build: Use isinstance(other, Target) instead of hasattr
In the comparison methods of Target. There are several problems with the
old implementation:
1. It's not idiomatic
2. It can match on things that It shouldn't (like a Compiler, which has
   a `get_id() -> str` method, but not one that we should compare with
   Targets
3. It confuses mypy, which doesn't handle hasattr
2021-09-30 21:01:38 +02:00
Dylan Baker d7bb0acbe3 build: Add type annotations to AliasTarget
It's just a RunTarget with one default value overriden
2021-09-30 21:01:38 +02:00
Dylan Baker 377c23388f build: drop unnecissary method from RunTarget 2021-09-30 21:01:38 +02:00
Dylan Baker 0a6fdd4900 build: Fully annotate RunTarget 2021-09-30 21:01:38 +02:00
Dylan Baker f9b14dc570 build: Add full type annotations to CommandBase 2021-09-30 21:01:38 +02:00
Dylan Baker c11eb86995 build: add forward delcarations to CommandBase class
It would probably be better if CommandBase had an initializer so it
could set the depend_files and dependencies attributes itself, but this
will make mypy happier.
2021-09-30 21:01:38 +02:00
Dylan Baker d80cfa27c9 build: Add a couple of obvious annotations to RunTarget 2021-09-30 21:01:38 +02:00
Xavier Claessens d2fa6d5080 Make custom_target() name argument optional 2021-09-30 12:26:19 -04:00
Daniel Mensinger 6b00c7dc81 Remove helpers.check_stringlist() 2021-09-25 12:44:11 +02:00
Dylan Baker 64c267c49c compilers: Add default search path stdlib_only_link_flags
This should be done in all cases of language_stdlib_only_link_flags, but
I don't have access to all of the compilers to test it.

This is required in cases where object files created by gfortran are
linked using another compiler with a differen default search path, such
as gfortran and clang together.
2021-09-25 00:18:22 +03:00
Jussi Pakkanen fee5cb697c
Merge pull request #9167 from dcbaker/submit/meson-main-type-checking
Add type annotations and type checking to meson main
2021-09-24 23:40:52 +03:00
Dylan Baker 68c23a6120 Add option to to transpile Cython to C++
This patch adds a new meson built-in option for cython, allowing it to
target C++ instead of C as the intermediate language. This can, of
course, be done on a per-target basis using the `override_options`
keyword argument, or for the entire project in the project function.

There are some things in this patch that are less than ideal. One of
them is that we have to add compilers in the build layer, but there
isn't a better place to do it because of per target override_options.
There's also some design differences between Meson and setuptools, in
that Meson only allows options on a per-target rather than a per-file
granularity.

Fixes #9015
2021-09-24 22:56:46 +03:00
Dylan Baker 9795323b86 pylint: check for duplicate imports
I ran into one of these from LGTM, and it would be nice if pylint could
warn me as part of my local development process instead of waiting for
the CI to tell me.
2021-09-24 10:36:05 -07:00
Dylan Baker d661a0cd96 build: use an object rather than a dict for the dep_manifest
This really is more of a struct than a dict, as the types are disjoint
and they are internally handled, (ie, not from user input). This cleans
some things up, in addition I spotted a bug in the ModuleState where the
dict with the version and license is passed to a field that expects just
the version string.
2021-09-24 10:36:05 -07:00
Dylan Baker c8d85575c0 build: Add annotation to dist_Scripts and install_scripts 2021-09-24 09:44:40 -07:00
Dylan Baker 343b40f67a build: add some missing type annotations
So that we can get interpreter/mesonmain.py type safe.
2021-09-24 09:44:40 -07:00
Filipe Laíns af8b55d49b mintro: add installed_plan
Signed-off-by: Filipe Laíns <lains@riseup.net>
2021-09-06 18:10:55 +02:00
Eli Schwartz 10cfc321f8
fix repr for alias_target
It has no command, so you cannot try printing it or it explodes with

IndexError: list index out of range
2021-09-01 15:42:39 -04:00
Dylan Baker 4d7031437c pylint: turn on superflous-parens
We have a lot of these. Some of them are harmless, if unidiomatic, such
as `if (condition)`, others are potentially dangerous `assert(...)`, as
`assert(condtion)` works as expected, but `assert(condition, message)`
will result in an assertion that never triggers, as what you're actually
asserting is `bool(tuple[2])`, which will always be true.
2021-08-31 16:28:54 -04:00
Dylan Baker 8c90140f2b build: add ability to set initial value of EnvironmentVariables
Which is useful as we move the validation out of the the
EnvironmentVariablesObject
2021-08-30 18:02:56 -07:00
Dylan Baker aee2325335 build: Fully annotate EnvironmentVariables 2021-08-30 18:02:56 -07:00
Dylan Baker b791b47c3b build: add annotations for DependencyOverride 2021-08-27 14:49:23 -07:00
Dylan Baker 3a45c5a7ce build: Add type annotations to Target.get_debug_filename 2021-08-20 18:57:19 +02:00
Dylan Baker e938ffb763 build: Add annotations to the CustomTargetIndex class
These are not complete, and are just enough for backends/backends.py
2021-08-20 18:57:19 +02:00
Dylan Baker c9e827a6a1 build: Add a `name` property to CustomTargetIndex
This is needed to make CustomTargetIndex polymorphic with Target derived
classes, and is used in the build module.
2021-08-20 18:57:19 +02:00
Dylan Baker d754ee1a7f build: Fix CustomTarget initializer annotation
the `output` parameter is a string, not an int.
2021-08-20 18:57:19 +02:00
Dylan Baker e08f896802 build: Add a couple of annotations to RunTarget 2021-08-20 18:57:19 +02:00
Dylan Baker cd7d602f33 build: Add type annotations for CustomTarget
Again, this is not complete and is just enough for backend.py. Again,
typing these is complicated massively by the layering violations in the
Target classes and the interpreter.
2021-08-20 18:57:19 +02:00
Dylan Baker b7d5ecc298 build: type get_import_filenames 2021-08-20 18:57:19 +02:00
Dylan Baker f21c50223b build: Add some type annotations to BuildTarget
This is not complete, it's just enough for backend/backend.py. A more
completely typing would be more difficult, especially whithout
untangling the layering violation between the build targets and the
interpreter.
2021-08-20 18:57:19 +02:00
Dylan Baker 225022abf6 build: Add type annotations for ExtractedObjects 2021-08-20 18:57:19 +02:00
Dylan Baker 65d5d9e20c build: Add missing annotations for Build.get_* methods
The underlying attributes are typed properly, but the getters are not
2021-08-20 18:57:19 +02:00
Dylan Baker 3467cf956c build: fix annotation for Build.targets
This really does need to be an OrderedDict, not a MutableMapping, as
there are consumers in the backend that need dictionary only methods.
2021-08-20 18:57:19 +02:00
Dylan Baker e3b2d4ac8b build: add annotation for build.postconf_scripts 2021-08-20 18:57:19 +02:00
Xavier Claessens 8c5aa031b5 Add install tags
Fixes: #7007.
2021-08-17 15:19:18 -04:00
Dylan Baker 6a83f8b9cb build: store global and project args per-machine even when not cross compiling
The problem is what happens in this case:
```meson
add_project_arguments('-DHOST', language : 'c', native : false)
add_project_arguments('-DBUILD', langauge : 'c', native : true)
```

The original meson behavior was that in an host == build configuration
only the `native : false` would be applied. This doesn't really make
sense as in that case the build machine is the host machine, so it is
both the native and non-native machine at once. We changed this so that
the both would be applied in a host == build configuration, but this is
a behavioral change, and needs to be reverted.

Fixes: #9037
2021-08-09 19:44:49 -04:00
Dylan Baker 8a7451e051 build: add a few annotations
I was debugging this code, these were trivial, so I added them.
2021-08-09 19:44:49 -04:00
Dylan Baker bc31c23074 build: Add annotation to CustomTargetIndex.get_subdir 2021-08-03 14:03:33 -07:00
Dylan Baker daf63fc377 build: Add get_subdir() to GeneratedList
It needs this to match the behavior of CustomTarget and
CustomTargetIndex, the later of which doesn't have a subdir attribute,
just `get_subdir()`
2021-08-03 14:03:33 -07:00
Marc-André Lureau 23ea9feee3 build: learn to take CustomTargetIndex as custom_target command
Fix ERROR: Argument <CustomTargetIndex:...>[0]> in "command" is invalid.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-07-27 11:26:05 -07:00
Simon Ser 1f3adc4dbe Add feed arg to custom_target() 2021-06-29 20:54:13 +03:00
Daniel Mensinger 8f7343831b refactor: Refactor BothLibraries logic
This commit introduces a new type of `HoldableObject`: The
`SecondLevelHolder`. The primary purpose of this class is
to handle cases where two (or more) `HoldableObject`s are
stored at the same time (with one default object). The
best (and currently only) example here is the `BothLibraries`
class.
2021-06-26 12:49:35 +02:00
Daniel Mensinger 3f889606c7 Split compiler detection from Environment
This moves all the compiler detection logic into the new
compilers.detect module. This dramatically reduces the size
and complexity of Environment.
2021-06-25 19:34:48 +02:00
Jussi Pakkanen 6e0a0fd1da
Merge pull request #8884 from dcbaker/submit/type-and-annotate-install-functions
Add annotations for the various install_* functions
2021-06-23 01:00:59 +03:00
Daniel Mensinger 0c4dd81c4d
fix: Handling BothLibraries objects (fixes #8907) 2021-06-22 21:09:19 +02:00
Jussi Pakkanen 7588dbc587
Merge pull request #8900 from bonzini/extract-objects-docs
extract_objects: fixes, tests and documentation for using the result in a custom_target
2021-06-22 20:39:58 +03:00
Dylan Baker d636b92c1a install_*: FileMode doesn't need to be None
There's no reason to allow None into the backend, it already has code to
check that all of the values of the FileMode object are None, so let's
use that, which is much simpler all the way down.
2021-06-22 09:13:41 -07:00
Dylan Baker f2ad5e377e backend: Headers.install_subdir is allowed to be None
But we don't properly handle that.
2021-06-22 09:12:54 -07:00
Paolo Bonzini bd75e0398f extract_objects: skip headers when building custom_target command line
As seen in the testcase, passing objects to custom_target does not work
if headers are passed extract_objects(), or if extract_all_objects() is used
and the sources include any header files.  To fix this, use the code that
already exists for unity build to filter out the nonexistent ".h.o" files.
This already gives for free the handling of genlist, which was mentioned
in a TODO comment.
2021-06-22 15:56:46 +02:00
Daniel Mensinger 7c757dff71 holders: Fix the remaining code to respect the holder changes 2021-06-18 23:48:33 +02:00
Daniel Mensinger 34c28dc92c holders: remove unholder 2021-06-18 23:48:33 +02:00
Daniel Mensinger 84a3e459a8 holders: Introduce BothLibraries 2021-06-18 23:48:33 +02:00
Daniel Mensinger 66b32a4591 holders: Introduce HoldableObject 2021-06-18 23:48:33 +02:00
Daniel Mensinger 850f64b9ab build: textwrap.dedent() some strings 2021-06-18 23:48:33 +02:00
Dylan Baker 6d52ddf3c7 build: add type annotations for the IncludeDirs object 2021-06-18 09:52:23 -07:00
Dylan Baker a65429d57b build: Fully annotate GeneratedList 2021-06-15 12:48:53 -07:00
Dylan Baker 4e7f59d70d build: Generator add missing annotations 2021-06-15 12:48:53 -07:00
Dylan Baker 0698a50c00 build: cleanup Generator.proccess_files a bit 2021-06-15 12:48:53 -07:00
Dylan Baker c422621317 interpreterobjects|build: use typed_kwargs for generator.process 2021-06-15 12:48:53 -07:00
Dylan Baker 5952dc9818 interpreter|build: use typed_pos_args and unholder in the interpreter
For generator.process_files. Just cleaner and nicer
2021-06-15 12:48:53 -07:00
Dylan Baker 2043461b87 build: Pass name of generator to initializer
It's really a property of the Generator what name to use, not something
that should be passed to each call to process files.
2021-06-15 12:48:53 -07:00
Dylan Baker 35bdaada1d interpreter|build: Do Generator keyword argument checking in the interpreter
For qt we already have all of the necissary checking in place. Now in
the interpreter we have the same, the intrperter does all of the
checking, then passed the arguments to the Generator initializer, which
just assigns the passed values. This is nice, neat, and clean and fixes
the layering violatino between build and interpreter.
2021-06-15 12:48:53 -07:00
Dylan Baker d2c1ab40a0 interpreter|build: Pass just the executable down to Generator
This requires that the interpreter has done the validation, which it now
does at all callsites. This simplifies the Generator initializer.
2021-06-15 12:48:53 -07:00
Dylan Baker 6eff0c3f8c build: fix type annotations fo project_*_args
These are Dict[str, Dict[str, List[str]]], unlike global arguments
because they must store the information per subproject
2021-06-08 11:00:55 +02:00
Eli Schwartz 3eb1da1fa2
condense lines 2021-06-07 16:51:47 -04:00
Eli Schwartz 2c71b63e77
more f-strings everywhere
pyupgrade didn't catch many .format() methods which were too complex
(e.g. multiline or applied to templates rather than string literals)
2021-06-07 16:51:47 -04:00
Dylan Baker b9f33c2380 Add C compiler when using Cython
Since cython transpiles to C.
2021-06-07 09:17:39 -07:00
Dylan Baker 4d1cbd1b8a compilers: Add cython file suffixes 2021-06-07 09:16:19 -07:00
Dylan Baker b6eb5c231c build: Add type annotations for Generator
They're not 100% complete, but it's mostly there.
2021-06-07 09:15:09 -07:00
Dylan Baker ff0fd7d44c build: Add a type annotation to CustomTarget 2021-06-04 20:10:05 -07:00
Dylan Baker 145d92aa27 build: Use ImmutableSetProtocol for lru_cache'd value
To avoid mutation if possible.
2021-06-02 15:53:17 -07:00
Dylan Baker cfb847a1f0 build: use typing.Mapping for lru_cached dicts
Thankfully the typing module provides us an immutable protocol for
mappings, so we don't have to write one ourselves.
2021-06-02 15:53:17 -07:00
Dylan Baker 113a159514 use an immutable list for an lru_cached functions
When mutable items are stored in an lru cache, changing the returned
items changes the cached items as well. Therefore we want to ensure that
we're not mutating them. Using the ImmutableListProtocol allows mypy to
find mutations and reject them. This doesn't solve the problem of
mutable values inside the values, so you could have to do things like:

```python
ImmutableListProtocol[ImmutableListProtocol[str]]
```

or equally hacky. It can also be used for input types and acts a bit
like C's const:

```python
def foo(arg: ImmutableListProtocol[str]) -> T.List[str]:
    arg[1] = 'foo'  # works while running, but mypy errors
```
2021-06-02 15:53:17 -07:00
Dylan Baker a5b43aa16c Add a helper to simplify the usage of PerMachineDefaultable 2021-05-28 09:26:38 -04:00
Dylan Baker d2e7bdccd7 build: Use a PerMachineDefaultable for (project|global)[_link]_args 2021-05-28 09:26:38 -04:00
Dylan Baker f9a9faba92 build: Use a PerMachineDefaultable for dependency override cache
This way if we're doing a host == build configuration then the build and
host dependencies will be stored correctly.
2021-05-28 09:26:38 -04:00
Dylan Baker 76768eaf20 build: fix type annotation import 2021-05-28 09:26:38 -04:00
Dylan Baker 189545c2a8 build: annotate can_compile_remove_sources 2021-05-19 23:28:17 +03:00
Dylan Baker 0fd907a8cc build: Simplify BuildTarget.process_sourcelist 2021-05-19 23:28:17 +03:00
Dylan Baker 7bd7d1cd73 interpreter: Pass unholdered sources into BuildTarget
The build level shouldn't be deal with interpreter objects, by the time
they leave the intpreter they should be in the Meson middle layer
representaiton
2021-05-19 23:28:17 +03:00
Xavier Claessens 3c64ecaf86 pkgconfig: Add support for CustomTarget objects in generator
Fixes: #8618.
2021-04-19 17:57:34 +03:00
Jussi Pakkanen 68dda2a241 Xcode: fix generators that take custom targets as inputs. 2021-04-18 19:19:29 +03:00
Jussi Pakkanen 86fb916d33 Xcode: Fix source generation. 2021-04-10 20:33:51 +03:00
Xavier Claessens 3fb9311d10 Remove ConfigureFile and ConfigureFileHolder
They are not used anywhere.
2021-03-26 23:39:01 +02:00
Xavier Claessens 1be13710ad
environment(): Allow stacking append() and prepend() (#8547)
* environment(): Allow stacking append() and prepend()

* Update docs/markdown/Reference-manual.md

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
2021-03-23 17:48:17 +02:00
Dylan Baker 40e3577a65 split program related classes and functions out of dependencies
Dependencies is already a large and complicated package without adding
programs to the list. This also allows us to untangle a bit of spaghetti
that we have.
2021-03-19 08:47:10 -04:00
Xavier Claessens 598e968993 Add `meson devenv` command and meson.add_devenv() 2021-03-16 09:00:50 -04:00
Xavier Claessens e0fcccc6e2 EnvironmentVariables: Simplify and annotate 2021-03-16 09:00:50 -04:00
Eli Schwartz 6a0fabc647
mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
2021-03-04 17:16:11 -05:00
Eli Schwartz 4340bf34fa
various python neatness cleanups
All changes were created by running

"pyupgrade --py3-only --keep-percent-format"

and committing the results. I have not touched string formatting for
now.

- use set literals
- simplify .format() parameter naming
- remove __future__
- remove default "r" mode for open()
- use OSError rather than compatibility aliases
- remove stray parentheses in function(generator) scopes
2021-03-04 17:11:26 -05:00
Xavier Claessens a2cae005ec build: Fix backend type 2021-03-04 11:33:22 -05:00
Jason Woodward 50af09de03 install_man locale support
Rather than having to manually build the locale aware man paths with

`install_data('foo.fr.1', install_dir: join_paths(get_option('mandir'), 'fr', 'man1'), rename: 'foo.1')`

Support doing

`install_man('foo.fr.1', locale: 'fr')`
2021-02-27 14:35:23 +02:00
Matthias Klumpp 4e5efd3897
Allow custom target output to be processed by generators 2021-02-25 20:53:41 +02:00
Xavier Claessens 2fabd4c7dc minstall: Add --skip-subprojects option
By default all subprojects are installed. If --skip-subprojects is given
with no value only the main project is installed. If --skip-subprojects
is given with a value, it should be a coma separated list of subprojects
to skip and all others will be installed.

Fixes: #2550.
2021-02-22 23:03:55 +02:00
Jussi Pakkanen a855bcab1c
Merge pull request #8162 from dcbaker/wip/2021-01/rust-module-bindgen
Add a wrapper to the rust module for bindgen
2021-02-07 16:57:39 +00:00
Jussi Pakkanen 034b81a09f
Merge pull request #8288 from bonzini/test-setup-exclude-suites
introduce add_test_setup(exclude suites: ...) keyword argument
2021-02-07 12:03:10 +00:00
Dylan Baker 6a568fa9ad build: Add type annotations for CustomTarget constructor
which are needed in the rust module for bindgen support.
2021-02-06 10:27:04 -08:00
Dylan Baker 5f624657a0 Add a method to IncludeDirs to convert to string list
I'm going to use this in the rust module as well, so having a single
source of truth is useful.
2021-02-06 10:27:04 -08:00
Xavier Claessens 522392e755 run_target: Add env kwarg
Re-implement it in backend using the same code path as for
custom_target(). This for example handle setting PATH on Windows when
command is an executable.
2021-02-05 17:53:09 -05:00
Paolo Bonzini c7c2bc8db1 interpreter, mtest: introduce add_test_setup(exclude_suites: ...)
This new keyword argument makes it possible to run specific
test setups only on a subset of the tests.  For example, to
mark some tests as slow and avoid running them by default:

    add_test_setup('quick', exclude_suites: ['slow'], is_default: true)
    add_test_setup('slow')

It will then be possible to run the slow tests with either
`meson test --setup slow` or `meson test --suite slow`.
2021-02-02 11:23:33 +01:00
Paolo Bonzini 41d1331349 build: fix flake8 2021-02-02 10:06:52 +01:00
Jeff Moguillansky 4f8cecca97 build: add function get_build_targets to Build class
Add function to Build class to get targets of type BuildTarget
Update xcode backend to call get_build_targets when iterating over targets.
This resolves crash in xcode backend when using custom targets:

AttributeError: ‘CustomTarget’ object has no attribute ‘objects’
2021-01-30 11:30:56 +00:00
Xavier Claessens 0626465ea8 Fix executable as script on Windows
On Windows this would fail because of missing DLL:
```
mylib = library(...)
exe = executable(..., link_with: mylib)
meson.add_install_script(exe)
```

The reason is on Windows we cannot rely on rpath to find libraries from
build directory, they are searched in $PATH. We already have all that
mechanism in place for custom_target() using ExecutableSerialisation
class, so reuse it for install/dist/postconf scripts too.

This has bonus side effect to also use exe_wrapper for those scripts.

Fixes: #8187
2021-01-30 09:51:06 +00:00
Xavier Claessens 633264984b custom_target: Add env kwarg 2021-01-27 09:00:54 -05:00
Dylan Baker bff0b41525 rust: Accept generated sources for main.rs
There are still caveats here. Rust/cargo handles generated sources by
writing out all targets of a single repo into a single output directory,
setting a path to that via a build-time environment variable, and then
include those files via a set of functions and macros. Meson's build
layout is naturally different, and ninja makes working with environment
variables at compile time difficult.

Fixes #8157
2021-01-19 10:14:10 -08:00
Dylan Baker 3ae115b57a Replace NinjaBackend is_rust_target with build.uses_rust
we have two functions to do the exact same thing, and they're basically
implemented the same way. Instead, let's just use the BuildTarget one,
as it's more generally available.
2021-01-19 10:12:38 -08:00
Dylan Baker e36aca42d0 build/interpreter: Split InstallDir to fix layering violation
Currently InstallDir is part of the interpreter, and is an Interpreter
object, which is then put in the Build object. This is a layering
violation, the interperter should have a Holder for build data. This
patch fixes that.
2021-01-13 13:32:48 -08:00
Dylan Baker 59328aba29 build: Add some type annotations 2021-01-13 13:32:48 -08:00