aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Stukalov <astukalov@gmail.com>2017-12-28 13:51:09 +0100
committerNirbheek Chauhan <nirbheek@centricular.com>2018-02-19 01:32:16 +0530
commit9cb86eae12cf6babdcb6c49a9fed3f9dc2d76972 (patch)
tree9b284ba2d42fb2486903a587e24b899258d7ffe4
parent398adbdb0d1434211e2eba03ebc07ea29e6cbee4 (diff)
downloadmeson-9cb86eae12cf6babdcb6c49a9fed3f9dc2d76972.zip
meson-9cb86eae12cf6babdcb6c49a9fed3f9dc2d76972.tar.gz
meson-9cb86eae12cf6babdcb6c49a9fed3f9dc2d76972.tar.bz2
fix meson location detection if run by wraptool
teach detect_meson_py_location() that meson.py is not the only one meson executable (there's wraptool + legacy scripts) that could be installed to the PATH folder fixes #2810
-rw-r--r--mesonbuild/mesonlib.py39
1 files changed, 23 insertions, 16 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index ee47c5a..53576bc 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -24,25 +24,32 @@ from glob import glob
def detect_meson_py_location():
c = sys.argv[0]
- c_fname = os.path.split(c)[1]
- if c_fname == 'meson' or c_fname == 'meson.py':
- # $ /foo/meson.py <args>
- if os.path.isabs(c):
- return c
- # $ meson <args> (gets run from /usr/bin/meson)
+ 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:
- # Special case: when run like "./meson.py <opts>" and user has
- # period in PATH, we need to expand it out, because, for example,
+ m_dir, c_fname = os.path.split(in_path_exe)
+ # Special case: when run like "./meson.py <opts>",
+ # we need to expand it out, because, for example,
# "ninja test" will be run from a different directory.
- if '.' in os.environ['PATH'].split(':'):
- p, f = os.path.split(in_path_exe)
- if p == '' or p == '.':
- return os.path.join(os.getcwd(), f)
- return in_path_exe
- # $ python3 ./meson.py <args>
- if os.path.exists(c):
- return os.path.join(os.getcwd(), c)
+ if m_dir == '.':
+ m_dir = os.getcwd()
+ 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
# The only thing remaining is to try to find the bundled executable and
# pray distro packagers have not moved it.