Commit Graph

276 Commits

Author SHA1 Message Date
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
Andres Freund d2d31c3cc2 macos: map arm64e to aarch64, map "whole" architecture strings
Some macos libraries use arm64e instead of arm64 as architecture. Due to the
string replace approach taken so far, we'd end up with aarch64e as
architecture, which the rest of meson doesn't know.

Move architecture mapping to map whole architecture names and add arm64e ->
aarch64 mapping.

This change doesn't touch the case for armv7[s], where we add arm, rather than
replace armv7[s], but it's certainly not in line with the other mappings.

Fixes: #9493

Co-authored-by: Tristan Partin <tristan@partin.io>
2023-07-13 11:44:57 -07: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
Jussi Pakkanen bf9a6a1b5c Renumber test dirs for rc2. 2023-07-05 23:56:18 +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
Eli Schwartz 77d4db533f
remove CI workaround for clang+msys2
Reverts part of commit 4e17d60d47.

msys2 is now fixed, so clang works well with the python headers.
2023-07-02 18:03:21 -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