Commit Graph

745 Commits

Author SHA1 Message Date
Dylan Baker 7d0d610045 ast/introspection: make mypy clean 2024-01-08 19:33:05 -05:00
Dylan Baker e991c4d454 Use SPDX-License-Identifier consistently
This replaces all of the Apache blurbs at the start of each file with an
`# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing
uses to be consistent in capitalization, and to be placed above any
copyright notices.

This removes nearly 3000 lines of boilerplate from the project (only
python files), which no developer cares to look at.

SPDX is in common use, particularly in the Linux kernel, and is the
recommended format for Meson's own `project(license: )` field
2023-12-13 15:19:21 -05:00
Eli Schwartz cddf2e9d87 fix another regression in converting build_target kwargs to typed_kwargs
This time we have a case where people are passing non-objects by using
them as str | File, which we never warned about and silently accepted.
If it was passed via custom_target outputs we *would* error out,
interestingly enough. At the backend layer, we just pass them directly
to the linker... which is valid, if we misdetected what's a valid linker
input or people just used funny names. In particular, the mingw
toolchain allows passing a *.def file directly, and some people are
doing that.

If we do want to allow this, we should do it consistently. For now, just
follow the current theme of what's expected, but do so by warning
instead of fatally erroring, for cases where users were able to do it in
the past.
2023-11-13 23:43:42 +02:00
Xavier Claessens d25d8e2772 rust: Fix linking with C libraries (again)
Pass link arguments directly down to linker by using `-C link-args=`
instead of letting rustc/linker resolve `-l` arguments. This solves
problems with e.g. +verbatim not being portable. Note that we also pass
`-l` args as `-Clink-args=-l` because rustc would otherwise reorder
arguments and put `-lstdc++` before `-Clink-args=libfoo++.a`.

However, when building a rlib/staticlib we should still use `-l`
arguments because that allows rustc to bundle static libraries we
link-whole. In that case, since there is no platform specific dynamic
linker, +verbatim works.

This also fix installed staticlib that now bundle uninstalled static
libraries it links to (recursively). This is done by putting them all
into self.link_whole_targets instead of putting their objects into
self.objects, and let rustc do the bundling. This has the extra
advantage that rustc can bundle static libries built with CustomTarget.

Disable bundling in all other cases, otherwise we could end up with
duplicated objects in static libraries, in diamond dependency graph
case.

Fixes: #12484
2023-11-09 16:20:01 -05:00
Xavier Claessens d0a7a203a6 build: Add dummy base class for CustomTarget and CustomTargetIndex
CustomTarget and CustomTargetIndex often have to be special cased
because they are not subclass of BuildTarget. It's easier to introduce a
dummy base class.

This fix recursive functions over link targets that might encouters
libraries built as CustomTarget.
2023-11-09 14:03:18 -05:00
Xavier Claessens 21bf18afa1 build: Simplify recursive function that extracts objects in link_whole 2023-11-09 14:02:02 -05:00
Xavier Claessens 06b9d1e75a rust: proc-macro should be ignored in transitive dependencies
Fixes: #12459
2023-11-02 14:15:09 -04:00
Aditya Vidyadhar Kamath f4d19db25e
Use target.aix_so_archive to decide to archive shared library in AIX
Previously, AIX support was updated to archive shared libraries per AIX
platform conventions, which expect .a files that contain .so files. This
is usually correct, but an edge case occurs for loadable plugins, e.g.
what meson creates for `shared_module()`. A notable example is python
extensions (SciPy, for example).

These should *not* be archived, because the .so file itself needs to be
loaded as a plugin. For example, SciPy fails to import in the python
interpreter.

Handle this by differentiating between plugins and regular libraries,
and only archiving when safe to do so.

Fixes #12219
2023-10-31 19:18:17 -04:00
Dudemanguy e9e098b73e build: improve the warning for executables with the same name
adb1a360b9 added the feature and also the
usual meson-style warning to users that might be using the feature but
were not targeting a new enough meson version. Well unfortunately the
warning both doesn't actually work (it didn't take different directories
into account) and is also really slow because it creates an O(N^2) loop
for checking this.

Instead, rework this by adding an additional set that stores a tuple
containing the target name and its subdirectory. We only add this tuple
if the target is an executable since it is the only time it will be
relevant. After that, simply check if the name + subdir combination
already exists in the set along with the target being executable. If so,
then we execute FeatureNew which may possibly warn. This is a simply
O(1) lookup which is way faster. Fixes #12404.
2023-10-25 23:43:40 +03:00
Dylan Baker 1abdd9dd61 interpreter: use typed_kwargs for build_target.name_suffix 2023-10-17 08:09:06 -07:00
Dylan Baker 9f80a069ec interpreter: use typed_kwargs for build_target.name_prefix 2023-10-17 08:09:06 -07:00
Dylan Baker 507d8bf4d7 interpreter: use typed_kwargs for build_target.build_by_default
This allows a little bit of cleanup in the build layer, since there is
code now that would always be true and we shouldn't do that.
2023-10-17 08:09:06 -07:00
Dylan Baker b2f681c92a build: use a TypedDict for d_features
This allows for better type checking.
2023-10-16 13:28:32 -07:00
Dylan Baker 9b1efa37fd interpreter: use typed_kwargs for build_target.d_import_dirs 2023-10-16 13:28:32 -07:00
Dylan Baker 523a27c6f0 build: Use typed_kwargs for language args
This also moves the repacking into the interpreter, making the build
implementation simpler and removing a layering violation. This also
makes use a defaultdict to remove the need to call `.get()`
2023-10-09 17:33:48 -04:00
Dylan Baker cbca191948 interpreter: Handle BuildTarget.vala_args as Files in the interpreter
Way back in Meson 0.25, support was added to `vala_args` for Files.
Strangely, this was never added to any other language, though it's been
discussed before. For type safety, it makes more sense to handle this in
the interpreter level, and pass only strings into the build IR.

This is accomplished by adding a `depend_files` field to the
`BuildTarget` class (which is not exposed to the user), and adding the
depend files into that field, while converting the arguments to relative
string paths. This ensures both the proper build dependencies happen, as
well as that the arguments are always strings.
2023-10-09 17:33:48 -04:00
Nomura 3cac6ea545 Add env kwarg in generator.process() 2023-10-05 09:59:43 -07:00
Dudemanguy adb1a360b9 build: use suffix when getting target id for exes
When checking target names, meson explictly forbids having multiple
targets with the same name. This is good, but it is strict and it is
impossible to have targets with the same basename and differing suffixes
(e.g. foo and foo.bin) in the same directory. Allow this for executables
by including the suffix (if it exists) in the interal target id. So foo
would be foo@exe and foo.bin would be foo.bin@exe.
2023-10-05 08:43:38 -07:00
Dudemanguy 4fadb2a296 msvc: unify debug filename handling
The MSVC code is extremely confusing, and it turns out it actually
constructs debug (pdb) files names/path independently in separate
places. This is really hard to parse. Instead, refactor it so that the
source of the debug filename is within the target itself
(get_debug_filename). Add a couple of generic methods to retrieve the
full path of the debug filename name in the backend and use that when
needed.
2023-10-05 08:43:38 -07:00
Dylan Baker 937aab09c0 interpreter: handle implib/export_dynamic conflicts in the interpreter
This differentiates export_dynamic being explicitly set to False from it
being unset. This allows us to deprecate explicitly setting
export_dynamic to false, but setting implib. This is already the case in
the other direction, if implib is False but export_dynamic is enabled
then we get a hard error.

This also moves the validation up to the Interpreter and out of the
build level.
2023-09-29 15:52:03 -07:00
Dylan Baker 32be9bd6de add support for vs_module_defs to Executables
fixes: #9254
2023-09-28 14:35:01 -04:00
Dylan Baker 5421c24ea0 fix using a CustomTargetIndex for vs_module_defs
Because `CustomTargetIndex`es don't have a `subdir` property, but they do
implement the `get_subdir()` method
2023-09-28 14:35:01 -04:00
Dylan Baker f4ea89be60 interpreter: use typed_kwargs for build_target(vs_module_defs) 2023-09-28 14:35:01 -04:00
Dylan Baker f485a8cf16 interpreter: use typed_kwargs for static_library(pic) 2023-09-28 11:31:56 -07:00
Dylan Baker 798791baac interpreter: use typed_kwargs for static_library(prelink) 2023-09-28 11:31:56 -07:00
Xavier Claessens c6f33aed2d Rust: Fix proc-macro usage when cross compiling
Force BUILD machine and allow to link with HOST machine.
2023-09-19 13:54:49 -04:00
Xavier Claessens 7592003484 Rust: Prevent linking Rust ABI with C library/executable 2023-09-19 13:54:49 -04:00
Xavier Claessens 10dcd87d00 Rust: Replace rust_crate_type with rust_abi
Meson already knows if it's a shared or static library, user only need
to specify the ABI (Rust or C).
2023-09-19 13:54:49 -04:00
Arsen Arsenović 0af126fec7 install_{data,headers,subdir}: implement follow_symlinks
This permits users who rely on following symlinks to stay on the old
default of following them.
2023-09-13 21:44:40 -04:00
Xavier Claessens b2654b2d43 Fix crash when installing a vala library and python sources
Installing python sources causes the python module to call
create_install_data() before Ninja backends adds extra outputs to Vala
targets.

Target objects are supposed to be immutable, adding outputs that late is
totally wrong. Add extra vala outputs immediately, but be careful
because the main output is only added later in post_init(). Luckily
the base class already puts a placeholder item in self.outputs for the
main filename so we can just replace self.outputs[0] instead of
replacing the whole list which would contain vala outputs at that stage.
This is surprisingly what SharedLibrary was already doing.
2023-09-07 10:56:37 -04:00
Xavier Claessens d5f17bc9ff Rename OptionOverrideProxy to OptionsView and move to coredata
Coredata is where all option handling is done so it makes sense there.
It is a view on a list of options for a given subproject and with
optional overrides. This change prepare for using that view in a more
generic way in the future.
2023-09-07 06:55:07 -04:00
Xavier Claessens 4eb9c84cf9 include_directories: Always add both source and build dirs
Compiler checks were not adding build dir side, which prevents using
headers generated with configure_file().
2023-08-28 20:18:26 -04:00
Xavier Claessens 6f87215f1f build: Simplify import_filename handling
This removes deadcode, vs_import_filename and gcc_import_filename were
not needed.
2023-08-24 18:50:12 -04:00
Charles Brunet 7cbe37ebd9 Add more descriptive description to CustomTarget
Allow modules using CustomTarget to modify the command description used by ninja backend. This result in more precise logs when building a project.
2023-08-18 00:36:49 -04:00
Dylan Baker 9d32302032 interpreter: use typed_kwargs for shared_library(darwin_versions) 2023-08-14 09:55:18 -07:00
Dylan Baker 09bc028c71 interpreter: use typed_kwargs for shared_library(soversion) 2023-08-14 09:55:18 -07:00
Dylan Baker cd676e229b interpreter: use typed_kwargs for shared_library(version) 2023-08-14 09:55:18 -07:00
Eli Schwartz 90ce084144
treewide: automatic rewriting of all comment-style type annotations
Performed using https://github.com/ilevkivskyi/com2ann

This has no actual effect on the codebase as type checkers (still)
support both and negligible effect on runtime performance since
__future__ annotations ameliorates that. Technically, the bytecode would
be bigger for non function-local annotations, of which we have many
either way.

So if it doesn't really matter, why do a large-scale refactor? Simple:
because people keep wanting to, but it's getting nickle-and-dimed. If
we're going to do this we might as well do it consistently in one shot,
using tooling that guarantees repeatability and correctness.

Repeat with:

```
com2ann mesonbuild/
```
2023-08-11 13:41:03 -04:00
Xavier Claessens 926c3a6919 Error when an installed static library links to internal custom target
When an installed static library A links to an internal static library B
built using a custom_target(), raise an error instead of a warning. This
is because to be usable, A needs to contain B which would require to
extract the archive to get its objects files.

This used to work, but was printing a warning and was installing a
broken static library, because we used to overlink in many cases, and
that got fixed in Meson 1.2.0. It now fails at link time with symbols
from the custom target not being defined. It's better to turn the
warning into a hard error at configure time.

While at it, noticed this situation can happen for any internal custom
or rust target we link to, recursively.
get_internal_static_libraries_recurse() could be called on CustomTarget
objects which do not implement it, and even if we did not call that
method, it would still fail when trying to call extract_all_objects() on
it.

Fixes: #12006
2023-08-07 05:44:08 -07:00
Alexandre Janniaux f3b9db9e9d build.py: improve BuildTarget error message
Improve the error message when a build target is assigned as dependency
of another build target, which allows to better pinpoint where the issue
lies on.

In the example that follow, modules/meson.build:294 is in a for loop
creating library targets from an array of dictionary, and doesn't point
to the location where interop_sw_plugin is assigned with vlc_opengl:

Before:

    modules/meson.build:294:17: ERROR: Tried to use a build target as a dependency.
    You probably should put it in link_with instead.

After:

    modules/meson.build:294:17: ERROR: Tried to use a build target vlc_opengl as a dependency of target interop_sw_plugin.
    You probably should put it in link_with instead.

It would probably be best to directly pinpoint where the assignment was
made but it's probably harder so start simple by saying what is
concerned by the error.
2023-08-06 10:24:26 -04:00
Eli Schwartz 404312c6dd do better sanity check for vs_module_defs input
We allow custom_target() but check for it based on hasattr, ever since
the initial implementation way back in the day, in commit
66a6ea984b. This is a bit broken because
various objects might support that but still aren't supposed to work. We
can actually just use isintance checks like we do immediately above,
which are more accurate and avoid crashes on things that aren't even
targets at all, like run_target(). Although custom_target indexes are
actually targets those didn't work either.

Fixes #9648
2023-07-31 11:00:22 -07:00
Dylan Baker 1a182ab599 make 'gui_app' an interpreter only concept
Since it's deprecated anyway, we don't really want to plumb it all the
way down into the build and backend layers. Instead, we can just turn
it into a `win_subsystem` value in the interpreter if `win_subsystem`
isn't already set.
2023-07-25 13:29:08 -04:00
Dylan Baker 1cfbe5279d interpreter: use typed_kwargs for Executable(win_subsystem) 2023-07-25 13:29:08 -04:00
Dylan Baker 67035a181e interpreter: use typed_kwargs for gui_app 2023-07-25 13:29:08 -04:00
Dylan Baker 9faf91d14f build: remove useless method call
This does nothing, so just delete it.
2023-07-24 14:24:15 -04:00
Dylan Baker c8241d79e4 build: remove BuildTarget.need_install
This would be either the value `kwargs['install']`, or `False`. There
isn't any case that `BuildTarget.need_install` handles that
`BuildTarget.install` doesn't handle, if we just initialized it
correctly. So, just set Target.install correctly in the super
initializer, and do away with need_install.
2023-07-24 14:24:15 -04:00
Dylan Baker 01b5581a10 build|interpreter: move main_class to typed_kwargs
Also move it into the Jar class. This is an exclusive Jar keyword
argument, and is only used inside java paths, so there's no reason to
have this in all build targets.
2023-07-20 14:20:46 -04:00
Eli Schwartz 0bb1647fd1
move various bits of type-checking only code to TYPE_CHECKING blocks
Mostly detected with flake8-type-checking. Also quote T.cast() first
arguments, since those are not affected by future annotations.
2023-07-19 18:31:37 -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
Charles Brunet 3e3d5e97c3 Fix display of generator 2023-07-13 13:26:33 -04:00