aboutsummaryrefslogtreecommitdiff
path: root/run_tests.py
diff options
context:
space:
mode:
authorMartin Kelly <mkelly@xevo.com>2018-04-24 16:57:18 -0700
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-05-30 18:29:16 +0000
commit0627e9d616dc311b7c9b0ef17301f680ac9e78a7 (patch)
treed58d446c9fa19d5ad4be7dc8b7fbdbed105a076d /run_tests.py
parentab599b5733539130db5c4d17c664744f4d5aacaf (diff)
downloadmeson-0627e9d616dc311b7c9b0ef17301f680ac9e78a7.zip
meson-0627e9d616dc311b7c9b0ef17301f680ac9e78a7.tar.gz
meson-0627e9d616dc311b7c9b0ef17301f680ac9e78a7.tar.bz2
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.
Diffstat (limited to 'run_tests.py')
-rwxr-xr-xrun_tests.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/run_tests.py b/run_tests.py
index 648e6ce..731d864 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -42,6 +42,28 @@ if mesonlib.is_windows() or mesonlib.is_cygwin():
else:
exe_suffix = ''
+def setup_pythonpath():
+ # Make sure python can import mesonbuild, even if we change directories as
+ # some tests do. Since sys.path is the final product of fairly complex code
+ # in site.py, it's hard to tell where each entry came from just by looking
+ # at sys.path, so we don't know if a given entry was set from a relative or
+ # absolute path. If an entry was set from a relative path, it won't
+ # continue to work if we change directories. Instead of trying to guess
+ # where a given entry came from, just add the known-good mesonbuild to
+ # PYTHONPATH so that it will continue to be importable from other
+ # directories.
+ import mesonbuild
+ meson_dir = os.path.dirname(os.path.abspath(mesonbuild.__file__))
+ meson_root = os.path.realpath(os.path.join(meson_dir, os.pardir))
+ try:
+ python_path = os.environ['PYTHONPATH']
+ except KeyError:
+ python_path = meson_root
+ else:
+ paths = python_path.split(os.pathsep) + [meson_root]
+ python_path = os.pathsep.join(paths)
+ os.environ['PYTHONPATH'] = python_path
+
def get_backend_args_for_dir(backend, builddir):
'''
Visual Studio backend needs to be given the solution to build