From 657d9f2b29334556366eb3c0801612e9e7385f57 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 19 Feb 2018 17:43:50 +0530 Subject: Support running out-of-tree tests against a meson in PATH Closes https://github.com/mesonbuild/meson/issues/3015 --- mesonbuild/mesonlib.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 65b689f..695c4a9 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -56,12 +56,18 @@ def detect_meson_py_location(): # 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) - # The only thing remaining is to try to find the bundled executable and - # pray distro packagers have not moved it. fname = os.path.normpath(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.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. -- cgit v1.1