Commit Graph

1397 Commits

Author SHA1 Message Date
Daniel Stone a0514a7c41 tests: Write out LD_LIBRARY_PATH for built shared libraries
When a test executable references a local shared library, make sure that
we apply the appropriate $LD_LIBRARY_PATH so that the linker can find it
at runtime.

The DT_RUNPATH entry does ensure that the binary references the path to
the shared library build, however the RUNPATH list is only searched
after $LD_LIBRARY_PATH. So if the user has a shared library of the same
name in their $LD_LIBRARY_PATH, this will be the version found and used
for running the test. This is bad if you're trying to use Meson to test
a shared library you're developing and have installed in a local prefix
which is under $LD_LIBRARY_PATH.

Fixes #1635
2022-11-30 11:44:47 -08: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
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
Denis Fortin b78ebc6741 Fix options overrides for vsbackend
Use OptionOverrideProxy instead of pure options.
Closes #10393
2022-11-10 06:19:41 -05:00
Xavier Claessens f5871e240d backends: Try guessing install tag for all installed files
It was only trying to guess install tag, and log missing tags, for files
installed by install_data(). Do it also for all other files, especially
custom_taget() that commonly installs generated headers.
2022-11-02 14:53:35 +02: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 42a7f8e8ef vs backend: Add support for CompileTarget
Since vs backend only support the C compiler, everything else are custom
targets. Convert CompileTarget into a Generator to reuse existing code.
This will be useful in the future to support transpilers, and
assemblers.
2022-10-23 12:21:46 +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
Luke Elliott 4f0452b283 fix: don't set FavorSizeOrSpeed in vs backend if optimization disabled (/Od set).
Debugging is broken with clang-cl when FavorSizeOrSpeed is set.
2022-10-13 09:02:54 -04:00
Tatsuyuki Ishi 673dca5c07 Add b_thinlto_cache for automatically configuring incremental ThinLTO 2022-10-13 04:18:13 -04:00
Eli Schwartz 2cb7350d16 run wrapped-due-to-env commands on unix via the env program
First, check if the env program exists. If it does, it is faster than
doing it via a python script `basically-env.py` that maybe imports all
of mesonbuild.* as a side effect of project structure.

We do not, however, use env for setting up PATH additions, since env can
override an environment variable but not extend it. So in that case we
still need to wrap the command via python.

By default, all run_targets (at least) are wrapped and now wrap via the
`env` program as they export e.g.
MESONINTROSPECT='/usr/bin/meson introspect'
2022-10-09 08:03:58 -04:00
Jan Tojnar a590cfde0c compilers: Add optimization=plain option
https://github.com/mesonbuild/meson/pull/9287 changed the `optimization=0`
to pass `-O0` to the compiler. This change is reasonable by itself
but unfortunately, it breaks `buildtype=plain`, which promises
that “no extra build flags are used”.

`buildtype=plain` is important for distros like NixOS,
which manage compiler flags for optimization and hardening
themselves.

Let’s introduce a new optimization level that does nothing
and set it as the default for `buildtype=plain`.
2022-10-09 14:43:18 +03:00
Dylan Baker df1b95cf2b
pylint: enable consider-merging-isinstance 2022-10-04 00:33:14 -04:00
Dylan Baker f11ebf20ff
pylint: enable unnecessary-lambda 2022-10-03 00:16:09 -04:00
Caleb Cornett e574eba0a5 Add cross-compile support for Microsoft GDK platforms 2022-09-29 07:52:07 -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 2a262d2936 Automatically tag systemtap files 2022-09-28 00:13:49 -04:00
Xavier Claessens a010274d4b Automaticall tag installed tests
It is common, at least in GNOME projects, to install tests. Files goes
into various locations, including:
- /usr/lib/x86_64-linux-gnu/installed-tests
- /usr/share/installed-tests
- /usr/libexec/installed-tests

It is safe to assume that everything that goes into a "installed-tests"
subdir should be tagged as "tests" by default.
2022-09-28 00:13:49 -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
Vili Väinölä 496dce0666 Fix including headers from another drive on VS backend
Include paths to different drives as absolute paths

fixes #8329
2022-09-20 18:32:36 -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
Dylan Baker b11cf2f371 pylint: enable consider-using-dict-items
Which found a couple of places where we could write better code.
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
Eli Schwartz 7eb5709bd9
backends: limit maximum path of generated filenames
When calculating the output filename for a compiled object, we sanitize
the whole input path, more or less. In cases where the input path is
very long, this can overflow the max length of an individual filename
component.

At the same time, we do want unique names so people can recognize what
these outputs actually are. Compromise:

- for filepaths with >5 components (which are a lot more likely to cause
  problems, and simultanously less likely to have crucial information that
  far back in the filepath)
- if an sha1 hash of the full path, replacing all *but* those last 5
  components, produces a path that is *shorter* than the original path

... then use that modified path canonicalization via a hash. Due to the
use of hashes, it's unique enough to guarantee correct builds. Because
we keep the last 5 components intact, it's easy to tell what the output
file is compiled from.

Fixes building in ecosystems such as spack, where the build environment
is a very long path containing repetitions of
`__spack_path_placeholder__/` for... reasons of making the path long.
2022-09-11 14:51:03 -04:00
Andres Freund 91206aaeb0 vs: Fix CustomBuild contents.
%% survived into the output since 038b31e72b. That failed to fail, at
least in the common cases, because the whole command sequence is unnecessary /
redundant - it appears to come from cmake, which executes multiple commands
within a single CustomBuild element.
2022-09-09 18:37:30 -04:00
Thomas Li a4d5442207 Fix install_subdirs not showing up in intro-install_plan.json 2022-09-06 02:09:38 -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
Alf Henrik Sauge 06bf9a5cda Fix purely white space issues reported by flake8 2022-08-26 17:12:40 -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
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
Dylan Baker 394f734b1d build: Add a Union alias for all build targets 2022-08-18 21:57:36 -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
Christian Wendt 468022f91c backends: Remove /Zi arg if requested to use /Z7
Change the order of testing flags and get_external_args() to
handle flags set by get_external_args() correctly.
2022-07-15 11:26:01 -04:00
Tad Young 4c706e961b
add missing lower() to fix msvc backend platform detection
Regardless of which MachineChoice we base the platform on, we compare
its value to lowercased identifiers. So we need to lowercase the
targetplatform too... but we only did so sometimes.

This broke e.g. on "Win32", but only when *not* doing a cross build.

Fixes #10539
2022-06-26 08:10:12 -04: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 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 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