diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2017-11-22 20:35:43 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2017-11-23 20:48:44 +0200 |
commit | 247d632f376fe209b336a5100a589c2599687b27 (patch) | |
tree | cf952b411bef84237c3c3dcf3dd71e451d6eb98e | |
parent | d882b6fbd466940d452cfaa890bd9270e10a93b4 (diff) | |
download | meson-247d632f376fe209b336a5100a589c2599687b27.zip meson-247d632f376fe209b336a5100a589c2599687b27.tar.gz meson-247d632f376fe209b336a5100a589c2599687b27.tar.bz2 |
Try harder to find meson.py. Closes #2672.
-rw-r--r-- | mesonbuild/mesonlib.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index e9cf6cf..56d347e 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -22,13 +22,35 @@ import collections 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) + in_path_exe = shutil.which(c_fname) + if in_path_exe: + return in_path_exe + # $ python3 ./meson.py <args> + if os.path.exists(c): + return os.path.join(os.getcwd(), c) + + # The only thing remaining is to try to find the bundled executable and + # pray distro packagers have not moved it. + fname = os.path.join(os.path.dirname(__file__), '..', 'meson.py') + if not os.path.exists(fname): + raise RuntimeError('Could not determine how to run Meson. Please file a bug with details.') + return fname + 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: - meson_command = [sys.executable, os.path.join(os.path.dirname(__file__), '..', 'meson.py')] python_command = [sys.executable] + meson_command = python_command + [detect_meson_py_location()] # Put this in objects that should not get dumped to pickle files |