From 247d632f376fe209b336a5100a589c2599687b27 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Wed, 22 Nov 2017 20:35:43 +0200 Subject: [PATCH] Try harder to find meson.py. Closes #2672. --- mesonbuild/mesonlib.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index e9cf6cf96..56d347e3b 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 + if os.path.isabs(c): + return c + # $ meson (gets run from /usr/bin/meson) + in_path_exe = shutil.which(c_fname) + if in_path_exe: + return in_path_exe + # $ python3 ./meson.py + 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