From 246d5d86f5b6fe8c3680ab2fc1c52d6c55cffa0c Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Tue, 18 Sep 2018 11:57:15 -0400 Subject: [PATCH] Move set_meson_command() to mesonlib --- mesonbuild/mesonlib.py | 17 +++++++++++++++++ mesonbuild/mesonmain.py | 17 +---------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 8648a0dcf..33900b63f 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -48,6 +48,23 @@ else: python_command = [sys.executable] meson_command = None +def set_meson_command(mainfile): + global python_command + global meson_command + # On UNIX-like systems `meson` is a Python script + # On Windows `meson` and `meson.exe` are wrapper exes + if not mainfile.endswith('.py'): + meson_command = [mainfile] + elif os.path.isabs(mainfile) and mainfile.endswith('mesonmain.py'): + # Can't actually run meson with an absolute path to mesonmain.py, it must be run as -m mesonbuild.mesonmain + meson_command = python_command + ['-m', 'mesonbuild.mesonmain'] + else: + # Either run uninstalled, or full path to meson-script.py + meson_command = python_command + [mainfile] + # We print this value for unit tests. + if 'MESON_COMMAND_TESTS' in os.environ: + mlog.log('meson_command is {!r}'.format(meson_command)) + def is_ascii_string(astring): try: if isinstance(astring, str): diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index dfad2e784..9f85cde10 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -253,21 +253,6 @@ def run_script_command(args): raise MesonException('Unknown internal command {}.'.format(cmdname)) return cmdfunc(cmdargs) -def set_meson_command(mainfile): - # On UNIX-like systems `meson` is a Python script - # On Windows `meson` and `meson.exe` are wrapper exes - if not mainfile.endswith('.py'): - mesonlib.meson_command = [mainfile] - elif os.path.isabs(mainfile) and mainfile.endswith('mesonmain.py'): - # Can't actually run meson with an absolute path to mesonmain.py, it must be run as -m mesonbuild.mesonmain - mesonlib.meson_command = mesonlib.python_command + ['-m', 'mesonbuild.mesonmain'] - else: - # Either run uninstalled, or full path to meson-script.py - mesonlib.meson_command = mesonlib.python_command + [mainfile] - # We print this value for unit tests. - if 'MESON_COMMAND_TESTS' in os.environ: - mlog.log('meson_command is {!r}'.format(mesonlib.meson_command)) - def run(original_args, mainfile): if sys.version_info < (3, 5): print('Meson works correctly only with python 3.5+.') @@ -284,7 +269,7 @@ def run(original_args, mainfile): mlog.error('Please download and use Python as detailed at: https://mesonbuild.com/Getting-meson.html') return 2 # Set the meson command that will be used to run scripts and so on - set_meson_command(mainfile) + mesonlib.set_meson_command(mainfile) args = original_args[:] if len(args) > 0: # First check if we want to run a subcommand.