Commit Graph

3155 Commits

Author SHA1 Message Date
Tristan Partin 543e9ca0cf Remove XML filter from testlog.{json,txt} and std streams
This was an unintended consequence of the original patch in #11977.

Co-authored-by: Benoit Pierre <benoit.pierre@gmail.com>
2023-08-17 17:31:30 -04:00
Tristan Partin f52bcaa27f Add fs.relative_to()
Returns a relative path from arg 2 to arg 1 similar to
os.path.relpath().
2023-08-17 17:05:49 -04:00
Xavier Claessens f88a9cd6b3 fs.read(): Catch FileNotFoundError 2023-08-16 14:48:09 -07:00
Andrew McNulty c730807696 Python: Add 'limited_api' kwarg to extension_module
This commit adds a new keyword arg to extension_module() that enables
a user to target the Python Limited API, declaring the version of the
limited API that they wish to target.

Two new unittests have been added to test this functionality.
2023-08-14 20:02:09 -04:00
Christoph Reiter 6671b7359f tests: fix "4 custom target depends extmodule" with Python 3.8+ on Windows
Since CPython 3.8 .pyd files no longer look in PATH for loading libraries,
but require the DLL directory to be explicitely added via os.add_dll_directory().
This resulted in those tests failing with 3.8+ on Windows.

Add the DLL build directory with os.add_dll_directory() to fix them.

This was never noticed in CI because it only uses Python 3.7 and the
MSYS2 CPython still used the old behaviour until now.
2023-08-08 16:32:39 -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
Xavier Claessens 9df1627997 Compiler: Add werror kwarg to compiles(), links() and run() methods
Fixes: #5399
2023-08-07 08:21:05 -04:00
Xavier Claessens e01d53b816 compiler: Add required keyword to has_* methods
add the "required" keyword to the functions

has_function
has_type
has_member
has_members
has_argument
has_multi_arguments
has_link_argument
has_multi_link_argument
has_function_attribute

Co-authored-by: Milan Hauth <milahu@gmail.com>
2023-08-05 07:14:08 -04:00
Nomura 50baf3c626 Add default_options argument to find_program() 2023-08-04 14:46:39 -04:00
Xavier Claessens cec3edc08a Unify message(), format() and fstring formatting
Share a common function to convert objects to display strings for
consistency.

While at it, also add support for formatting user options.
2023-08-02 13:35:29 -04:00
Eli Schwartz 13f8eba9b6
treewide: internally avoid deprecated machine file uses of "pkgconfig"
We support this in a machine file:

```
[binaries]
pkgconfig = 'pkg-config'
pkg-config = 'pkg-config'
```

and you can use either one, because internally we look up both. If you
only set *one* of them, this plays awkwardly with setting $PKG_CONFIG,
since we don't know which one you set in the machine file and the
*other* one will be initialized from the environment instead.

In commit 22df45a319 we changed program
lookup of config-tool style dependencies to use the regular tool names
and only fall back on the strange internal names. This affected the
pkg-config class too.

The result is that instead of preferring `pkgconfig =` followed by
$PKG_CONFIG followed by `pkg-config =`, we inverted the lookup order.
This is a good idea anyway, because now it behaves consistently with
`find_program('pkg-config')`.

Unfortunately, we documented the wrong name in a bunch of places, and
also used the wrong name in various testsuite bits, which meant that if
you set $PKG_CONFIG and then ran the testsuite, it would fail.

Correct these references, because they are buggy.

One test case expected to find_program() a native copy for convenience
of testing against natively installed glib. Force it to resolve a native
copy.
2023-08-02 01:35:16 -04:00
Daniele Nicolodi 9eb7fe332f Fix install_data() default install path
This fixes two issues in constructing the default installation path
when install_dir is not specified:

- inside a subproject, install_data() would construct the destination
  path using the parent project name instead than the current project
  name,

- when specifying preserve_path, install_data() would construct the
  destination path omitting the project name.

Fixes #11910.
2023-07-26 13:30:49 -04:00
Dylan Baker 020610cfbe modules/pkgconfig: Don't insert None into devenv list
When the pkgconfig module is imported, but not used, it will insert None
on the end of the devenv list. This list is not expected to contain
None, and causes Meson to crash. This can happen in complex build setups
(reported from mesa), where pkgconfig is only used in some
configurations

Fixes: #12032
2023-07-25 00:13:16 -04:00
George Sedov c2ed846b64 hdf5 tests: make cpp test actually use cpp HDF5
the previous version didn't even link to libhdf5_cpp.so
2023-07-23 13:52:39 -04:00
Eli Schwartz a8b9bd2b74 tests: bump the C++ std for protobuf tests
Based on https://opensource.google/documentation/policies/cplusplus-support
Google no longer supports C++11, and protobuf spawns an `#error` if you
don't have at least 14.

So, perform our currently scheduled automatic bump.
2023-07-18 21:58:58 -04:00
Eli Schwartz 0a40e591d3 tests: mark gpgme test skippable on Ubuntu rolling
It has been rebuilt to no longer provide the deprecated gpgme-config
tool.
2023-07-18 21:58:58 -04:00
Xavier Claessens 9d88d0d5cc ci: Skip test_generate_gir_with_address_sanitizer
It fails with glib >= 2.76 and gobject-introspection <= 1.76.1.

Fixes: #11754
2023-07-18 14:48:59 -04:00
Jussi Pakkanen 3b5287b652 Fix build using GDC 13
Do not run tests that use integers in versions with compiler that do
not support them.

Old versions of GDC supported plain integers in version and debug
strings but they are deprecated and GDC 13 hard errors on them.
2023-07-16 23:57:57 +03:00
Dylan Baker 76eba99850 rust: disable overflow-checks by default
These result in very large binaries when linked, and are not generally
useful. A user can turn them back on by passing `-C overflow-checks=yes`
manually via `-Drust_args` or the `RUSTFLAGS` environment variable

fixes: #11785
2023-07-15 12:22:30 -07:00
Eli Schwartz adaea4136f
compiler.compiles/links: fix failure when compiling a built File object
In order to pass a File object down into the compiler impl and compile
it, we cannot pass a string with the filename, and we cannot either pass
the File object as-is, since it relies on being given Environment
attributes to calculate the relative location. So we build a fresh File
object as an absolute path.

But the code to do this was totally broken. Instead of using the File
method to get an absolute path, we used one that expected to create
builddir-relative paths... and then gave it the absolute source dir as
the "relative path portion" prefix. This worked by accident as long as
it wasn't a built File, but if it was a built file then we intentionally
didn't include that prefix -- which was wrong anyway, since we need the
build directory!

Use the correct method to get an absolute path in all cases, and emit a
warning if it was a built file. This never worked. Sometimes it crashed,
sometimes it silently returned false.

Fixes #11983
2023-07-14 14:50:51 -04:00
Matthieu Rogez b92858a5be
cmake: fix directory separators in generated packageConfig.cmake files
On windows, meson would mix posix and windows dir separators in the
computed PACKAGE_RELATIVE_PATH.

Here we force posix directory separator even on Windows. This matches
the CMake behavior and fixes interpretation of the resulting path.

Fixes #6955
Fixes #9702
2023-07-13 15:39:44 -04:00
Tristan Partin 3784f72973 Silence some encoding warnings
By specifiying explicit encodings, we can silence warnings like:

 /__w/meson/meson/test cases/common/100 postconf with args/postconf.py:15: EncodingWarning: 'encoding' argument not specified
  with open(input_file) as f:

in CI.
2023-07-13 09:55:10 -07:00
Nazir Bilal Yavuz bd3d2cf918 mtest: fix unencodable XML chars
Replace unencodable XML chars with their printable representation, so
that, xmllint can parse test outputs without error.

Closes #9894

Co-authored-by: Tristan Partin <tristan@partin.io>
2023-07-13 09:38:55 -07:00
Xavier Claessens 1fef03c0f0 build: dependencies should come after link_with on link command
This fixes regression caused by
3162b901ca
that changes the order in which libraries are put on the link command.

In addition, that commit was wrong because libraries from dependencies
were processed before process_compiler() is called, which that commit
wanted to avoid.
2023-07-10 23:12:24 +03:00
Xavier Claessens cd63853ad2 build: Fix linking multiple libraries and some are promoted
When a link() is promoted to link_whole() we still have to handle the
rest of the list.

Fixes: #11956
2023-07-10 23:12:24 +03:00
Eli Schwartz 4166bf1eb2 Revert "backends: Cache creation of install data"
This reverts commit 904b47085f.

This is not a real bottleneck, and we want to create it thrice -- once
before the backend is generated. The final install data needs to be
created fresh.

Update unittest to demonstrate the issue.

Fixes https://bugs.gentoo.org/910050
2023-07-10 17:21:11 +03:00
Jussi Pakkanen bf9a6a1b5c Renumber test dirs for rc2. 2023-07-05 23:56:18 +03:00
Xavier Claessens d140342c14 comp.preprocess(): Do not treat every file as assembly
Fixes: #11940
2023-07-05 21:34:25 +03:00
Jussi Pakkanen d391e5281c
Merge pull request #11742 from xclaesse/link-whole-cases
Fix niche cases when linking static libs
2023-07-05 01:10:58 +03:00
Kacper Michajłow 7fe6e18a02 tests: add standard option to get_define() test
This properly tests MSVC case which produce different preprocessed
output depending on language version.
2023-07-04 16:29:15 -04:00
GertyP 36bf53bdfd
Experimental 'genvslite' WIP. (#11049)
* Capture all compile args from the first round of ninja backend generation for all languages used in building the targets so that these args, defines, and include paths can be applied to the .vcxproj's intellisense fields for all buildtypes/configurations.

Solution generation is now set up for mutiple build configurations (buildtypes) when using '--genvslite'.

All generated vcxprojs invoke the same high-level meson compile to build all targets;  there's no selective target building (could add this later).  Related to this, we skip pointlessly generating vcxprojs for targets that aren't buildable (BuildTarget-derived), which aren't of interest to the user anyway.

When using --genvslite, no longer inject '<ProjectReference ...>' dependencies on which a generated .vcxproj depends because that imposes a forced visual studio build dependency, which we don't want, since we're essentially bypassing VS's build in favour of running 'meson compile ...'.

When populating the vcxproj's shared intellisense defines, include paths, and compiler options fields, we choose the most frequent src file language, since this means more project src files can simply reference the project shared fields and fewer files of non-primary language types need to populate their full set of intellisense fields.  This makes for smaller .vcxproj files.

Paths for generated source/header/etc files, left alone, would be added to solution projects relative to the '..._vs' build directory, where they're never generated;  they're generated under the respective '..._[debug/opt/release]' ninja build directories that correspond to the solution build configuration. Although VS doesn't allow conditional src/header listings in vcxprojs (at least not in a simple way that I'm aware of), we can ensure these generated sources get adjusted to at least reference locations under one of the concrete build directories (I've chosen '..._debug') under which they will be generated.

Testing with --genvslite has revealed that, in some cases, the presence of 'c:\windows\system32;c:\windows' on the 'Path' environment variable (via the make-style project's ExecutablePath element) is critical to getting the 'meson compile ...' build to succeed.  Not sure whether this is some 'find and guess' implicit defaults behaviour within meson or within the MSVC compiler that some projects may rely on. Feels weird but not sure of a better solution than forcibly adding these to the Path environment variable (the Executable Path property of the project).

Added a new windows-only test to windowstests.py ('test_genvslite') to exercise the --genvslite option along with checking that the 'msbuild' command invokes the 'meson compile ...' of the build-type-appropriate-suffixed temporary build dir and checks expected program output.

Check and report error if user specifies a non-ninja backend with a 'genvslite' setup, since that conflicts with the stated behaviour of genvslite.  Also added this test case to 'WindowsTests.test_genvslite'

I had problems tracking down some problematic environment variable behaviour, which appears to need a work-around. See further notes on VSINSTALLDIR, in windowstests.py, test_genvslite.
'meson setup --help' clearly states that positional arguments are ... [builddir] [sourcedir].  However, BasePlatformTests.init(...) was passing these in the order [sourcedir] [builddir].  This was producing failures, saying, "ERROR: Neither directory contains a build file meson.build." but when using the correct ordering, setup now succeeds.

Changed regen, run_tests, and run_install utility projects to be simpler makefile projects instead, with commands to invoke the appropriate '...meson.py --internal regencheck ...' (or install/test) on the '[builddir]_[buildtype]' as appropriate for the curent VS configuration.  Also, since the 'regen.vcxproj' utility didn't work correctly with '--genvslite' setup build dirs, and getting it to fully work would require more non-trivial intrusion into new parts of meson (i.e. '--internal regencheck', '--internal regenerate', and perhaps also 'setup --reconfigure'), for now, the REGEN project is replaced with a simpler, lighter-weight RECONFIGURE utility proj, which is unlinked from any solution build dependencies and which simply runs 'meson setup --reconfigure [builddir]_[buildtype] [srcdir]' on each of the ninja-backend build dirs for each buildtype.
Yes, although this will enable the building/compiling to be correctly configured, it can leave the solution/vcxprojs stale and out-of-date, it's simple for the user to 'meson setup --genvslite ...' to fully regenerate an updated, correct solution again. However, I've noted this down as a 'fixme' to consider implementing the full regen behaviour for the genvslite case.

* Review feedback changes -
- Avoid use of 'captured_compile_args_per_buildtype_and_target' as an 'out' param.
- Factored a little msetup.py, 'run(...)' macro/looping setup steps, for genvslite, out into a 'run_genvslite_setup' func.

* Review feedback:  Fixed missing spaces between multi-line strings.

* 'backend_name' assignment gets immediately overwritten in 'genvslite' case so moved it into else/non-genvslite block.

* Had to bump up 'test cases/unit/113 genvslites/...' up to 114; it collided with a newly added test dir again.

* Changed validation of 'capture' and 'captured_compile_args_...' to use MesonBugException instead of MesonException.

* Changed some function param and closing brace indentation.
2023-06-28 15:29:57 +03:00
Jussi Pakkanen 9e1e4cafd5 Condense test directory names for release. 2023-06-28 15:28:52 +03:00
Dylan Baker 6bfb47a455 rust: Override the default MSVCRT when linking Rust and !rust together
Rust by default links with the default MSVCRT, (dynamic, release).
MSVCRT's cannot be mixed, so if Meson compiles a C or C++ library and
links it with the debug MSVCRT, then tries to link that with the Rust
library there will be failures. There is no built-in way to fix this for
rustc, so as a workaround we inject the correct arguments early in the
linker line (before any libs at least) to change the runtime. This seems
to work and is recommended as workaround in the upstream rust bug
report: https://github.com/rust-lang/rust/issues/39016.

Given that this bug report has been opened since 2017, it seems unlikely
to be fixed anytime soon, and affects all (currently) released versions
of Rust.
2023-06-27 11:53:18 -07:00
Dylan Baker 772cb92624 rust: get stdlib arguments for non-rust languages when linking
Otherwise we might not get things like libstdc++, which we need.
2023-06-27 11:53:18 -07:00
Dylan Baker 5d16bd5308 modules/rust: Add a keyword argument to pass extra args to the rust compiler
This may be necessary to, for example, stop rustc complaining about
unused functions
2023-06-27 11:53:18 -07:00
Dylan Baker 43f24060f3 modules/rust: Add a `link_with` kwarg to the test method
This was requested by Mesa, where a bunch of `declare_dependency`
objects are being created as a workaround for the lack of this keyword
2023-06-27 11:53:18 -07:00
Daniele Nicolodi c900e6b0b3 mintro: record subproject in install_plan 2023-06-26 23:06:29 -04:00
Eli Schwartz a71846d749
Revert "modules: move gnome targets into gnome module"
This reverts commit a2def550c5.

This results in a 2k line file being unconditionally imported at
startup, and transitively loading two more (for a total cost of 2759
lines of code), and it's not clear it was ever needed to begin with...
2023-06-26 13:10:33 -04:00
Eli Schwartz a1ef957e34
linkers: delay implementations import until detect is run
This saves on a 1500-line import at startup and may be skipped entirely
if no compiled languages are used. In exchange, we move the
implementation to a new file that is imported instead.

Followup to commit ab20eb5bbc.
2023-06-26 13:10:33 -04:00
Eli Schwartz 5849979afa
stop importing cmake when it isn't used
We don't need a CMakeInterpreter until and unless we actually attempt to
use a cmake subproject via the cmake module.

Minus 10 files and 3679 lines of code imported at startup.
2023-06-26 13:10:33 -04:00
Eli Schwartz b1ddfabf8f
dependencies: defer importing a custom dependency until it is used
This lessens the amount of code imported at Meson startup by mapping
each dependency to a dictionary entry and using a programmable import to
dynamically return it.

Minus 16 files and 6399 lines of code imported at startup.
2023-06-26 13:10:33 -04:00
Eli Schwartz c82305db0c
dependencies: delay often-unused imports
We expose detect.py as the mesonbuild.dependencies entrypoint and import
it upfront everywhere. But unless the `dependency()` function is
actually invoked, we don't need *any* of the private implementations for
this.

Avoid doing so until, as part of actual dependency lookup, we attempt
that specific dependency method. This avoids importing big modules if
`method:` is specified, and in most cases hopefully pkg-config works and
we can avoid importing the cmake implementation particularly.

Actually avoiding most of these imports requires more refactoring. But
even so, the garden path no longer needs to import the dub dependency
impl.
2023-06-26 13:10:32 -04:00
Eli Schwartz 620bdf5895
add profiling startup import check and testcase to count it 2023-06-26 13:08:57 -04:00
Alyssa Ross ab17bd2393 rust: fix -C prefer-dynamic behavior
I noticed when building a project that uses a proc macro that Meson
passed -C prefer-dynamic for the executable, and not the proc macro,
while cargo passed -C prefer-dynamic for the proc macro, but not for
the executable.  Meson's behavior broke setting -C panic=abort on the
executable.

As far as we can tell, because we explicitly pass each library path to
rustc, the only thing -C prefer-dynamic affects in Meson is how the
standard libraries are linked.  Generally, one does not want the
standard libraries to be dynamically linked, because if the Rust
compiler is ever updated, anything linked against the old standard
libraries will likely break, due to the lack of a stable Rust ABI.
Therefore, I've reorganised Meson's behavior around the principle that
the standard libraries should only be dynamically linked when Rust
dynamic linking has already been opted into in some other way.  The
details of how this manifests are now explained in the documentation.
2023-06-21 18:05:16 -04:00
Xavier Claessens 6f2956e76c interpreter: Accept more types in default_options dict values 2023-06-20 16:10:20 -07:00
Martin Dørum e869a09bc2 add str.splitlines method
The new splitlines method on str is intended to replace usage of
fs.read('whatever').strip().split('\n').
The problem with the .strip().split() approach is that it doesn't have a
way to represent empty lists (an empty string becomes a list with one
empty string, not an empty list), and it doesn't handle Windows-style
line endings.
2023-06-20 08:28:47 -04:00
Eli Schwartz 7126ca6e27
tests: remove unnecessary non-meson syntax from meson.build
We don't use parentheses for the if function, because it's not a
function.
2023-06-07 16:40:52 -04:00
Eli Schwartz e2e6fd2e61
tests: update llvm version exclusions for hopefully the last time
This is now fixed upstream and expected to be backported to the next
point release.
2023-06-07 16:40:52 -04:00
Eli Schwartz 95ee4d7d13
tests: be DRY in llvm framework test
It's a lot more readable to not repeat big arrays.
2023-06-07 16:40:52 -04:00
Eli Schwartz 96f6600832
tests: avoid hard to debug error when llvm is found with only one method
In commit 89146e84c9 we added some
complicated code to verify the llvm framework's "combination" matrix
lookup. It expects to find llvm with both cmake and config-tool, with
the same version. But the sanity check is wonky -- it checks that both
have the same found status, instead, so if both are not found then we
proceed to try to convert the string "unknown" to a mapping of semver
integers, and this is guaranteed to fail.

This can happen for example if the system llvm exists in the general
case, but actual modules cannot be found because the system llvm does
not distribute static modules. For example, this is the case on Gentoo.

Abort more obviously by just insisting that both be found. If they
aren't both found, then investigative efforts know to look at why they
weren't found.
2023-06-07 16:40:51 -04:00