Commit Graph

26 Commits

Author SHA1 Message Date
Andrew McNulty bc30d5982d meson command tests: clean up temporary script upon completion 2024-09-23 09:17:49 -07:00
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
Eli Schwartz 3070bd49a2 do not resolve symlinks when calculating the meson command
We embed the route to executing meson in various cases, most especially
regen rules in build.ninja. And we take care to ensure that it's a
canonicalized path. Although the code has moved around over time, and
adapted in ways both bad and good, the root of the matter really comes
down to commit 69ca8f5b54 which notes the
importance of being able to run meson from any location, potentially
not on PATH or anything else.

For this reason, we switched from embedding sys.argv[0] to
os.path.realpath, a very heavy stick indeed. It turns out that that's
not actually a good thing though... simply resolving the absolute path
is enough to ensure we can accurately call meson the same way we
originally did, and it avoids cases where the original way to call meson
is via a stable symlink, and we resolved a hidden location.

Homebrew does this, because the version of a package is embedded into
the install directory. Even the bugfix release. e.g.

```
/opt/homebrew/bin/meson
```

is symlinked to

```
/opt/homebrew/Cellar/meson/1.0.0/bin/meson
```

Since we went beyond absolutizing the path and onwards to canonicalizing
symlinks, we ended up writing the latter to build.ninja, and got a
"command not found" when meson was upgraded to 1.0.1. This was supposed
to work flawlessly, because build directories are compatible across
bugfix releases.

We also get a "command not found" when upgrading to new feature
releases, e.g. 0.64.x to 1.0.0, which is a terrible error message. Meson
explicitly "doesn't support" doing this, we throw a MesonVersionMismatchException
or in some cases warn you and then effectively act like --wipe was given.
But the user is supposed to be informed exactly what the problem is, rather
than getting "command not found".

Since there was never a rationale to get the realpath anyways, downgrade
this to abspath.

Fixes #11520
2023-03-28 15:29:52 +03:00
Eli Schwartz 118396f344 runpython: make it work for -c as well
In commit 4e4f97edb3 we added support for
runpython to accept `-c 'code to execute'` in addition to just script
files. However, doing so would mangle the sys.argv in the executed code
-- which assumes, as python itself does, that argv is the stuff after
the code to execute. We correctly handled this for script files, but the
original addition of -c support pushed this handling into a script-file
specific block.
2023-01-30 15:13:06 +02:00
Eli Schwartz 908a78dbc2
tests: make the command tests work when python is not the one in the shebang
We test a couple ways of running the meson command, and double check
that the debug logs record the meson command used (including python).
But when running the meson command as an executable instead of as a
python script, we see whichever version `env` in the shebang sees.

Fix this by mocking the python command as well.
2022-11-17 19:10:51 -05:00
Jussi Pakkanen b0eecda108 Only use Debian path fixing on old distros. 2022-10-06 01:07:17 +03:00
Jussi Pakkanen a2079939de Use system install scheme rather than the incorrect Debian one. 2022-04-23 11:57:06 +03:00
Eli Schwartz 751f84405e
pyupgrade --py37-plus 2022-01-10 18:36:56 -05:00
Daniel Mensinger 3e396b3782
fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Eli Schwartz e494be9b02 setuptools: don't hardcode list of modules to install, use find_packages
And don't run a pointless test to verify that the hardcoded list has
been manually maintained correctly. The same test rules used there can
translate directly to find_packages pattern rules.
2021-03-09 22:59:56 +02: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 0fa808f706 Add script to create a zipapp.
Invoke create_zipapp.py from the root of the repository and it will
create a minimal zipapp with only the mesonbuild module code and a
__main__.py directly copied from meson.py

The meson.py launcher already tracks the desired entry point, and its
only other effect is to add the mesonbuild directory to the path if it
exists, which it won't in the zipapp. So there's no need to duplicate
this into another __main__.py
2020-11-27 18:12:08 +02: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
Daniel Mensinger 59910c437a Fix setuptools 49 test. (fixes #7452) 2020-07-19 14:45:59 +03:00
Michael Hirsch 6f2eb6233c pep8: add missing import, remove unused variable 2020-06-15 23:33:40 +03: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
Daniel Mensinger ec0998e694
tests: Ignore all files in 'data' directories 2019-06-28 17:02:20 +02:00
Christoph Reiter 5a9c9c70df tests: fix test_meson_installed after the recent appveyor image update
Since the last appveyor image update which also included a msys2 update
test_meson_installed() fails for the msys2 mingw jobs complaining that
the install path isn't included in PYTHONPATH.

It complains that "site-packages\" isn't included in "site-packages" ignoring
that the separator should be ignored here. Work around the issue by making
sure that the path set as PYTHONPATH always ends with os.sep.
2018-11-14 15:00:01 -08:00
Michael Forney 50b2ef7354 Consider 'samu' when looking for ninja command
samu prints a different message when the build is a no-op, so make
assertBuildIsNoop consider that as well.

Also, if compile_commands.json cannot be found, just skip the test. This
seems reasonable since meson just produces a warning if `ninja -t compdb`
fails.

Finally, only capture stdout in run_meson_command_tests.py, since the
backend may print messages the tests don't recognize to stderr.

Fixes #3405.
2018-11-11 00:21:47 +02:00
Niklas Claesson 4ef4edee2f tests runners: Refactor out global variables and add argparse 2018-10-10 21:19:06 +02:00
Nirbheek Chauhan 8277d94e24 meson_command_tests: Don't pass pathlib.Path to open [skip appveyor]
Closes https://github.com/mesonbuild/meson/issues/4047
2018-08-18 19:13:15 +03:00
Nirbheek Chauhan c0413f5d49 setup: Add tests for the installed files list
Ensure that the installed files list matches what we expect, to avoid
surprises at release time.
2018-08-12 01:18:58 +05:30
Nirbheek Chauhan 2ee28029f9 Install meson.exe as the entrypoint on Windows
Thanks to Rafael Rivera for the suggestion

Fixes https://github.com/mesonbuild/meson/issues/1877
2018-08-11 03:19:57 +05:30
Christoph Burger-Scheidlin e4a83e47d4 Fix __main__.py for zipapp to work
0a035de removed main from meson.py breaking the call from __main__.py.
This causes zipapps to fail, since the call to meson.main() fails.

Copying the invocation from meson.py fixes this issue.

Additionally, add a test to run_meson_command_tests.py that
builds a zipapp from the source and attempts executing this
zipapp with --help to ensure that the resulting zipapp is
properly executable.
2018-08-07 03:55:35 -07:00
Nirbheek Chauhan 0a035dea6d Set the meson command to use when we know what it is
Instead of using fragile guessing to figure out how to invoke meson,
set the value when meson is run. Also rework how we pass of
meson_script_launcher to regenchecker.py -- it wasn't even being used

With this change, we only need to guess the meson path when running
the tests, and in that case:

1. If MESON_EXE is set in the env, we know how to run meson
   for project tests.
2. MESON_EXE is not set, which means we run the configure in-process
   for project tests and need to guess what meson to run, so either
   - meson.py is found next to run_tests.py, or
   - meson, meson.py, or meson.exe is in PATH

Otherwise, you can invoke meson in the following ways:

1. meson is installed, and mesonbuild is available in PYTHONPATH:
   - meson, meson.py, meson.exe from PATH
   - python3 -m mesonbuild.mesonmain
   - python3 /path/to/meson.py
   - meson is a shell wrapper to meson.real
2. meson is not installed, and is run from git:
   - Absolute path to meson.py
   - Relative path to meson.py
   - Symlink to meson.py

All these are tested in test_meson_commands.py, except meson.exe since
that involves building the meson msi and installing it.
2018-06-01 19:20:04 +00:00