Commit Graph

285 Commits

Author SHA1 Message Date
Alyssa Ross 9322a29d7f Skip pkg-config-dependent tests if it's missing 2023-12-17 16:21:11 -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
Andres Freund f6f46173c4 macos: Fix test_pkgconfig_parse_libs() test on arm
The unit test infrastructure hardcodes the architecture as x86_64. On
macos, the test_pkgconfig_parse_libs() test creates a few libraries
for testing using clang. This leads to the test failing on arm based
macs, as darwin_get_object_archs() will skip over these libraries,
which then leads to the test failing because of using -l instead of
referencing the libraries by their full path.

I am not at all sure this is the best approach.

I am also somewhat confused why nobody else has encountered this? CI
apparently just runs on x86_64 macs?

CC: @tristan957
2023-12-13 00:44:59 +02:00
Eli Schwartz 17c6d5eb47
unittests: migrate from jsonschema to fastjsonschema
The former has rust dependencies, which lead to max capping on Cygwin
since there is no rust compiler there. But it turns out there are other
disadvantages of jsonschema:

- it involves installing 5 wheels, instead of just 1
- it is much slower

To give some perspective to the latter issue, this is what it looks like
when I test with jsonschema:

```
===== 1 passed, 509 deselected in 3.07s =====
Total time: 3.341 seconds
```

And here's what it looks like when I test with fastjsonschema:
```
===== 1 passed, 509 deselected, 1 warning in 0.28s =====
Total time: 0.550 seconds
```

I cannot think of a good reason to use the former. Although in order to
work on old CI images, we'll support it as a fallback mechanism
2023-12-10 19:02:39 -05:00
Eli Schwartz 5f659af870
ninja backend: don't hide all compiler warnings for transpiled languages
This was originally added for vala only, with the rationale that vala
generates bad code that has warnings. Unfortunately, the rationale was
fatally flawed. The compiler warns about a number of things, which the
user can control depending on their code (or their code generator's
code), but some of those things are absolutely critical to warn about.

In particular, GCC 14 and clang 17 are updating their defaults to warn
-- and error by default for -- invalid C code that breaks the standard,
but has been silently accepted for over 20 years "because lots of people
do it". The code in question is UB, and compilers will generate faulty
machine code that behaves erroneously and probably has a mass of CVEs
waiting to happen.

Compiler warnings are NOT safe to just... universally turn off. Compiler
warnings could be either:

- coding style lints

- threatening statements that the code is factually and behaviorally wrong

There is no magic bullet to ignore the former while respecting the
latter. And the very last thing we should ever do is pass `-w`, since
that causes ALL warnings to be disabled, even the manually added
`-Werror=XXX`.

If vala generated code creates warnings, then the vala compiler can
decrease the log level by generating better code, or by adding warning
suppression pragmas for *specific* issues, such as unused functions.
2023-12-05 19:51:56 -05:00
Andres Freund c1f0897248 macos: Fix path in test to be Sonoma compatible
The path tested prior does not exist anymore in Sonoma. It seems less likely
that 'cat' will be removed, so use that.
2023-12-03 12:53:15 +02:00
Jussi Pakkanen 97dc8801a6 Renumber test dirs for rc3. 2023-11-12 19:18:06 +02:00
Eli Schwartz fb1c6e32f4
Fine-tune the error message when trying to build outside the project root
We try to backtrack through the filesystem to find the correct directory
to build in, and suggest this as a possible diagnostic. However, our
current heuristic relies on parsing the raw file with string matching to
see if it starts with `project(`, and this may or may not actually work.

Instead, do a bit of recursion and parse each candidate with mparser,
then check if the first node of *that* file is a project() function.

This makes us resilient to a common case: where the root meson.build is
entirely valid, but, the first line is a comment containing e.g. SPDX
license headers and a simple string comparison simply does not cut it.

Fixes the bad error message from #12441, which was supposed to provide
more guidance but did not.
2023-11-04 22:13:11 -04:00
Jussi Pakkanen 3bbe66e971 Condense test directories for RC1. 2023-10-27 17:43:03 +03:00
Dylan Baker 450b3db378 modules/rust: Add a test that bindgen drops arguments it shouldn't use
This does require hacking up the test pretty badly, since we need to not
ever pass GCC these invalid values. But it's preferable to writing
another project test I think.

Co-Authored-by: Nirbheek Chauhan <nirbheek@centricular.com>
2023-10-20 20:21:08 +05:30
Xavier Claessens ea42d2d019 cargo: Fix '1.0.45' version conversion
The middle 0 was wrongly dropped.
2023-10-09 21:13:58 -04:00
Xavier Claessens b5b952688f cargo: builder: Remove all duplicated functions
Keep only the Builder class, there is no point in duplicating
everything.
2023-10-09 21:13:58 -04:00
Dylan Baker 013536fcb4 interpreter: add <lang>_(static|shared)_args
Which allow passing arguments specifically to the static or shared
libraries.

For design, this is all handled in the interpreter, by the build layer
the arguments are combined into the existing fields. This limits changes
required in the mid and backend layers
2023-10-09 17:33:48 -04:00
Benjamin Redelings 84b8d257e4 Allow c++23 in gcc-11. 2023-10-09 23:53:31 +03:00
Dudemanguy 03a0d3ddfb mcompile: add suffix as an additional parameter
Since the previous commit allows for more scenarios with name
collisions, it makes sense to expand the compile command so that it can
also take into account suffixes. i.e. meson compile -C build foo.exe can
now work if the executable has an exe suffix along with being named foo.
2023-10-05 08:43:38 -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
Tristan Partin 1991ad8706
Remove type comments in run_project_tests.py 2023-10-04 15:23:00 -04:00
Lei YU dac25ba9a8 unittest: Fix clang-tidy-fix
The unittest case for `clang-tidy-fix` checks if the whole project is in
git or not, and skips if not.

Fix this by creating a temporary git repo, copy the test files and run
the tests, following how `clang-format` does.

It also reverts some help code introduced in the previous test.

Tested: Verify the test case passes.

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
2023-09-28 10:54:39 -04:00
Eli Schwartz 5b317c5658
compilers: use correct version comparison for openbsd libraries
It should *be* a version comparison. We are guaranteed to get a
two-element version number, which also parses as a float but a float
doesn't correctly handle version sorting when the second component
differs in number of digits.

The standard way to handle this is by comparing tuples such that each
component is an integer. Do so here.

Fixes #12195

Co-authored-by: George Koehler <xkernigh@netscape.net>
(for unittests)
2023-09-26 02:36:15 -04:00
Lei YU 8d6b474bf6 Add clang-tidy-fix target
Add the `clang-tidy-fix` target to apply clang-tidy fixes to the source
code.
This is done by calling `run-clang-tidy` with `-fix` argument.

Add a test case to run `clang-tidy-fix` and verify the file is changed.

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
2023-09-25 16:25:01 +03:00
Xavier Claessens f1c35b561f pkgconfig: Set PKG_CONFIG in env for devenv and g-ir-scanner 2023-09-18 13:51:27 -04:00
Xavier Claessens 0eae4e0936 pkgconfig: Restore logging of pkg-config version
While at it, make more methods private by storing the version found on
the instance. That avoids having to call check_pkgconfig() as static
method from unittests.
2023-09-18 13:51:27 -04:00
Xavier Claessens dec85c41a9 Remove get_configtool_variable()
This also makes it more consistent with get_pkgconfig_variable() which
always return empty value instead of failing when the variable does not
exist. Linking that to self.required makes no sense and was never
documented any way.
2023-09-18 13:51:27 -04:00
Xavier Claessens 30d7f506c7 Remove get_pkgconfig_variable()
Make sure that pkgconfig_define is a pair of strings and not a list with
more than 2 strings.
2023-09-18 13:51:27 -04:00
Christoph Reiter 1306d15616 Revert "tests: skip a test that fails with new Python 3.11 from MSYS2"
This reverts commit 68dce66bf9.

The upstream issues https://github.com/msys2-contrib/cpython-mingw/issues/141
has been fixed now.
2023-09-14 11:47:22 -04:00
Jussi Pakkanen d2dfef5205
Merge pull request #12152 from bruchar1/ast-preserve-all
Preserve whitespaces and comments in AST
2023-09-12 17:50:13 +03:00
Charles Brunet 57178e8ae7 fix bug with openssl when cmake is missing
Fixes #12098

DependencyFactory was returning a lambda, but it has no log_tried() function
2023-09-12 17:31:32 +05:30
Charles Brunet d3a26d158e raw printer
this printer preserves all whitespaces and comments in original meson.build file. It will be useful for rewrite and potential auto-formatter
2023-09-11 07:51:19 -04:00
Xavier Claessens fe9af72684 wrap: Use MESON_PACKAGE_CACHE_DIR as default packagecache path
Allow packagecache to contain already extracted directory to match what
some distro does with Cargo source packages in /usr/share/cargo/registry.

Note that there is no need to lock the cache directory because we
download into a temporary name and atomically rename afterward. It means
we could be downloading the same file twice, but at least integrity is
guaranteed.

Fixes: #12211
2023-09-05 09:05:24 +05:30
Jussi Pakkanen 08d83a4a97
Merge pull request #10332 from xclaesse/std-opt
c_std, cpp_std: Change to a list of desired versions in preference order
2023-08-30 12:04:09 -07:00
Xavier Claessens e3a71a7b58 msetup: Update options when builddir is already configured
`meson setup -Dfoo=bar builddir` command was returning success ignoring
new option values.

This now also update options. It is useful because it means
`meson setup -Dfoo=bar builddir && ninja -C builddir` works regardless
whether builddir already exists or not, and when done in a script,
changing options in the script will automatically trigger a reconfigure
if needed. This was already possible by always passing --reconfigure
argument, but that triggers a reconfigure even when options did not
change.
2023-08-25 09:43:24 -04:00
Xavier Claessens 18b96cd069 machine file: Add @GLOBAL_SOURCE_ROOT@ and @DIRNAME@ 2023-08-23 11:33:39 -04:00
Benoit Pierre 268276f7ac tests: fix assertion rewriting when pytest is used 2023-08-18 00:37:40 -04:00
Eli Schwartz 1fd70a2a00
tests: consolidate MESON_SKIP_TEST reporting and use it in unittests
Previously, we only reported the skip reason when running project tests.
2023-08-17 21:30:32 -04:00
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
Jan200101 b91244c3b7 correct cmakedefine behavior
- allow defines with leading whitespace
- always do replacement for cmakedefine
- output boolean value for cmakedefine01
- correct unittests for cmakedefine
- add cmakedefine specific unittests
2023-08-08 14:53:43 -07: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 82a8c72187 c_std, cpp_std: Change to a list of desired versions in preference order
Projects that prefer GNU C but can fallback to ISO C can now set for
example `default_options: 'c_std=gnu11,c11'` and it will use gnu11 when
available, fallback to c11 otherwise. It is an error only if none of the
values are supported by the current compiler.

This allows to deprecate gnuXX values from MSVC compiler, that means
that `default_options: 'c_std=gnu11'` will now print warning with MSVC
but still fallback to 'c11' value. No warning is printed if at least one
of the values is valid, i.e. `default_options: 'c_std=gnu11,c11'`.

In the future that deprecation warning will become an hard error because
`c_std=gnu11` should mean GNU is required, for projects that cannot be
built with MSVC for example.
2023-08-07 08:28:00 -04:00
Simon McVittie 61554ad37b tests: Assert that mips64 kernel is detected as mips64 with no compilers
Reproduces: https://github.com/mesonbuild/meson/issues/12017
Signed-off-by: Simon McVittie <smcv@debian.org>
2023-08-06 02:32:25 -04:00
Simon McVittie 432317bc6b tests: Pass a mock C compiler to detect_cpu(), detect_cpu_family()
In some cases the desired result can be different if there are no
compilers at all. The expectations here are based on there being at
least one compiler, so reflect that by providing one; a later test
enhancement can cover the case where there are no compilers provided.

As a result of the mock any_compiler_has_define(), all that matters
will be the distinction between an empty or non-empty dict: the compiler
object itself is unused.

Signed-off-by: Simon McVittie <smcv@debian.org>
2023-08-06 02:32:25 -04:00
Xavier Claessens 183e4b8e90 PkgConfigDependency: Move CLI handling into its own abstraction
This makes the code cleaner and will allow to have other implementations
in the future.
2023-08-03 16:27:52 -04:00
Eli Schwartz cdef674169 convert booleans in summary function to correct representation
str() is going to return titlecased "True" which is not how meson works.
This is misleading, so use the meson-specific format instead.
2023-08-02 20:38:14 -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
Dan Hawson 7c955618dd
Rename variables that clash with pdb commands
By default, pdb assumes that any command run is python code to be
evaluated, but only if that code isn't a builtin pdb command. You can
force it to be evaluated as python code by prefixing it with `!`.

It's handy to simply name a python variable and have its variable be
printed.

But single letter variables like 's' and 'p' make debugging with pdb
commands (i.e. 's'tep, and 'p'rint evaluated expressions) less
convenient, and potentially confusing.
2023-07-31 15:43:28 -04:00
Jussi Pakkanen 1cd16a7cc5
Merge pull request #11986 from williamspatrick/clang-enable-cpp23
add support for newer C++ -std= flags on Clang/GCC
2023-07-31 16:59:16 +03:00
Christoph Reiter 68dce66bf9 tests: skip a test that fails with new Python 3.11 from MSYS2
For some (atm unknown) reason mingw Python fails to load some modules
when MSYS2 is removed from PATH, like in this test.

Skip for now to make the test suite pass again. Once
https://github.com/msys2-contrib/cpython-mingw/issues/141 is fixed
this can be reverted.
2023-07-30 22:39:45 -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 bbe649a5fc unittests: test the vala template 2023-07-25 15:50:21 -04:00
Dylan Baker c30cdfc4b0 unittests: use subtests for template tests
Which gives more exact errors
2023-07-25 15:50:21 -04:00
Steven Noonan 51d04776a3 tests: add support for c++23/c++26 detection
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2023-07-14 13:29:16 -05:00