Commit Graph

795 Commits

Author SHA1 Message Date
Eli Schwartz 9e8a3b9cbd when generating optional utility targets in ninja, skip existing aliases too
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-05 12:33:17 -08:00
Dylan Baker 2d349eae8c
pylint: enable the set_membership plugin
Which adds the `use-set-for-membership` check. It's generally faster in
python to use a set with the `in` keyword, because it's a hash check
instead of a linear walk, this is especially true with strings, where
it's actually O(n^2), one loop over the container, and an inner loop of
the strings (as string comparison works by checking that `a[n] == b[n]`,
in a loop).

Also, I'm tired of complaining about this in reviews, let the tools do
it for me :)
2022-11-30 16:23:29 -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
Dylan Baker 9e9a9ac4de backend/ninja: replace ` ` with `_` in rust crate-names
Because spaces aren't allowed and result in compilation failures
2022-11-17 19:07:15 -05:00
Eli Schwartz 21f86fa902
Revert "backends/ninja: run `ranlib -c $out` when using the apple ar"
This reverts commit bdc6f243e9.

This is part of #10628 and needs to be reverted, as it breaks other
things.

See https://github.com/mesonbuild/meson/pull/10628#issuecomment-1230560772
2022-10-31 23:22:07 -04:00
Xavier Claessens e04bce3f04 Not all compilers support depfile 2022-10-24 14:52:13 +02:00
Xavier Claessens 65590e6e4b Add cc.preprocess() method for c-like compilers
This introduce a new type of BuildTarget: CompileTarget. From ninja
backend POV it is the same thing as any other build target, except that
it skips the final link step. It could be used in the future for
transpilers too.
2022-10-23 12:21:46 +02:00
Xavier Claessens 5e0f22896f Compilers: Add a preprocessor mode for clike compilers
A compiler object can now return a list of "modes", they are new
compiler object specialized for a specific task.
2022-10-23 12:21:46 +02:00
Xavier Claessens af6d70a176 ninja: Simplify getting rule name from compiler object 2022-10-18 16:32:03 +02:00
Tatsuyuki Ishi 673dca5c07 Add b_thinlto_cache for automatically configuring incremental ThinLTO 2022-10-13 04:18:13 -04:00
Xavier Claessens e1db50d4d9 compilers: Cleanup a bit languages/suffixes lists
Use set where order does not matter, fix is_source() to really mean only
source suffixes.
2022-09-27 11:15:07 -04:00
Xavier Claessens fa254229b7 ninjabackend: Fix get_target_generated_sources() return type
Type annotation, documentation string, and implementation were doing 3
different things. Change implementation to match type annotation which
makes the most sense because it match what get_target_sources() does.

All callers only use keys from the returned dictionary any way, but
that's going to change in next commits.
2022-09-26 15:39:06 -04:00
Dylan Baker 4da14918cd pylint: enable consider-using-in 2022-09-19 20:57:52 -04:00
Dylan Baker 188c552dcf pylint: enable use-maxsplit-arg
This finds a bunch of places where we can do more efficient string
splitting.
2022-09-19 20:57:52 -04:00
Eli Schwartz cc5ef6478f
compilers: perform targeted imports for detect
Only import the ones we need for the language we are detecting, once we
actually detect that language.

This will allow finally dropping the main imports of these files in a
followup commit.
2022-09-19 15:19:00 -04:00
Eli Schwartz 0a9048e554
compilers: don't use instance checks to determine properties
In various situations we want to figure out what type of compiler we
have, because we want to know stuff like "is it the pgi one", or "does
it use msvc style". The compiler object has this property already, via
an API specifically designed to communicate this info, but instead we
performed isinstance checks on a compiler class.

This is confusing and indirect, and has the side effect of requiring
more imports everywhere. We should do away with it.
2022-09-19 15:18:59 -04:00
Dylan Baker 9a645c1c5a rust: Generate a rust-project.json file when rust targets are present
When at least one Rust target is present, we now generate a
rust-project.json file, which can be consumed by rust-analyzer. This is
placed in the build directory, and the editor must be configured to look
for this (as it is not a default search path).
2022-09-12 18:51:27 -04:00
Konstantin Kharlamov 251113fa67 backend/ninja: omit --backend when regenerating build dir
Currently a cosmetic bug is present: once a build dir was regenerated,
meson would start showing:

  User defined options
    backend: ninja

This is not true as user have not defined the option, it is default.
Fix this by omitting the `--backend ninja` parameter from "regenerate"

In my tests this does not affect the situation when one specifies
`--backend ninja` explicitly, it still shows the backend as user-defined
after reconfiguration.

Fixes: https://github.com/mesonbuild/meson/issues/10632
2022-09-02 16:04:08 -04:00
Dylan Baker c02d7fe119 backend/ninja: properly track objects extracted from fortran sources
We need this to ensure that .mod files are created before we start
compiling, and to ensure that the proper include directory arguments are
generated.
2022-08-24 22:50:35 -04:00
Dylan Baker bdc6f243e9 backends/ninja: run `ranlib -c $out` when using the apple ar
Apple's AR is old, and doesn't add externed symbols to the symbol table,
instead relying on the user calling ranlib with -c. We need to do that
for the user
2022-07-25 15:36:59 -07:00
Eli Schwartz 5b2f921d52
ninja depscanner: handle C++ sources named capital C
In commit 4ca9a16288 we added unreliable
support (it warns you if you try it) for gcc-compatible treatment of
uppercase-C files being C++ instead of C. In order to handle it
correctly, we needed to evaluate can-compile by special-casing "C" to
avoid lowercasing it for comparisons.

This didn't cover all cases where we check if "C" is a C++ language
file. We also straight-up check the language of a file (rather than
working backwards to see if a C++ compiler can compile it) when doing
module scanning, and this needs to special-case "C" as well.

We also had one case where we only checked lowercase fortran extensions,
but not lowercase C++ extensions. While we are at it, use lowercase for
C++ as well, except the "C" special case.

Fixes #10629
2022-07-25 16:59:41 -04:00
Justin Blanchard ec388fe7c2 ar linker: detect the "osx ld" case (where generating thin archives won't work) based on host OS, not build OS. 2022-07-21 22:00:00 -07:00
Ty c7eb601e07 Fix finding of Visual studio path in mingw64
Ninja backend will fail to find the vs dep dependency
prefix string in a mingw64 environment. This change
simply updates the regex to be able to capture mingw64's unique
file separation pattern.
2022-07-16 00:31:45 +03:00
Jussi Pakkanen df4714be95
Merge pull request #10464 from rtbo/fix_generated_deps
add D generated files to order-only deps
2022-06-19 22:16:20 +03:00
Michael Mera 9b21428006 fix parameter expansion in several error messages
At several points in the code base, f-strings are not correctly expanded
due to missing 'f' string prefix. This fixes all the occurrences I could
find.
2022-06-17 12:16:42 -04:00
Paolo Bonzini dae986073d take override_option('unity=...') into account when allowing extract_objects()
A single target could be picked for unity build, and in that case
extract_objects() should not be allowed.

Likewise for the opposite case, where extract_objects() should be allowed
if unity build is disabled for a single target.  A test that covers that
case is added later.
2022-06-14 10:11:22 -07:00
Eli Schwartz f3ba24f289
ninja backend: generate additional meta-rules for test/benchmarks targets
'meson-test-prereq' now depends on any targets that were formerly added
directly to 'all'. Behavior is not changed -- the all target still
depends on this other meta-rule, and thus indirectly depends on all
targets it used to depend on.

It is now possible to build just the targets needed for the testsuite
and then e.g. run `meson test --no-rebuild`.
2022-06-13 17:19:34 -04:00
Eli Schwartz a49cd00d64 treewide: various cleanups to move imports for mypy into typechecking blocks
Along the way, add __future__ annotations where lacking.
2022-06-10 09:15:48 -04:00
Eli Schwartz 6aeb8792ca flake8: remove import that was never used
Introduced via commit 0d0a4fa0fe, probably
in the course of heavy rebasing.
2022-06-10 09:15:48 -04:00
Remi Thebault e9576a4361
use compilers.lang_suffixes to determine lang 2022-06-09 21:19:56 +02:00
Dylan Baker 3dec0db06d backends/ninja: Add missing type annotation 2022-06-08 23:19:09 +03:00
Remi Thebault 1d15c6f502
add D generated files to order-only deps 2022-06-05 01:35:02 +02:00
Dylan Baker a2def550c5 modules: move gnome targets into gnome module
They're not used outside of the gnome module anyway, and they create
some annoying potentials for dependency loops
2022-06-01 22:49:10 -04:00
Eli Schwartz 38c00feb9d
relax target name restrictions to cater to internal use
We don't want to allow targets that conflict with:
- our aliased meson-* targets for phony commands
- any meson-*/ directories we create for internal purposes

We do want to allow targets such as:
- our own meson-*.X manpages

There are a couple routes we could take.

Using a better restriction, such as `meson-internal__*`, is trivially
done for our aliased targets, but changing directory names is...
awkward. We probably cannot do this, and doing the former but not the
latter is not very useful.

We could also carefully allow patterns we know we won't use, such as
file extensions, but which the manpages need, which works for our
directories and for many aliased targets, but run_target() is
user-specified and can be anything.

Use a hybrid approach to cover both use cases. We will now allow target
names that fulfill *all* the following criteria:
- it begins with "meson-"
- it doesn't continue with "internal__"
- it has a file extension
2022-05-31 17:49:29 -04:00
Eli Schwartz dd2f1c4c57
ninja backend: simplify generation of phony targets
Every phony target has a special indirection rule created because ninja
is bad at deleting generated outputs and tries to delete phony outputs
too.

Instead of invoking this as a separate helper post-creation function to
create the alias, wrap NinjaBuildElement and create it behind the
scenes. This simplifies target naming and means one less line at every
single use site.
2022-05-31 17:49:29 -04:00
Jussi Pakkanen eef51fa3d6 Add some scaffolding needed for C++ modules in GCC.
Further work pending GCC bug #105467 and/or Ninja bug #1962.
2022-05-06 18:48:15 +03:00
Ben Brown 20ac070fca Fix typo in comment 2022-04-14 14:43:50 -04:00
Eli Schwartz 8ae2bf5a9e
allow RunTarget to skip wrapping due to env
Forcing serialization on when writing out the build rule makes very
little sense. It was always "forced" on because we mandated a couple of
environment variables due to legacy reasons.

Add an attribute to RunTarget to say that a given target doesn't *need*
those environment variables, and let ninja optimize them away and run
the command directly if set.
2022-03-31 22:52:31 -04:00
Xavier Claessens 90310116ab Replace backend.get_option_for_target() with target.get_option()
That method had nothing specific to the backend, it's purely a Target
method. This allows to cache the OptionOverrideProxy object on the
Target instance instead of creating a new one for each option lookup.
2022-03-29 16:10:28 -04:00
Tristan Partin c65abc568c Add support for cython_args
cython_args was previoously ignored by Meson.
2022-03-23 15:44:01 -04:00
Eli Schwartz 7b78c6b41b ninja backend: do not fatally error on compdb failure
We print a warning if a compilation database isn't successfully
generated, which is good, because that gives some visibility in case the
user really wanted to use the compdb. But warnings default to being
fatal with --fatal-meson-warnings, which is not so good, because this
isn't a very important warning at all, and we'd rather not error out in
such cases when building works fine and a random bonus IDE feature
doesn't work.

Mark this particular warning as non-fatal.

Fixes side issue in https://github.com/mesonbuild/wrapdb/pull/343#issuecomment-1074545609
2022-03-23 15:46:01 +05:30
Xavier Claessens 86aaac8e42 backends: Stop separating base and compiler options
Since OptionKey is used we can mix all options together in a single
dictionary. That's already what we do in coredata.options.
2022-03-22 17:20:48 -04:00
Tristan Partin 39f1d52e4a Add ability to add resources to jars
Previously Meson lacked the ability to add resources to jar files.

Fixes #9945
2022-03-22 13:21:26 +02:00
Dylan Baker 9b83fc5ece ninja: fix handling of rust structured_sources in rare case
In the even that all of the inputs are generated, and they're all
generated into the same folder, and there are no subfolders, we would
fail to correctly handle all of the files after the main file. Let's fix
that.t
2022-03-21 11:26:52 -07:00
Dylan Baker f9445300b3 structured_sources: fix subdir handling
We currently don't handle subdirectories correctly in
structured_sources, which is problematic. To make this easier to handle
correctly, I've simply changed `structured_sources` to only use Files
and not strings as an implementation detail.
2022-03-18 19:46:24 -07:00
Dylan Baker 0d0a4fa0fe backends/ninja: Add support for structured sources with rust 2022-03-07 12:33:33 -08:00
Dylan Baker da2cdacb28 backend/ninja: add rules to copy files to the build dir 2022-03-07 12:33:33 -08:00
Xavier Claessens 01e92dc543 Fix default install tag for shared lib symlinks
Versioned shared libraries should have .so file in devel, .so.1 and
.so.1.2.3 in runtime.

Fixes: #9811
2022-03-07 09:27:02 -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
Alyssa Ross 3596b6b19a ninjabackend: fix rust program names with dashes
This substitution matches the behaviour of rustc[1] when inferring
crate name based on file name.

[1]: 4e8fb743cc/compiler/rustc_session/src/output.rs (L88)
2022-02-10 15:05:37 -08:00