Commit Graph

102 Commits

Author SHA1 Message Date
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
Nirbheek Chauhan 1b1c66d7bc meson.py: sys.path requires str, not pathlib.Path 2018-06-10 01:44:43 +00: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
Nirbheek Chauhan f56b402a5b Revert "mesonlib: handle meson exe wrappers"
This reverts commit 0627e9d616.

Breaks installation: https://github.com/mesonbuild/meson/issues/3647

Will be restored once that can be fixed.
2018-05-31 15:40:10 +05:30
Martin Kelly 0627e9d616 mesonlib: handle meson exe wrappers
There are cases when it is useful to wrap the main meson executable with
a script that sets up environment variables, passes --cross-file, etc.
For example, in a Yocto SDK, we need to point to the right meson.cross
so that everything "just works", and we need to alter CC, CXX, etc. In
such cases, it can happen that the "meson" found in the path is actually
a wrapper script that invokes the real meson, which may be in another
location (e.g. "meson.real" or similar).

Currently, in such a situation, meson gets confused because it tries to
invoke itself using the "meson" executable (which points to the wrapper
script) instead of the actual meson (which may be called "meson.real" or
similar). In fact, the wrapper script is not necessarily even Python, so
the whole thing fails.

Fix this by using Python imports to directly find mesonmain.py instead
of trying to detect it heuristically. In addition to fixing the wrapper
issue, this should make the detection logic much more robust.
2018-05-30 18:29:16 +00:00
Jon Turney cd5dba5358 Fix flake8 'imported but unused' reports
$ flake8 | grep F401
./meson.py:17:1: F401 'mesonbuild.mesonlib' imported but unused
./meson.py:18:1: F401 'locale' imported but unused
./run_unittests.py:24:1: F401 'sys' imported but unused
./mesonbuild/minit.py:2:1: F401 'pyclbr.Function' imported but unused
./mesonbuild/minit.py:18:1: F401 'os' imported but unused
./mesonbuild/backend/vs2010backend.py:15:1: F401 'sys' imported but unused
./mesonbuild/backend/xcodebackend.py:19:1: F401 'sys' imported but unused
./mesonbuild/dependencies/ui.py:20:1: F401 'shutil' imported but unused
./mesonbuild/modules/python3.py:15:1: F401 'sys' imported but unused
./mesonbuild/modules/unstable_icestorm.py:15:1: F401 '..compilers' imported but unused
./mesonbuild/modules/unstable_icestorm.py:15:1: F401 '..mlog' imported but unused
./test cases/common/98 gen extra/srcgen3.py:3:1: F401 'os' imported but unused
2018-03-03 21:06:45 +00:00
Jussi Pakkanen 88756bfe95 Print UTF-8 warning only when actually encountering non-ascii filenames. 2017-12-14 23:49:12 +02:00
Luke Shumaker ef9a49d464 fix a typo in the UTF-8 warning message 2017-09-20 14:02:57 -04:00
Jussi Pakkanen 20b57d6e15 Write deprecation warnings to stderr. 2017-08-02 22:01:13 +03:00
Jussi Pakkanen 59a35c4c53 Print deprecation warnings on old style commands. 2017-08-02 22:01:13 +03:00
Jussi Pakkanen 4ef495c596 Do not warn about non-utf8 locales on Windows. 2016-12-10 00:57:09 +02:00
Nirbheek Chauhan 34394afce6 meson.py: Warn if the encoding is not UTF-8 compatible 2016-11-23 16:00:33 +05:30
Nirbheek Chauhan 69ca8f5b54 meson.py: Always resolve full path to meson.py
There is no reason to not always do this. Without this, we end up with
a relative path to meson.py in build.ninja files when meson.py is
launched using subprocess.Popen and friends from the meson source root.

This was causing the unittests to intermittently fail when regen was
getting invoked by the pic test. Funnily enough, this only happened when
run via ./run_tests.py because __file__ was 'run_unittests.py' in that
(as opposed to './run_unittests.py') case which made
os.path.dirname(__file__) be '', and the os.path.split test in meson.py
thought that meson.py was invoked via PATH.
2016-10-12 20:25:03 +05:30
Franz Zapata 4b5a0e5de7 Reintroduce Python Zipapp support
* Added `main` function as an entry point.
 * Created `__main__.py` to allow the creation of Zipapps without explicitly
   calling `meson:main`.
2016-10-10 23:41:40 +03:00
Emanuele Aina 6c50253645 Use argv[0] to internally relaunch meson.py
When installing Meson, distutils may choose to put shim scripts in the
`PATH` that only set up the egg requirements before launching the real
`meson.py` contained in the egg.

This means that `__file__` points to the real `meson.py` file, but
launching it directly is doomed to fail as it's missing the metadata
contained in the shim to set up the path egg, resulting in errors when
trying to import the `mesonbuild` module.

A similar issue affects Meson when installed as a zipapp, with the
current code going great lengths to figure out how to relaunch itself.

Using `argv[0]` avoids these issues as it gives us the way the current
executable has been launched, so we are pretty much guaranteed that
using it will create another instance of the same executable. We only
need to resolve relative paths as the current working directory may
get changed before re-launching the script, and using `realpath()` for
that saves us the trouble of manually resolving links and getting caught
in endless loops.

This also mean that `meson_script_file` no longer necessarily point to a
absolute file, so rename it to `_launcher` which hopefully would be less
prone to inducing false assumptions.
2016-10-08 15:41:31 +02:00
Jussi Pakkanen c69c15ee16 Revert #823, see also #830. 2016-10-02 09:35:02 -04:00
Jussi Pakkanen 08e43e8bfd Revert #830 because it broke the case when the main script is not in path. 2016-10-01 22:06:54 +03:00
Emanuele Aina 338dbc964c User argv[0] to internally relaunch meson.py
When installing Meson distutils may choose to put shim scripts in the
PATH that only set up the egg requirements before launching the real
`meson.py` contained in the egg.

This means that __file__ points to the real `meson.py` file, but
launching it directly is doomed to fail as it's missing the metadata
contained in the shim to set up the path egg, resulting in errors when
trying to import the `mesonbuild` module.

A similar issue affects Meson when installed as a zipapp, with the
current code going great lengths to figure out how to relaunch itself.

Using argv[0] avoids these issues as it gives us the way the current
executable has been launched, so we are pretty much guaranteed that
using it will create another instance of the same executable.
2016-09-30 15:30:27 -04:00
Franz Zapata ac41a45669 Support running Meson as a Python zip application 2016-09-28 12:40:54 -04:00
Jussi Pakkanen 455e55f8e5 Back to .py suffix in files. Closes #394. 2016-03-02 21:49:29 +02:00
Jussi Pakkanen 23b98cd6e6 Renamed meson package to mesonbuild so that we can have a script named meson in the same toplevel dir. 2016-01-16 17:35:29 +02:00
Jussi Pakkanen 66c01401de Moved scripts in the module and started work to run them via the main meson command. 2016-01-15 23:37:22 +02:00
Jussi Pakkanen 8b1039fa30 Organise files into a module structure. 2016-01-15 21:22:09 +02:00
Thibault Saunier 33b2a414e9 Make it working on python 3.3 2015-12-04 10:17:49 +01:00
Yoav Alon a4809cf632 Added support for extended command line to overcome OS command line length limitation 2015-11-28 21:26:56 +02:00
Jussi Pakkanen 1caf7e6f4a Yet another step in the neverending saga of -Wpedantic. 2015-11-23 00:57:01 +02:00
Wink Saville 60896c0f04 Add --version to command line arguments. 2015-11-17 09:13:52 -08:00
Jussi Pakkanen 63e803ae0f Made shared the default libtype as it is faster for daily development. 2015-11-04 00:36:07 +02:00
Jussi Pakkanen 8495075cee Turned builtin options into proper objects. 2015-11-03 03:31:56 +02:00
Jussi Pakkanen e2313b85d7 Refactored builtin options to a dictionary and created a new default library target type. 2015-11-03 03:03:54 +02:00
Jussi Pakkanen c0070aadae Now that projects can easily override defaults, return warning level to 2. 2015-10-26 20:18:05 +02:00
Jussi Pakkanen 572ce0f451 Added cpu family property to system information. 2015-10-18 01:08:04 +03:00
Thibault Saunier c24573483d Do not use intr before it exists 2015-09-19 16:24:33 +02:00
Jussi Pakkanen 5c5f8c7813 Merged trunk changes. 2015-09-17 20:07:40 +03:00
Jussi Pakkanen 067935ce76 Added conf option for build tree layout. 2015-09-17 19:21:26 +03:00
Jussi Pakkanen 384365c843 Added outdir() method to build targets so we can make output dirs togglable. 2015-09-17 18:48:26 +03:00
Jussi Pakkanen c7e367ac16 Can set default warning with an envvar. 2015-09-04 23:31:32 +03:00
Jussi Pakkanen 6cca79b052 Added multiple selectable warning levels. 2015-08-27 01:07:29 +03:00
Jussi Pakkanen 9d559b2b39 More robust windows detection and more logs. 2015-08-25 23:09:54 +03:00
Jussi Pakkanen bd5b4deeda Better sanity testing. 2015-08-25 01:19:58 +03:00
Jussi Pakkanen 30d0c2292f Support target-only cross compilation properly. 2015-07-27 00:55:28 +03:00
Jussi Pakkanen 37b2a195bd Get build machine's CPU info too. 2015-07-27 00:55:27 +03:00
Jussi Pakkanen 463d08d545 Now host_machine, build_machine and target_machine are properly separated and return correct values. 2015-07-27 00:55:27 +03:00
Igor Gnatenko 174e72413f style: fix indenting in meson.py
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2015-06-18 22:06:01 +03:00
Igor Gnatenko 79417eac80 meson: fix undefined-variable in backends chooser
E:146,57: Undefined variable 'options' (undefined-variable)

Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2015-06-18 19:25:29 +03:00
Igor Gnatenko 9616bed9fc introduce check python version in meson.py
To ensure that people will not confused that something won't work.

Related: https://github.com/miit-pm/RWD/pull/1#issuecomment-102607931
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2015-05-16 14:16:20 +03:00
Jussi Pakkanen b5cec55835 Moved functionality from __main__ to a function to make it callable. 2015-04-23 16:50:29 +03:00
Jussi Pakkanen ef180676c2 Add command line switch to print version number. 2015-03-13 22:42:47 +02:00
Jussi Pakkanen 3f46cd7fb3 Added gobject-introspection to gnome module. 2015-03-08 19:39:03 +02:00