Commit Graph

100 Commits

Author SHA1 Message Date
Eli Schwartz a580fac83a
tests: allow setting MESON_CI_JOBNAME=thirdparty
This is treated by the test harness as though unset, i.e. we do normal
skipping and don't assume we are running in Meson's own project CI.

However, it has one distinction which is that it isn't an error to set
$CI without setting $MESON_CI_JOBNAME, if it is in fact set but to the
ignored value.

This lets automated workflows such as Linux distro testing, particularly
alpine linux, set $CI or have it set for them by default, without
messing things up.

Also it has the advantage of $CI actually enabling useful benefits! We
will still assume that this thirdparty environment wants to force
verbose logging (printing testlogs, running ninja/samu with -v) and
colorize the console.
2022-02-17 14:48:27 -05:00
Eli Schwartz 4274e0f42a unittests: fine-tune the check for whether we are in CI
The $CI environment variable may be generally set by Github or Gitlab
actions, and is not a reliable indicator of whether we are running "CI".
It could also, for an absolutely random example that didn't *just
happen*, be Alpine Linux's attempt to enable the Meson testsuite in
their packaging, which... uses Gitlab CI.

In this case, we do want to perform normal skipping on not-found
requirements. Instead of checking for $CI, check for $MESON_CI_JOBNAME
as we already use that in all of our own CI jobs for various reasons.

This makes it easier for linux distros to package Meson without
accumulating hacks like "run the testsuite using `env -u CI`".
2022-02-14 14:46:01 +05:30
Jan Tojnar df451f1013 meson: Allow directory options outside of prefix
This bring us in line with Autotools and CMake and it is useful
for platforms like Nix, which install projects
into multiple independent prefixes.

As a consequence, `get_option` might return absolute paths for some
directory options, if a directory outside of prefix is passed.

This is technically a backwards incompatible change but its effect
should be minimal, thanks to widespread use of `join_paths`/`/` operator
and pkg-config generator module. It should only cause an issue when
a path were constructed by concatenating the value of directory path option.

Also remove a comment about commonpath since we do not use that since
<00f5dadd5b>.

Fixes: https://github.com/mesonbuild/meson/issues/2561
2022-02-09 11:04:59 -05:00
Daniel Mensinger 2e2ca5a877 cmake: ci: Skip tests on Ubuntu Bionic where CMake is stuck on 3.10 2022-02-03 11:25:59 -05:00
Paolo Bonzini 7a975d75cf unittests: check that "verbose: true" works on tests
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2022-02-01 09:05:27 +01:00
Nirbheek Chauhan 19684d23e8 unittests: Fix warning about distutils deprecation
unittests/rewritetests.py:19: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
  from distutils.dir_util import copy_tree
2022-01-30 02:13:42 +05:30
Nirbheek Chauhan 2512c25c0b ninja backend: Fix usage of same constants file for native and cross
For example:
```
meson builddir \
        --native-file vs2019-paths.txt \
        --native-file vs2019-win-x64.txt \
        --cross-file vs2019-paths.txt \
        --cross-file vs2019-win-arm64.txt
```
This was causing the error:

> ERROR: Multiple producers for Ninja target "/path/to/vs2019-paths.txt". Please rename your targets.

Fix it by using a set() when generating the list of regen files, and
add a test for it too.
2022-01-30 02:13:42 +05:30
Dylan Baker 574525673f interpreterobjects: use typed_* for configuration_data.set*
This removes the ability to use ConfigurationData as a dict, but
restricting the inputs to `str | int | bool`. This may be a little too
soon for this, and we may want to wait on that part, it's only bee 8
months since we started warning about this.
2022-01-18 17:53:29 -05:00
Dylan Baker 6b272973e0 dependencies: don't pass kwargs from get_pkgconfig_variable
This is a layering violation, we're relying on the way the interpreter
handles keyword arguments. Instead, pass them as free variables,
destructuring in the interpreter
2022-01-18 17:53:29 -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
Eli Schwartz 98a41ec24e
manually clean up some python 3.6 era code 2022-01-10 18:36:57 -05:00
Eli Schwartz 140097faf0
port from embedded data to importlib.resources 2022-01-10 18:36:57 -05:00
Eli Schwartz be6e09bfdb
condense lines 2022-01-10 18:36:57 -05:00
Eli Schwartz 751f84405e
pyupgrade --py37-plus 2022-01-10 18:36:56 -05:00
Jussi Pakkanen 117ba23071 Condense test directory numbers for rc1. 2022-01-02 19:07:36 +02:00
Nirbheek Chauhan 37b122b87e unit tests: Don't check quoting with multiple libs
pkgconf has a bug on MSYS2 due to which prefixes with spaces are not
handled correctly if the library has a Requires: on another library
and both have prefixes with spaces in them.

See: https://github.com/pkgconf/pkgconf/issues/238

So move the unit test to libanswer.pc instead of libfoo.pc till that
is fixed.
2021-12-22 12:12:11 +05:30
Nirbheek Chauhan 06b1132f82 Set RPATH for all non-system libs with absolute paths
If a pkg-config dependency has multiple libraries in it, which is the
most common case when it has a Requires: directive, or when it has
multiple -l args in Libs: (rare), then we don't add -Wl,-rpath
directives to it when linking.

The existing test wasn't catching it because it was linking to
a pkgconfig file with a single library in it. Update the test to
demonstrate this.

This function was originally added for shared libraries in the source
directory, which explains the name:
https://github.com/mesonbuild/meson/pull/2397

However, since now it is also used for linking to *all* non-system
shared libraries that we link to with absolute paths:
https://github.com/mesonbuild/meson/pull/3092

But that PR is incomplete / wrong, because only adding RPATHs for
dependencies that specify a single library, which is simply
inconsistent. Things will work for some dependencies and not work for
others, with no logical reason for it.

We should add RPATHs for *all* libraries. There are no special length
limits for RPATHs that I can find.

For ELF, DT_RPATH or DT_RUNPATH are used, which are just stored in
a string table (DT_STRTAB). The maximum length is only a problem when
editing pre-existing tags.

For Mach-O, each RPATH is stored in a separate LC_RPATH entry so there
are no length issues there either.

Fixes https://github.com/mesonbuild/meson/issues/9543

Fixes https://github.com/mesonbuild/meson/issues/4372
2021-12-22 12:12:11 +05:30
Celeste Wouters c5148d8c73 rewriter: create {add,rm}_extra_files commands
Add ability to mutate a target's `extra_files` list through the
rewriter.

The logic is copied from sources add/rm, but changes the `extra_files`
kwarg instead of the sources positional argument.
Has additional logic to handle creating the `extra_files` list if it
doesn't exist.
2021-12-15 21:21:29 +01:00
Dylan Baker f5d961f127 add message option to since_values and deprecated_values
This allows these two arguments to take a tuple of (version, message),
where the message will be passed to Feature*'s message parameter
2021-12-06 20:06:14 -05:00
Dylan Baker 51845a3a45 unittests/internal: use more subTest 2021-12-06 20:06:14 -05:00
Dylan Baker 930cbdb86d Add deprecated_message and since_message to KwargInfo
For passing an extra message to Feature*

This allows providing a more detailed message.
2021-12-06 20:06:14 -05:00
Dylan Baker b8ba493044 unittests/internal: use mock and subTest
This just makes things a little cleaner, and allows more accurate error
reporting.
2021-12-06 20:06:14 -05:00
Dylan Baker 82136da933 interpreterbase/decorators: Fix types of deprecated_values and since_values
Which shouldn't be Dict[str, str], they should be Dict[_T, str], as nay
value that can be passed to types is valid here.
2021-12-06 20:06:14 -05:00
Eli Schwartz bea735dd76
make sure files arguments to compiler.compiles and friends, performs rebuild
If the compiler check is updated as a string in meson.build, we force
rebuild, which is a good thing since the outcome of that check changes
the configuration context and can enable or disable parts of the build.

If the compiler check came from a files() object then we didn't add a
regen rule on those files.

Fixes #1656
2021-11-28 11:52:36 -05:00
Jussi Pakkanen 11e26a0fa9
Merge pull request #9599 from dcbaker/submit/typed_kwargs-message-improvements
Improve error messages for typed_kwarg type mismatches in containers
2021-11-27 22:33:15 +02:00
Dylan Baker bfa0c61877 tests: add a test for OptionKey.from_string 2021-11-25 18:14:06 +02:00
Nirbheek Chauhan af5993fffd shared_module: Add soname when used as a link target
Emit a detailed deprecation warning that explains what to do instead.
Also add a unittest.

```
DEPRECATION: target prog links against shared module mymod, which is incorrect.
             This will be an error in the future, so please use shared_library() for mymod instead.
             If shared_module() was used for mymod because it has references to undefined symbols,
             use shared_libary() with `override_options: ['b_lundef=false']` instead.
```

Fixes https://github.com/mesonbuild/meson/issues/9492
2021-11-24 23:18:53 +05:30
Dylan Baker bd9d981871 unit tests: Extend prebuilt test to test intermediate
This provides coverage for the bug:
https://github.com/mesonbuild/meson/issues/9542
2021-11-24 02:23:57 +05:30
Dylan Baker 457e2d9812 unittests: use UnitTest.addCleanup a bit 2021-11-24 02:23:57 +05:30
Paolo Bonzini 8581a2b122 interpreter: extract_objects provides a valid source
This ensures that there is no warnings when running meson on
test cases/common/22 object extraction.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-11-23 18:10:15 +05:30
Dylan Baker d412f0aff5 unittests: cover cases here two of the same wrong type are provided
We don't want to get something like "expected array[str], but got
array[int | int]", we really want `arrayp[int]`.
2021-11-22 12:27:17 -08:00
Dylan Baker 762c504612 typed_kwargs: use | for type unions, not ,
Python uses this syntax now, as does typescript and other languages
2021-11-22 12:24:33 -08:00
Dylan Baker ecc47d67a9 typed_kwargs: provide better error messages for wrong container types
Currently, if you pass a `[]string`, but the argument expects
`[]number`, then you get a message like `expected list[str] but got
list`. That isn't helpful. With this patch arrays and dictionaries will
both print messages with the types provided.
2021-11-22 12:24:14 -08:00
Eli Schwartz 8dbb0ee476
Feature kwargs decorator: automatically report the nodes which trigger an issue 2021-11-20 20:48:30 -05:00
Dylan Baker cc8018744d tests: replace python2 framework with metal
The bundled python is deprecated, metal is unlikely to be deprecated any
time soon, so let's use that.
2021-11-18 16:55:14 -05:00
Xavier Claessens c8d125653d
python.dependency(): Do not stop when first candidate is not found
It has to lookup the dependency with required=False otherwise it raises
an exception when the first candidate (pkg-config) failed.
2021-11-02 14:24:08 -04:00
Nirbheek Chauhan 04ae1cfb79 Fix cygwin test failure due to shortpath usage
Two tests are failing on Cygwin because the argument is passed as
a long-path and the Path is ending up as a short-path:

AllPlatformTests.test_run_target_files_path

  Traceback (most recent call last):
    File "/cygdrive/d/a/meson/meson/test cases/common/51 run target/check-env.py", line 22, in <module>
      assert build_root == env_build_root
  AssertionError

SubprojectsCommandTests.test_purge

  >       self.assertEqual(deleting(out), sorted([
              str(self.subprojects_dir / 'redirect.wrap'),
              str(self.subprojects_dir / 'sub_file'),
              str(self.subprojects_dir / 'sub_git'),
          ]))
  E       AssertionError: Lists differ: ['/cygdrive/c/Users/runneradmin/AppData/Local/Temp/tmpeaa2a49[205 chars]git'] != ['/cygdrive/c/Users/RUNNER~1/AppData/Local/Temp/tmpeaa2a49z/s[196 chars]git']

  [...]

  ['/cygdrive/c/Users/runneradmin/AppData/Local/Temp/tmpeaa2a49z/src/subprojects/redirect.wrap',
                      ^^^^^^^^^^^
  ['/cygdrive/c/Users/RUNNER~1/AppData/Local/Temp/tmpeaa2a49z/src/subprojects/redirect.wrap',
                      ^^^^^^^^

The fix is to not use the tempdir for all tests, but only for tests
that check the mode.
2021-10-31 19:22:36 +05:30
Xavier Claessens 3902bd4ef1 Fix add_install_script() ignoring install_tag
Fixes: #9454
2021-10-27 20:49:28 -04:00
Xavier Claessens ef255db73a test_clang_format: Do not assume meson source is in git
Fixes: #9437
2021-10-27 15:32:57 -04:00
Eli Schwartz 739de7b088
unittests: use better assert methods
assertTrue and assertFalse are recommended against, if you can get a
more specific assertion. And sometimes it is considerably shorter, for
example we have a custom assertPathExists which we can take advantage
of.
2021-10-26 20:53:43 -04:00
Eli Schwartz 67792fc223
do not save unused variable
Constructing a PackageDefinition is enough to assert that it raises an
error.
2021-10-26 20:53:43 -04:00
Eli Schwartz e0b86a8d38
remove unused variable
It never made sense here to save self.init() which returns a string
containing a log or stdout or something, and which was never actually
used.

Also we then overwrote the variable with a pathname...
2021-10-26 20:53:42 -04:00
Eli Schwartz 7b53c26501
remove dead code that is immediately overridden
In commit d932cd9fb4, we migrated to
meson's own static linker definition, and the old code that hardcoded
two of the possible exelists should have been removed in the process.
2021-10-26 20:53:42 -04:00
Eli Schwartz 1979132a9d
do not save variable when all we want is the side effect of popping it
It's redefined on every loop iteration, and as the comment says, we just
want to make sure the next loop skips a value.
2021-10-26 20:53:41 -04:00
Xavier Claessens 8a0d12ec29 optinterpreter: Fix builtin option names not being reserved anymore 2021-10-14 14:17:50 -04:00
Paolo Bonzini 5e96730d7d introspect: include choices for array options
There was even a test covering this, but it did not fail due to a typo.
2021-10-14 09:04:25 -04:00
Christian Clauss a5020857f3 Fix typos discovered by codespell 2021-10-10 16:12:25 -04:00
Xavier Claessens 32b7cbd4a7 clangformat: Only format files tracked by git by default 2021-10-10 14:13:35 -04:00
Eli Schwartz 0a3a9fa0c3
ar linker: generate thin archives for uninstalled static libraries
Since they will never be used outside of the build directory, they do
not need to literally contain the .o files, and references will be
sufficient.

This covers a major use of object libraries, which is that the static
library would potentially take up a lot of space by including another
copy of every .o file.

Fixes #9292
Fixes #8057
Fixes #2129
2021-10-10 13:32:22 -04:00
Xavier Claessens 709d151eb9 typed_kwargs: Fix when ContainerTypeInfo is used in a tuple
info.types could be a tuple like (str, ContainerTypeInfo()). That means
we have to check types one by one and only print error if none of them
matched.

Also fix the case when default value is None for a container type, it
should leave the value to None to be able to distinguish between unset
and empty list.
2021-10-09 18:13:34 -04:00