Commit Graph

265 Commits

Author SHA1 Message Date
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
Xavier Claessens dacd11a624 pkgconfig: Cache the implementation instance 2023-09-18 13:51:27 -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
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 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
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
Eli Schwartz cfc1abcfaf
project tests: add log of the setup command being run
Followup to commit 2acb6ee79e.
2023-03-20 17:22:50 -04:00
Eli Schwartz 2a0b80eb67
tests: fix regression that broke mtest_inprocess
In commit faf79f4539 we broke this utility
function by referencing a non-existent variable. Fortunately, the only
time we ever used said function was once, and that in a test case where
we tested that it raised a MesonException before the undefined variable
error could occur.
2023-03-20 16:58:16 -04:00
Eli Schwartz 7e5a1d6089 CI: log individual steps in run_tests 2023-02-13 09:09:10 -05:00
Eli Schwartz 608a6196a0
python 3.11: suppress an incorrect EncodingWarning
python 3.11 adds a warning that in 3.15, UTF-8 mode will be default.
This is fantastic news, we'd love that. Less fantastic: this warning is
silly, we *want* these checks to be affected. Plus, the recommended
alternative API would (in addition to warning people when UTF-8 mode
removed the problem) also require using a minimum python version of 3.11
(in which the warning was added) or add verbose if/else soup.

The simple, and obvious, approach is to add a warnings filter to hide
it.
2022-11-03 15:44:41 -04:00
Eli Schwartz 5bfab845d0
compilers: directly import from subpackages
It turns out we don't generally need to proxy every compiler ever
through the top-level package. The number of times we directly poke at
one is negligible and direct imports are pretty clean.
2022-09-19 15:19:00 -04:00
Marvin Scholz 34ea8fdf98 unittests: move get_convincing_fake_env_and_cc to run_tests.py 2022-03-31 10:55:55 +02:00
Eli Schwartz a6e08e8fa7
use a more sane check instead of run_custom_lint
Unfortunately, checking for strings without context is exceedingly prone
to false positives, while missing anything that indirectly opens a file.

Python 3.10 has a feature to warn about this though -- and it uses a
runtime check which runs at the same time that the code fails to open
files in the broken Windows locale. Set this up automatically when
running the testsuite.

Sadly, Python's builtin feature to change the warning level, e.g. by
setting EncodingWarning to error at startup, is utterly broken if you
want to limit it to only certain modules. This is tracked in order to be
more efficiently ignored at https://bugs.python.org/issue34624 and
https://github.com/python/cpython/pull/9358

It is also very trigger happy and passing stuff around via environment
variable either messes with the testsuite, or with thirdparty programs
which are implemented in python *such as lots of gnome*, or perhaps
both.

Instead, add runtime code to meson itself, to add a hidden "feature".
In the application source code, running the 'warnings' module, you can
actually get the expected behavior that $PYTHONWARNINGS doesn't have. So
check for a magic testsuite variable every time meson starts up, and if
it does, then go ahead and initialize a warnings filter that makes
EncodingWarning fatal, but *only* when triggered via Meson and not
arbitrary subprocess scripts.
2022-03-01 21:42:52 -05:00
Eli Schwartz 62a6c95c13
unittests: make ninja detection faster and more robust
Instead of blindly assuming when $CI is set that `ninja` is always
correct and always new enough, check for it the same way we do when $CI
is not set.

Instead of special casing when $CI is set and skipping ninja detection
in subprocess tests (by assuming it is always `ninja`), skip detection
in subprocess tests all the time, by passing this information around
across processes after the first time it is looked up.

This means that local (non-CI) tests are faster too!

Fixes running unittests in alpine linux using samu. Although ninja is a
symlink to samu, the exact output string on no-op builds is different,
which we already handle, but what we don't handle is the fact that samu
prints a third case when you invoke it as `ninja`. If $CI is exported,
then the unittests ignored $NINJA entirely.

Fixes running unittests when $CI is set, `samu` exists and `ninja` does
not exist. This is not currently the case anywhere, but may be in the
future; why not fix it now?
2022-02-17 14:48:27 -05:00
Nirbheek Chauhan faf79f4539 Add a test for the --vsenv meson setup option
The tests and the unittests both unconditionally call setup_vsenv()
because all tests are run using the backend commands directly: ninja,
msbuild, etc.

There's no way to undo this vs env setup, so the only way to test that
--vsenv works is by:

1. Removing all paths in PATH that provide ninja
2. Changing setup_vsenv(force=True) to forcibly set-up a new vsenv
   when MESON_FORCE_VSENV_FOR_UNITTEST is set
3. Mock-patching build_command, test_command, install_command to use
   `meson` instead of `ninja`
4. Asserting that 'Activating VS' is in the output for all commands
5. Ensure that compilation works because ninja is picked up from the
   vs env.

I manually checked that this test actually does fail when the previous
commit is reverted.
2022-01-16 23:42:19 +05:30
Xavier Claessens 928078982c Add --vsenv command line option and active VS only when needed 2021-10-10 23:15:18 +03:00
Daniel Mensinger 28175bbee2
pathlib: Patch pathlib to work around some bugs (fixes #7295) 2021-06-29 11:28:08 +02:00
Daniel Mensinger 765aff5a42 coverage: Enable coverage reports 2021-06-22 21:05:11 +03:00
Daniel Mensinger 99a91df844 tests: clear mesonlib.project_meson_versions (which **really** needs a refactor) 2021-06-18 23:48:33 +02:00
Daniel Mensinger b2112bc4f6 tests: Always enable the traceback in run_project_tests.py 2021-06-18 23:48:33 +02:00
Daniel Mensinger 7fc755b334 typing: Fully annotate run_project_tests.py 2021-06-09 13:25:36 +02:00
Jussi Pakkanen a9b65b421e Remove HFS workaround as everyone should use APFS by now. 2021-05-29 00:22:38 +03:00
Jussi Pakkanen 0b2a7300c0 Set up VS environment automatically when run. 2021-05-13 11:03:10 +03:00
Jussi Pakkanen 1d06d4ca1a Set unittest backend with an argument rather than an envvar. 2021-05-08 21:35:08 +03:00
Jussi Pakkanen 0e4c358f35 Xcode: add objective C flags to plain C because Xcode requires it. 2021-04-25 15:35:13 +03:00
Eli Schwartz 6a0fabc647
mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
2021-03-04 17:16:11 -05:00
Eli Schwartz 4340bf34fa
various python neatness cleanups
All changes were created by running

"pyupgrade --py3-only --keep-percent-format"

and committing the results. I have not touched string formatting for
now.

- use set literals
- simplify .format() parameter naming
- remove __future__
- remove default "r" mode for open()
- use OSError rather than compatibility aliases
- remove stray parentheses in function(generator) scopes
2021-03-04 17:11:26 -05:00
Dylan Baker 44c836e0d9 add a script to run a single test
As a Meson developer it's often frustrating to have a single functional
test with a regression. These tests can be awkward to reproduce,
especially when they make use of a test.json file. This script provides
a simmple interface to call functional tests 1 at a time, regardless of
whether they use a test.json or not. If they do use a test.json, and
have a matrix, then the `--subtest` option can be used to select spcific
combinations, for example:
```sh
./run_single_test.py "test cases/frameworks/15 llvm" --subtest 1
```
will run only the second (zero indexed of course) subtest from the llvm
test cases.

This is not a super elegent script, but this is super useful.
2021-02-23 09:08:55 -08:00
Dylan Baker 3e11da6db5 run_*_tests: Add some type annotations 2021-02-23 08:38:19 -08:00
Paolo Bonzini 9ba7b0ebd0 mlog: add __str__ method to AnsiDecorator
Automatically colorize the text when printing the AnsiDecorator, based
on the result of mlog.colorize_console().  This is how AnsiDecorator
is used most of the time anyway.
2021-01-21 08:54:35 -05:00
Dylan Baker e81acbd606 Use a single coredata dictionary for options
This patches takes the options work to it's logical conclusion: A single
flat dictionary of OptionKey: UserOptions. This allows us to simplify a
large number of cases, as we don't need to check if an option is in this
dict or that one (or any of 5 or 6, actually).
2021-01-04 12:20:58 -08:00
Dylan Baker f9b19e73a5 move OptionKey to mesonlib
There's starting to be a lot of things including coredata that coredata
needs to itself include. putting it in mesonlib makes more sense
2021-01-04 12:20:40 -08:00
Dylan Baker fe973d9fc4 use OptionKey for compiler_options 2021-01-04 12:20:39 -08:00
Dylan Baker f6672c7a19 use real pathlib module
We added the _pathlib module to work around defeciencies in python 3.5's
implementation, since we now rely on 3.6 lets drop this
2020-11-20 15:08:40 -08:00
Daniel Mensinger 1dfaccfd91 pathlib: Fix resolve() by overriding it in Python 3.5 2020-10-04 10:45:48 +02:00
Dylan Baker bb3fe3c451 compilers/mixins/clike: fix mypy issues 2020-09-24 12:14:13 -07:00
Dylan Baker 80ec7ec681 tests: Make monkey patching smarter
There are two problems here. The first is that we're doing manual monkey
patching which is fragile and verbose, when unittest.mock is designed
specifically to solve this exact problem. The second is that we're
monkey patching os.environ at two different levels with the same
information. So let's only do it once.
2020-09-17 11:26:50 +00:00
Jon Turney 36600d7465 Add a test run in an environment which only has a cross compiler
Add '--cross-only' option to run_tests.py, so we can arrange not to run
tests in the 'native' suite when only a cross-compiler is available, as
they can't succeed.
2020-09-10 07:20:41 +00:00
Daniel Mensinger 8f95efe40b
typing: fixup of #7688
This bug not beeing caught in review is another reason for
adding strict typing support to meson.
2020-09-08 20:15:59 +02:00
Michael Hirsch 1ec84c570f run_*tests*.py: print Meson version at start of test suite
on some systems, tests may take over an hour to run--only to find
you might have used an unintended Meson version (e.g. release instead
of dev). This change prints the Meson version at the start of the
run_*tests*.py scripts.

Also, raise SystemExit(main()) is preferred in general over
sys.exit(main())
2020-06-15 23:33:40 +03:00
Jon Turney f107f9b396
Make colourize_console() a function
Currently, colourize_console is a constant, set at process
initialization.

To allow the actual stdout to be easily compared with the expected when
running tests, we want to allow colourization to be on for the test
driver, but not for the in-process configure done by run_configure,
which has stdout redirected from a tty to a pipe.

v2:
Cache _colorize_console per file object

v3:
Reset cache on setup_console()
2020-04-30 20:11:31 +01:00
John Ericson 278c294aa4 Compiler options per lang
A current rather untyped storage of options is one of the things that
contributes to the options code being so complex. This takes a small
step in synching down by storing the compiler options in dicts per
language.

Future work might be replacing the langauge strings with an enum, and
defaultdict with a custom struct, just like `PerMachine` and
`MachineChoice`.
2020-04-20 23:23:15 +03:00
Nirbheek Chauhan be486a2ec8 ninjabackend: List PDBs in output list for targets
This is more correct, and forces the target(s) to be rebuilt if the
PDB files are missing. Increases the minimum required Ninja to 1.7,
which is available in Ubuntu 16.04 under backports.

We can't do the same for import libraries, because it is impossible
for us to know at configure time whether or not an import library will
be generated for a given DLL.
2020-02-22 06:49:34 +05:30
Jon Turney 26d1c2a52d
Specify crossfile use in CI job configuration
Pull the crossfile specification out of run_test.py so it can be
specified in the CI job configuration.

Also make some fixes to output ordering in run_test.py.
2020-01-28 21:41:22 +00:00
Nirbheek Chauhan b9d0c7a169 run_tests: Fix detection of ninja 1.9
`get_backend_commands()` doesn't get called when we run tests as
subprocesses, so detect ninja on import. This should speed up CI.

Fixes https://github.com/mesonbuild/meson/issues/5888
2020-01-15 12:14:30 +05:30
Dylan Baker 31bb6eae45 run_tests.py: use mlog.log_once to avoid spamming ninja < 1.9 warnings 2019-12-13 09:57:05 -05:00
Daniel Mensinger 286b9f0921 lgtm: Fix Module imported with `import` and `import from` 2019-12-05 00:22:10 +02:00
Daniel Mensinger 80ec5e9d28 Fix all flake8 warnings 2019-10-20 17:44:43 +03:00
Aleksey Gurtovoy 75daed27bc mesonlib.split_args/quote_arg/join_args 2019-09-05 23:42:47 +03:00
Nirbheek Chauhan 35732dfaa1 tests: Require ninja 1.9 on CI
Also, print messages when we have to enable the timestamp resolution
workaround.
2019-09-01 22:58:33 +03:00