aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mesonlib.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 /mesonbuild/mesonlib.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 'mesonbuild/mesonlib.py')
-rw-r--r--mesonbuild/mesonlib.py48
1 files changed, 1 insertions, 47 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index fe426c5..28ae7b5 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -38,58 +38,12 @@ except Exception:
from glob import glob
-def detect_meson_py_location():
- c = sys.argv[0]
- c_dir, c_fname = os.path.split(c)
-
- # get the absolute path to the <mesontool> folder
- m_dir = None
- if os.path.isabs(c):
- # $ /foo/<mesontool>.py <args>
- m_dir = c_dir
- elif c_dir == '':
- # $ <mesontool> <args> (gets run from /usr/bin/<mesontool>)
- in_path_exe = shutil.which(c_fname)
- if in_path_exe:
- if not os.path.isabs(in_path_exe):
- m_dir = os.getcwd()
- c_fname = in_path_exe
- else:
- m_dir, c_fname = os.path.split(in_path_exe)
- else:
- m_dir = os.path.abspath(c_dir)
-
- # find meson in m_dir
- if m_dir is not None:
- for fname in ['meson', 'meson.py']:
- m_path = os.path.join(m_dir, fname)
- if os.path.exists(m_path):
- return m_path
-
- # No meson found, which means that either:
- # a) meson is not installed
- # b) meson is installed to a non-standard location
- # c) the script that invoked mesonlib is not the one of meson tools (e.g. run_unittests.py)
- fname = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'meson.py'))
- if os.path.exists(fname):
- return fname
- # If meson is still not found, we might be imported by out-of-source tests
- # https://github.com/mesonbuild/meson/issues/3015
- exe = shutil.which('meson')
- if exe is None:
- exe = shutil.which('meson.py')
- if exe is not None:
- return exe
- # Give up.
- raise RuntimeError('Could not determine how to run Meson. Please file a bug with details.')
-
if os.path.basename(sys.executable) == 'meson.exe':
# In Windows and using the MSI installed executable.
- meson_command = [sys.executable]
python_command = [sys.executable, 'runpython']
else:
python_command = [sys.executable]
- meson_command = python_command + [detect_meson_py_location()]
+meson_command = python_command + ['-m', 'mesonbuild.mesonmain']
def is_ascii_string(astring):
try: