Commit Graph

344 Commits

Author SHA1 Message Date
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
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
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
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 14e35b63c0 parser: allow whitespaces and comments in cont_eol
FIXME: another approach would be to consider cont_eol as comment (i.e.
add backslash and whitespaces to the comment regex). In both cases it
works until we want to parse comments separately.

TODO?: handle eol_cont inside a string (to split long string without
breaking lines). Probably a bad idea and better to simply join a
multiline string.
2023-09-11 07:51:19 -04:00
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
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
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
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
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
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
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
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
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
Xavier Claessens a78af23686 Fix niche cases when linking static libs
Case 1:
- Prog links to static lib A
- A link_whole to static lib B
- B link to static lib C
- Prog dependencies should be A and C but not B which is already
  included in A.

Case 2:
- Same as case 1, but with A being installed.
- To be useful, A must also include all objects from C that is not
  installed.
- Prog only need to link on A.
2023-05-01 12:57:45 -04:00
Josh Soref cf9fd56bc9 fix various spelling issues
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-11 19:21:05 -04:00
Jussi Pakkanen 78d8924d43 Condense test directories for rc1. 2023-03-28 17:18:57 +03:00
Daan De Meyer adb619db61 Stop using replace_if_different() for coredata pickle file
This was added in f774609 to only change the access time of the
coredata file if the coredata struct actually changed. However,
this doesn't work as pickle serializations aren't guaranteed to
be stable. Instead, let's manually check if options have changed
values and skip the save if they haven't changed.

We also extend the associated unit test to cover all the option
types and to ensure that configure does get executed if one of the
options changes value.
2023-03-16 17:18:30 -04:00
Daniele Nicolodi f39ccde513 mintro: Add exclude_{files, dirs} to install_subdir install_plan
These are necessary for projects outside Meson itself that want to
extend the 'meson install' functionality as meson-python does to
assemble Python package wheels from Meson projects.

Fixes #11426.
2023-02-27 07:03:30 -05:00
Eli Schwartz cf07596cf6 test cases: use best practices method to find the python3 program
We do not need the python module's find_installation() for this, as this
does various things to set up building and installing python modules
(pure python and C-API). This functionality is already tested in the
python tests.

Elsewhere, when we just need an interpreter capable of running python
scripts in order to guarantee a useful scripting language for custom
commands, it suffices to use find_program(), which does not run an
introspection script or do module imports, and is thus faster and
a bit cleaner.

Either way, both methods are guaranteed to find the python3 interpreter,
deferring to mesonlib.python_command for that guarantee.

test "71 summary" can sometimes return the python command with the
".exe" part all uppercased for mysterious Windows reasons. Smooth this
over with ExternalProgram.
2023-02-24 20:45:00 -05:00
L. E. Segovia 088727164d interpreter/mesonmain: Add build_options method
This method allows meson.build to introspect on the changed options.
It works by merely exposing the same set of data that is logged by
MesonApp._generate.

Fixes #10898
2023-02-20 11:05:06 -05:00
Xavier Claessens 1a0eff0054 devenv: Allow dumping into file and select a format
It is often more useful to generate shell script than dumping to stdout.
It is also important to be able to select the shell format.

Formats currently implemented:
- sh: Basic VAR=prepend_value:$VAR
- export: Same as 'sh', but also export VAR
- vscode: Same as 'sh', but without substitutions because they don't
  seems to work. To be used in launch.json's envFile.
2023-01-18 11:06:48 -05: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
Paolo Bonzini b38bf09b94 add more testcases for prebuilt objects
Cover more cases including passing objects via ExtractedObjects and
CustomTarget.
2022-12-21 13:36:18 -08:00
Benjamin Gilbert 35e230e48c depfixer: silence fix_jar() and make it do something
fix_jar() tries to remove an existing Class-Path entry from the jar
manifest by postprocessing the manifest and passing it to `jar -um`.
However, `jar -um` can only add/replace manifest entries, not remove
them, and it also complains loudly when replacing an entry:

    Dec 13, 2022 7:11:19 PM java.util.jar.Attributes read
    WARNING: Duplicate name in Manifest: Manifest-Version.
    Ensure that the manifest does not have duplicate entries, and
    that blank lines separate individual sections in both your
    manifest and in the META-INF/MANIFEST.MF entry in the jar file.

Thus fix_jar() produces one such warning for each entry in the manifest
and accomplishes nothing else.

Use jar -uM instead.  This completely removes the manifest from the jar
and allows adding it back as a normal zip member, fixing fix_jar() and
avoiding the warnings.

Fixes: https://github.com/mesonbuild/meson/issues/10491
Fixes: c70a051e93 ("java: remove manifest classpath from installed jar")
2022-12-14 15:37:59 -05:00
David Robillard e85138fcc8 Fix various spelling errors
Found with codespell.
2022-11-24 15:17:23 -05:00
Jussi Pakkanen 3ae89a7150 Handle freezing tests. Fixes #10752. 2022-11-21 16:44:24 +02: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
L. E. Segovia 7e5b0760ce minstall: make do_strip run with -Sx for macOS targets
This commit also adds some extra symbol noise to lib.c, in order to aid
detection of the debug information with nm.

Fixes #10943
2022-11-01 17:56:18 +02:00
Jussi Pakkanen 458dcf8aac Condense test directory numbers. 2022-10-25 00:03:32 +03:00
Elliott Sales de Andrade 9c4d6088b1 Accept disablers in summary values
They are commonly used as a replacement for a `dependency`, and not
accepting them in `summary` breaks the last example in [1] when used as
a value.

[1] https://mesonbuild.com/Disabler.html#disabling-parts-of-the-build
2022-10-24 11:17:18 +02:00
Dylan Baker 6d50fadde5 tests: fix targets with no sources
This was never supposed to be possible, so stop doing it.
2022-08-17 13:44:08 -07:00
Eli Schwartz 6db9a01449 CI: fix error when mixing clang 14 with released valgrind versions
Because clang now defaults to a dwarf version that valgrind does not yet
support. There's support in valgrind git master, though.
2022-08-11 08:05:48 -07:00
Daan De Meyer f774609b09 Only reconfigure if configure options actually changed
Currently, if we run "meson configure -Doption=value", meson will
do a reconfigure when running "ninja build" afterwards, even if
the new value is the same one that was already configured previously.

To avoid this unnecessary reconfigure, let's use replace_if_different()
instead of unconditionally replacing the conf file in coredata's save()
function.
2022-07-31 20:43:27 +03:00
Jussi Pakkanen befd26985c Fix test case numbers. 2022-07-07 10:04:51 -07:00