Commit Graph

660 Commits

Author SHA1 Message Date
Dylan Baker e268d9f137 build: Add a found method to Executable
Again, this is necessary for polymorphism with ExternalProgram
2023-01-10 09:53:22 -08:00
Dylan Baker 1f90873844 build: Add a get_path method to Executable
This is needed to make Executable Polymorphic with ExternalProgram. This
can happen when a build program overrides a lookup.
2023-01-10 09:53:22 -08:00
Paolo Bonzini b3fc3cd6b5 add objects keyword argument to declare_dependencies 2023-01-04 09:44:32 -08:00
Paolo Bonzini 8d2940024b allow passing generated objects in the "objects" keyword argument
Generated objects can already be passed in the "objects" keyword argument
as long as you go through an extract_objects() indirection.  Allow the
same even directly, since that is more intuitive than having to add them
to "sources".

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2023-01-04 09:44:32 -08: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
Eli Schwartz 100456de07
fix broken fs.copyfile function that crashed if you tried to use it
At least, if you tried to use it when passing an install_dir. Because
T.Sequence is horrible and we should never use it, and the annotations
are a lie that produces bugs.

So, fix the annotations on CustomTarget to never allow this to happen
again, and also fix the function too. Move some definitions elsewhere
inline to satisfy the linter.

Fixes #11157
2022-12-11 18:28:39 -05:00
Eli Schwartz cbf4496434
simplify install_tag handling according to the accepted API
There are two problems here: a typing problem, and an algorithm problem.

We expect it to always be passed to CustomTarget() as a list, but we ran
list() on it, which became horribly mangled if you violated the types
and passed a string instead. This caused weird*er* errors and didn't
even do anything. We want to do all validation in the interpreter,
anyway, and make the build level dumb.

Meanwhile we type it as accepting a T.Sequence, which technically
permits... a string, actually. This isn't intentional; the point of
using T.Sequence is out of a misguided idea that APIs are supposed to be
"technically correct" by allowing "anything that fulfills an interface",
which is a flawed concept because we aren't using interfaces here, and
also because "technically string fulfills the same interface as a list,
if we're talking sequences".

Basically:
- mypy is broken by design, because it typechecks "python", not "what we
  wish python to be"
- we do not actually need to graciously permit passing tuples instead of
  lists

As far as historic implementations of this logic go, we have formerly:
- originally, typeslistified anything
- switched to accepting list from the interpreter, redundantly ran list()
  on the list we got, and mishandling API violations passing a string
  (commit 11f9638035)
- switched to accepting anything, stringlistifying it if it was not
  `None`, mishandling `[None]`, and invoking list(x) on a brand new list
  from stringlistify (commit 157d438835)
- stopped stringlistify, just accept T.List[str | None] and re-cast to
  list, violates typing because we use/handle plain None too
  (commit a8521fef70)
- break typing by declaring we accept a simple string, which still
  results in mishandling by converting 'foo' -> ['f', 'o', 'o']
  (commit ac576530c4)

All of this. ALL of it. Is because we tried to be fancy and say we
accept T.Tuple; the only version of this logic that has ever worked
correctly is the original untyped do-all-validation-in-the-build-phase
typeslistified version.

Let's just call it what it is. We want a list | None, and we handle it too.
2022-12-11 18:28:38 -05:00
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 67da2ad0fb
pylint: enable simplifiable-if-statement 2022-11-30 07:01:22 -05:00
David Robillard e85138fcc8 Fix various spelling errors
Found with codespell.
2022-11-24 15:17:23 -05:00
Dylan Baker e45367169f build: fix annotations of BuildTarget derived classes
Which thinks `sources` should be `List[File]`, but they should be
`List[SourceOutputs]`
2022-11-17 19:07:15 -05:00
Eli Schwartz 0d3be23377 build: use the unified pickle loader to handle more edge cases
We have divergent implementations of loading a pickled *.dat file. The
Build class loader has a better error message. But the generic loader
handles TypeError and ModuleNotFoundError. Merge the implementations,
and use it for Build as well.

Fixes #11051
2022-11-17 12:56:04 -08:00
Eli Schwartz 4533dfc279
Revert "build: don't add targets to link_whole_targets if we took their objects"
This reverts commit c94c492089.

This broke propagated deps as well as PCH in MSVC, and has not been
fixed in time for the final release of 0.64.0, so it needs to be
reverted and then brought back later.

Fixes #10745
Fixes #10975
2022-10-31 23:22:07 -04:00
Xavier Claessens 01ee141339 Add NASM compiler 2022-10-24 11:06:57 +02:00
Jussi Pakkanen 4c2b64188d
Merge pull request #10916 from xclaesse/preprocess
Add cc.preprocess() method
2022-10-23 17:24:46 +03: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
Thomas Li 2761131ff9 BUG: Don't add debug files as targets when not building in debug mode 2022-10-19 11:32:25 -04:00
Dylan Baker df1b95cf2b
pylint: enable consider-merging-isinstance 2022-10-04 00:33:14 -04:00
Xavier Claessens 2dfd952eb9 Move classes used by scripts to their own module
Those classes are used by wrapper scripts and we should not have to
import the rest of mesonlib, build.py, and all their dependencies for
that.

This renames mesonlib/ directory to utils/ and add a mesonlib.py module
that imports everything from utils/ to not have to change `import
mesonlib` everywhere. It allows to import utils.core without importing
the rest of mesonlib.
2022-09-28 19:36: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
Dylan Baker 6f7ea0cc28 pylint: enable use-sequence-for-iteration
This found a couple of places where we *don't* want to use set(), and
want to use list() instead.
2022-09-19 20:57:52 -04:00
Thomas Li a4d5442207 Fix install_subdirs not showing up in intro-install_plan.json 2022-09-06 02:09:38 -04:00
Eli Schwartz af28826c24 flake8: fix missing import
This sort of worked, because it was a typing-only import and this file
isn't actually tested by mypy yet.
2022-08-29 23:32:43 +03:00
Dylan Baker c94c492089 build: don't add targets to link_whole_targets if we took their objects
What happens is this:
 - liba is a convenience static library
 - libb is an installed static library
 - libb links in liba with --link-whole
 - libc links to libb
 - we generate a link line with libb *and* liba, even though libb is a
   strict superset of liba

This is a bug that has existed since the we stopped using link-whole to
combine convenience libraries, and to instead propagate their
dependencies up. For most linkers this is harmless, if inefficient.
However, for apple's ld64 with the addition calling `ranlib -c`, this
ends up causing multiple copies of symbols to clash (I think that other
linkers recognize that these symbols are the same and combine them), and
linking to fail.

The fix is to stop adding libraries to a target's `link_whole_targets`
when we take its objects instead. This is an all around win since it
fixes this bug, shortens linker command lines, and avoids opening
archives that no new symbols will be found in anyway.
2022-08-24 22:50:35 -04:00
Dylan Baker a044f42308 build: add a `uses_fortran()` convenience method 2022-08-24 22:50:35 -04:00
Dylan Baker 741de25462 build: Don't attempt to link-whole with rust convenience libraries
There are two distinct cases here that need to be considered. The first
issue is https://github.com/mesonbuild/meson/issues/10723 and
https://github.com/mesonbuild/meson/issues/10724, which means that Meson
can't actually generate link-whole arguments with rust targets. The
second is that rlibs are never valid candidates for link-whole anyway.
The promotion happens to work because of another bug in the promotion
path (which is fixed in the next commit).
2022-08-24 22:50:35 -04:00
Eli Schwartz 3e73d4d77d
introspection: untangle install_plan implemetation, fix a bunch of wrong ones
Generally plumb through the values of get_option() passed to
install_dir, and use this to establish the install plan name. Fixes
several odd cases, such as:

- {datadir} being prepended to "share" or "include"

- dissociating custom install directories and writing them out as
  {prefix}/share/foo or {prefix}/lib/python3.10/site-packages

This is the second half of #9478
Fixes #10601
2022-08-22 14:15:22 -04:00
Eli Schwartz d395b1a768
fix up some message strings that don't include "setup" in the configure command 2022-08-22 00:23:14 -04:00
Dylan Baker 394f734b1d build: Add a Union alias for all build targets 2022-08-18 21:57:36 -04:00
Dylan Baker 5ca5e0c900 build: actually check for targets with no sources
Do to a bug in which a method, rather than an attribute, was checked
we would never detect that a target had no sources, even though we meant
to. As a result we would never actually error out when a target has no
sources. When fixing the check, I've changed the error to a warning
so that existing projects will continue to build without errors, only
warnings.
2022-08-17 13:44:08 -07:00
Eli Schwartz 00f8ced048
add compilers from extracted objects directly to build targets
In order to reliably link to static libraries or individual object
files, we need to take their languages into account as well. For static
libraries this is easy: we just add the static library's list of
compilers to the build target. For extracted objects, we need to only
add the ones for the objects we use.

But we did this really inefficiently -- in fact, downright terribly. We
iterated over all source files from the extracted objects, then tried to
look up a new compiler for them. Even though the extracted objects
already had a list of compilers! This broke once compilers were made
per-subproject, because while the extracted objects have a reference to
all the compilers it needs (just like static archives do, actually) we
might not actually be able to look up that compiler from scratch inside
the current subproject.

Fix this by asking the extracted objects to categorize all its own
sources and return the compilers we want.

Fixes #10579
2022-08-11 07:12:55 -04:00
Eli Schwartz 37f95303f0
typing: simplify type annotations for libraries
In a bunch of places we need to list various types of libraries
including custom_target outputs, and it gets very long. Use a common
T.Union for this.
2022-08-04 20:06:01 -04:00
David Seifert 11f76c2fc7 cuda: don't inject `-lstdc++` when linking
Fixes: #10570
2022-07-06 14:33:58 -07:00
Eli Schwartz 0703ee0aef
move various unused typing-only imports into type-checking blocks 2022-07-03 14:11:31 -04:00
Eli Schwartz b87067dc8b
fix regression that broke proper warnings about passing subproject as a dep
Regression in commit 7c757dff71.
SubprojectHolder is no longer an ObjectHolder and says so via a TODO:
this means that we have to fiddle with held_object. Yay.
2022-06-16 21:19:06 -04:00
fxxf b7159f4a1a
fix crash when passing invalid inputs as build_target dependencies
The `add_deps` function did not behave correctly when a specified
dependency is not an instance of `dependencies.Dependency`.

Reorder the logic flow to perform this validation first.

Fixes #10468
2022-06-16 21:15:27 -04:00
Paolo Bonzini e4a8f4dbd6 backend: always use the same code to compute the files in ExtractedObjects
Instead of asking the ExtractedObjects, but with a hook back into the backend,
use the existing function in the backend itself.  This fixes using the
extract_objects(...) of a generated source file in a custom_target.

It should also fix recursive extract_all_objects with the Xcode backend.

Fixes: #10394
2022-06-14 10:11:22 -07: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 85f3fc2022 flake8: don't use f-strings for strings without formatting 2022-06-13 13:34:39 +03:00
Sutou Kouhei f6e7cc070e build: CustomTargetIndex.is_linkable_target misses '.dylib'
CustomTarget.is_linkable_target has '.dylib'.

See also 93b1d31af9 that added '.dylib'
to CustomTarget.is_linkable_target but didn't add '.dylib' to
CustomTargetIndex.is_linkable_target.
2022-06-10 02:48:41 -04:00
Eli Schwartz c151988b39
intro-install_plan: fix destinations for build_targets with custom install_dir
There are a couple issues that combine to make the current handling a
bit confusing.

- we call it "install_dir_name" but it is only ever the class default

- CustomTarget always has it set to None, and then we check if it is
  None then create a different variable with a safe fallback. The if is
  useless -- it cannot fail, but if it did we'd get an undefined
  variable error when we tried to use `dir_name`

Remove the special handling for CustomTarget. Instead, just always
accept None as a possible value of outdir_name when constructing install
data, and, if it is None, fall back to {prefix}/outdir regardless of
what type it used to be.
2022-06-09 20:37:26 -04:00
Dylan Baker ac576530c4 build: correctly annotate _process_install_tag helper
Which could receive `None | Sequence[Optional[str]]`, but isn't
annotated for the `None`
2022-06-08 19:18:03 -04:00
Dylan Baker 2c6def856b Revert "build: check for -fno-pic and -fno-pie while we're checking for pic and pie"
This reverts commit 5f02d0d9e1.

Which isn't correct, we have very strange behavior of "force on pie/pic
or let the toolchain do whatever it wants, but you can't turn it off."
2022-06-08 19:18:03 -04:00
Dylan Baker c3ef52311a build: fix types added in CustomTarget.get_target_dependencies
Because everything except ExternalProgram in CustomTarget.sources is a
valid dependency
2022-06-08 23:19:09 +03:00
Dylan Baker c621ab2251 build: Fix type annotations for get_target_dependencies 2022-06-08 23:19:09 +03:00
Dylan Baker 629a9c68e2 build: use inheritance properly for is_internal
Calling `isinstance(self, X)` is an anti-pattern, we should just be using
inheritance for this, letting the `StaticLibrary` override the method, and
having the base class always return `False`.
2022-06-08 23:19:09 +03:00
Dylan Baker f235b814c3 build: Fix annotations for CustomTarget
and fix a bug in the backend that the correct annotations uncover
2022-06-08 23:19:09 +03:00
Dylan Baker d0a0e04c98 build: Store depends in GeneratedList instead of Generator
Since they are actually dependencies out the output not the Generator
itself.

This fixes dependency issues in the ninja backend, allowing Meson to
rebuild more accurately. It also does sometimes in the vs backend, but
there are problems in the vs backend I'm not sure how to solve. The
vsbackend is, itself, so fragile looking I don't want to get too
involved with it.
2022-06-08 23:19:09 +03:00
Dylan Baker c51639b4ff typing: replace ImmutableSetProtocol with typing.AbstractSet
Which does the same thing, but is a builtin and is more accurate
2022-06-08 23:19:09 +03:00