aboutsummaryrefslogtreecommitdiff
path: root/run_tests.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2018-06-01 13:00:17 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-06-01 19:20:04 +0000
commit0a035dea6d0b1416fc76e323bbd7b0ab5a60a4af (patch)
tree0399ae08fe7cd92d23563db29a401f5454b68693 /run_tests.py
parent14750b50ea9c9f53237bed59a79365e1ebbdacda (diff)
downloadmeson-0a035dea6d0b1416fc76e323bbd7b0ab5a60a4af.zip
meson-0a035dea6d0b1416fc76e323bbd7b0ab5a60a4af.tar.gz
meson-0a035dea6d0b1416fc76e323bbd7b0ab5a60a4af.tar.bz2
Set the meson command to use when we know what it is
Instead of using fragile guessing to figure out how to invoke meson, set the value when meson is run. Also rework how we pass of meson_script_launcher to regenchecker.py -- it wasn't even being used With this change, we only need to guess the meson path when running the tests, and in that case: 1. If MESON_EXE is set in the env, we know how to run meson for project tests. 2. MESON_EXE is not set, which means we run the configure in-process for project tests and need to guess what meson to run, so either - meson.py is found next to run_tests.py, or - meson, meson.py, or meson.exe is in PATH Otherwise, you can invoke meson in the following ways: 1. meson is installed, and mesonbuild is available in PYTHONPATH: - meson, meson.py, meson.exe from PATH - python3 -m mesonbuild.mesonmain - python3 /path/to/meson.py - meson is a shell wrapper to meson.real 2. meson is not installed, and is run from git: - Absolute path to meson.py - Relative path to meson.py - Symlink to meson.py All these are tested in test_meson_commands.py, except meson.exe since that involves building the meson msi and installing it.
Diffstat (limited to 'run_tests.py')
-rwxr-xr-xrun_tests.py43
1 files changed, 36 insertions, 7 deletions
diff --git a/run_tests.py b/run_tests.py
index 648e6ce..736cdc0 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -21,13 +21,16 @@ import shutil
import subprocess
import tempfile
import platform
+from io import StringIO
+from enum import Enum
+from glob import glob
+from pathlib import Path
+
+import mesonbuild
from mesonbuild import mesonlib
from mesonbuild import mesonmain
from mesonbuild import mlog
from mesonbuild.environment import detect_ninja
-from io import StringIO
-from enum import Enum
-from glob import glob
Backend = Enum('Backend', 'ninja vs xcode')
@@ -42,6 +45,28 @@ if mesonlib.is_windows() or mesonlib.is_cygwin():
else:
exe_suffix = ''
+def get_meson_script():
+ '''
+ Guess the meson that corresponds to the `mesonbuild` that has been imported
+ so we can run configure and other commands in-process, since mesonmain.run
+ needs to know the meson_command to use.
+
+ Also used by run_unittests.py to determine what meson to run when not
+ running in-process (which is the default).
+ '''
+ # Is there a meson.py next to the mesonbuild currently in use?
+ mesonbuild_dir = Path(mesonbuild.__file__).resolve().parent.parent
+ meson_script = mesonbuild_dir / 'meson.py'
+ if meson_script.is_file():
+ return str(meson_script)
+ # Then if mesonbuild is in PYTHONPATH, meson must be in PATH
+ mlog.warning('Could not find meson.py next to the mesonbuild module. '
+ 'Trying system meson...')
+ meson_cmd = shutil.which('meson')
+ if meson_cmd:
+ return meson_cmd
+ raise RuntimeError('Could not find {!r} or a meson in PATH'.format(meson_script))
+
def get_backend_args_for_dir(backend, builddir):
'''
Visual Studio backend needs to be given the solution to build
@@ -133,13 +158,13 @@ def get_fake_options(prefix):
def should_run_linux_cross_tests():
return shutil.which('arm-linux-gnueabihf-gcc') and not platform.machine().lower().startswith('arm')
-def run_configure_inprocess(meson_command, commandlist):
+def run_configure_inprocess(commandlist):
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
old_stderr = sys.stderr
sys.stderr = mystderr = StringIO()
try:
- returncode = mesonmain.run(commandlist, meson_command)
+ returncode = mesonmain.run(commandlist, get_meson_script())
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
@@ -149,11 +174,11 @@ def run_configure_external(full_command):
pc, o, e = mesonlib.Popen_safe(full_command)
return pc.returncode, o, e
-def run_configure(meson_command, commandlist):
+def run_configure(commandlist):
global meson_exe
if meson_exe:
return run_configure_external(meson_exe + commandlist)
- return run_configure_inprocess(meson_command, commandlist)
+ return run_configure_inprocess(commandlist)
def print_system_info():
print(mlog.bold('System information.').get_text(mlog.colorize_console))
@@ -214,6 +239,9 @@ if __name__ == '__main__':
'coverage.process_startup()\n')
env['COVERAGE_PROCESS_START'] = '.coveragerc'
env['PYTHONPATH'] = os.pathsep.join([td] + env.get('PYTHONPATH', []))
+ # Meson command tests
+ returncode += subprocess.call(mesonlib.python_command + ['run_meson_command_tests.py', '-v'], env=env)
+ # Unit tests
returncode += subprocess.call(mesonlib.python_command + ['run_unittests.py', '-v'], env=env)
# Ubuntu packages do not have a binary without -6 suffix.
if should_run_linux_cross_tests():
@@ -221,5 +249,6 @@ if __name__ == '__main__':
print()
returncode += subprocess.call(mesonlib.python_command + ['run_cross_test.py', 'cross/ubuntu-armhf.txt'],
env=env)
+ # Project tests
returncode += subprocess.call(mesonlib.python_command + ['run_project_tests.py'] + sys.argv[1:], env=env)
sys.exit(returncode)