Commit Graph

225 Commits

Author SHA1 Message Date
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
Dylan Baker c5b16ab8b9 modules/rust: Add a machine file property for extra clang args with bindgen
It's currently impossible to inject extra clang arguments when using
bindgen, which is problematic when cross compiling since you may need
critical arguments like `--target=...`. Because such arguments must be
passed after the `--` it's impossible to inject them currently without
going to something like a wrapper script.

Fixes: #11805
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
Eli Schwartz 25f5f3554d
tests: move script loaded modules test to platform-agnostic
We have the same platform startup logic here for all platforms and I do
not believe it's important to test this on the slow CI machines.
2023-06-25 15:38:31 -04:00
Charles Brunet 35291c9672
unittests: fix test_scripts_loaded_modules matching exactly our own modules
When meson is installed as editable, setuptools adds
`__editable___meson_1_0_99_finder` to the list. This contains the string
"meson" which isn't really accurate to what we want, which is modules
that are part of the `mesonbuild.*` namespace.
2023-06-16 02:11:02 -04:00
Charles Brunet 92592015bb
unittests: skip test using symlink if not available 2023-06-16 02:11:02 -04:00
Charles Brunet 64394fcbd6
unittests: ensure terminal has 80 chars width 2023-06-16 02:10:16 -04:00
Eli Schwartz aa13c46822
WIP: refactor loggable popen calls for consistency 2023-06-14 01:04:55 -04:00
Dylan Baker 4017dab484 cargo/cfg: Add a parser for the rust/cargo cfg() expressions
This uses a recursive descent parser + lexer to create an IR from cfg()
expressions, which it then converts into meson IR.
2023-06-07 19:20:30 -07:00
Dylan Baker 5e59e5a9e4 cargo/version: add a function to convert cargo versioning to meson 2023-06-07 19:20:30 -07:00
Eli Schwartz df053848eb
unittests: fix incorrect calculation of bytecompile outputs
If py2 is not found *and* the compiler is MSVC, we didn't take into
account that py2 is not found. This also meant that we didn't take into
account the expected count when it *is* found, because the python module
has a better finder than just "is the binary on PATH".
2023-06-07 16:40:52 -04:00
Dylan Baker ada2a976f0
mlog: use a hidden class for state
This is a pretty common pattern in python (the standard library uses it
a ton): A class is created, with a single private instance in the
module, and then it's methods are exposed as public API. This removes
the need for the global statement, and is generally a little easier to
reason about thanks to encapsulation.
2023-05-31 17:20:44 -04:00
Charles Brunet e7b9dfac98 mtest: wildcard selection
Allow the use of wildcards (e.g. *) to match test names in `meson test`.

Raise an error is given test name does not match any test.

Optimize the search by looping through the list of tests only once.
2023-05-25 13:44:13 -04:00
Charles Brunet 8d30577a2d intro: add more details to generated files(part 2)
- add `extra_paths` to intro-tests.json to know paths needed to run a
  test on Windows;
- add `depends` to alias targets in intro-targets.json to know what
  targets does an alias point to;
- add `depends` to intro-dependencies.json to know libraries linked with
  an internal dependency;
- renamed `deps` to `dependencies` in `intro-dependencies.json` for more
  uniformity.
2023-05-22 22:12:29 +03:00
Xavier Claessens 9d64143a4f summary: Add from which subproject each subproject have been called 2023-05-17 10:32:47 -04:00
Volker Weißmann 2699fd4b8a During reconfigure, show that no compiler was found, if compiler fails sanity check. 2023-05-13 11:06:24 +03:00
Ralf Gommers 9fe1efe357 Fix unit test that hardcoded `/` and hence broke on Windows 2023-05-05 12:23:52 -04:00
Benoit Pierre 66db4abf32 tests: fix `test_always_prefer_c_compiler_for_asm`
Handle the case where `sccache` is installed and used over `ccache`.
2023-05-03 09:17:09 -04:00
Eli Schwartz 9dbe718eb6
unittests: add magic flag global to integrate utility methods with unittest
The stdlib unittest module has a magic flag (undocumented) which
indicates that a module is part of a unittest framework.

> Truncates usercode tb at the first unittest frame.
>
> If the first frame of the traceback is in user code,
> the prefix up to the first unittest frame is returned.
> If the first frame is already in the unittest module,
> the traceback is not modified.

This avoids some ugliness, e.g. the following test error logs:

```
>       self.assertPathListEqual(intro[0]['install_filename'], ['/usr/lib/libstat.aaa'])

unittests/allplatformstests.py:432:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
unittests/baseplatformtests.py:393: in assertPathListEqual
    self.assertPathEqual(i[0], i[1])
unittests/baseplatformtests.py:384: in assertPathEqual
    self.assertEqual(PurePath(path1), PurePath(path2))
E   AssertionError: PurePosixPath('/usr/lib/libstat.a') != PurePosixPath('/usr/lib/libstat.aaa')
```

Since assertPathListEqual is our own assertion helper, we don't need to
give trace information about its internals. This change causes the error
log to become:

```
>       self.assertPathListEqual(intro[0]['install_filename'], ['/usr/lib/libstat.aaa'])
E       AssertionError: PurePosixPath('/usr/lib/libstat.a') != PurePosixPath('/usr/lib/libstat.aaa')

unittests/allplatformstests.py:432: AssertionError
```

which is a lot more readable.
2023-05-02 22:51:57 -04:00
Eli Schwartz 4e17d60d47
tests: add workarounds for python brokenness on Windows
msys2 is broken only on clang, due to -Werror issues in the python
headers as patched by msys2.

MSVC is simply weird... due to the use of an unversioned platlib/purelib
directory, the python2 and python3 components overlap.
2023-05-02 22:09:25 -04:00
Eli Schwartz 6a1427401c
tests: add a python test for bytecode compilation
Some tweaks are added to the test case so that it supports python2 as
well.
2023-05-02 19:28:35 -04:00
Cyan 6def03c787 detect_cpu: Fix mips32 detection on mips64
MIPS64 can run MIPS32 code natively, so there is a chance that a mixture
of MIPS64 kernel and MIPS32 userland exists. Before this Meson just
treats such mixture as mips64, because uname -m returns mips64.

So in this case we have to check compiler builtin defines for actual
architecture and CPU in use.

- Also fixes mips64 related detection tests in internaltests:
  Normalize mips64 as mips first, then if __mips64 is defined, return
  mips64 for mips64* machines.

  This is a bit confiusing because normally one would detect if a flag
  of 32-bit target is defined while running on a 64-bit machine. For
  mips64 it is almost just the other way around - we need to detect if
  __mips64 is set to make sure it is a mips64 environment.

Co-Authored-By: Jue Wang <maliya355@outlook.com>
2023-04-28 00:20:42 -04:00
Charles Brunet 5eb55075ba intro: add more details to generated json files
This will help with the writing of tools to generate
VisualStudio project and solution files, and possibly
for other IDEs as well.

- Used compilers a about `host`, `build` and `target` machines
  arere listed in `intro-compilers.json`
- Informations lister in `intro-machines.json`
- `intro-dependencies.json` now includes internal dependencies,
  and relations between dependencies.
- `intro-targets.json` now includes dependencies, `vs_module_defs`,
  `win_subsystem`, and linker parameters.
2023-04-20 18:31:39 +03:00
Daniele Nicolodi 1bc3d91112 minstall: Fix install_subdir() excludes with path separators on Win
The paths in meson.build use / as path separator, however, the paths
constructed during the directory structure walk use native path
separators, thus the path never compare equal to the excluded ones.
Normalize the exclusion paths before the comparison.
2023-04-14 21:37:52 +03: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
HiPhish 439a61affa Change "can not" to "cannot" throughout project
The word "cannot" expresses inability to do something whereas "can not"
expresses the ability to refrain from doing something.
2023-04-11 17:10:01 +03:00
Xavier Claessens 9c526974dc
msetup: Allow (re)configure of not empty builddir
Also prevent from using a parent directory as builddir by mistake.

Co-authored-by: Volker Weißmann <volker.weissmann@gmx.de>
Co-authored-by: Charles Brunet <charles.brunet@optelgroup.com>
2023-03-30 17:10:53 -04:00
Xavier Claessens 0418a40e68
msetup: use more consistent exceptions on exit
- MesonException for errors is clearer than SystemExit('error message')
  and provides meson-formatted "ERROR: ..."

- `raise SystemExit` with no parameter isn't obvious that it intends to
  exit successfully

While clarifying the latter, it was observed to cause
test_preprocessor_checks_CPPFLAGS() failure to be ignored. That test
checks get_define() on both c and cpp compilers, which means we need to
define either CPPFLAGS or both CFLAGS+CXXFLAGS.
2023-03-30 17:10:53 -04:00
Xavier Claessens ad151d9f11 coredata: Fix changing prefix option
This is a regression from #11537.
2023-03-30 17:01:04 -04:00
Jussi Pakkanen 78d8924d43 Condense test directories for rc1. 2023-03-28 17:18:57 +03:00
Dylan Baker 4a014d1724 Add support for meson.options as a replacement for meson_options.txt
We will still try to load `meson_options.txt` if `meson.options` doesn't
exist. Because there are some advantages to using `meson.options` even
with older versions of meson (such as better text editor handling)
we will not warn about the existence of a `meson.options` file if a
`meson_options.txt` file or symlink also exists.

The name `meson.options` was picked instead of alternative proposals,
such as `meson_options.build` for a couple of reasons:

  1. meson.options is shorter
  2. While the syntax is the same, only the `option()` function may be
     called in meson.options, while, it may not be called in meson.build
  3. While the two files share a syntax and elementary types (strings,
     arrays, etc), they have different purposes: `meson.build` declares
     build targets, `meson.options` declares options. This is similar to
     the difference between C's `.c` and `.h` extensions.

As an implementation detail `Interpreter.option_file` has been removed,
as it is used exactly once, in the `project()` call to read the options,
and we can just calculate it there and not store it.

Fixes: #11176
2023-03-28 15:01:10 +03:00
Xavier Claessens 42c4058304 unittests: Pass the exact backend name
CI runs with vs2019 and we were passing --backend=vs. This fix
reconfigure tests because we can't reconfigure with --backend=vs when
initial configuration determined the backend is actually vs2019.
2023-03-28 00:36:37 +03:00
Xavier Claessens 567d1fec9b Make backend option read-only 2023-03-28 00:36:37 +03:00
Eli Schwartz a024d75e15
backends: add a new "none" backend
It can only be used for projects that don't have any rules at all, i.e.
they are purely using Meson to:

- configure files
- run (script?) tests
- install files that exist by the end of the setup stage

This can be useful e.g. for Meson itself, a pure python project.
2023-03-20 17:22:50 -04: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
Charles Brunet a5a7b29a66 prevent lib prefix warning from pkg-config 2023-03-16 08:27:06 -04:00
Benoit Pierre 8da060706c msubprojects: fix potential error when resetting a git checkout
Untracked files need to be stashed too, or resetting may fail when
trying to (re-)apply a patch that adds one of those untracked files.
2023-03-04 20:35:30 -05:00
Xavier Claessens 0f67913dee typed_kwargs: Extend since_values and deprecated_values for types 2023-03-04 14:19:27 -05:00
Xavier Claessens f0dc61a764 interpreter: Add testcase..endtestcase clause support
This is currently only enabled when running unit tests to facilitate
writing failing unit tests.

Fixes: #11394
2023-03-01 20:13:34 -05:00
Stefan Hajnoczi b27104d920 unittests: add test for source dir stripping from rpaths
This test checks that rpaths are stripped correctly when their prefix
matches the source directory.

This test fails without the previous commit:

  1/4 visitation               FAIL            0.01s   exit status 127
  >>> MALLOC_PERTURB_=150 meson/tmpy7c0joy5/patron
  ――――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――――――――――――――――――――
  stderr:
  meson/tmpy7c0joy5/patron: error while loading shared libraries: libalexandria.so: cannot open shared object file: No such file or directory

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
2023-03-01 08:56:46 -05: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
Charles Brunet 04f233a80d allow install script to run in dry-run mode 2023-02-14 10:50:10 -05:00