diff options
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 4 | ||||
-rw-r--r-- | mesonbuild/backend/vs2010backend.py | 11 | ||||
-rw-r--r-- | mesonbuild/backend/xcodebackend.py | 2 | ||||
-rw-r--r-- | mesonbuild/dependencies/base.py | 2 | ||||
-rw-r--r-- | mesonbuild/environment.py | 12 | ||||
-rw-r--r-- | mesonbuild/mesonlib.py | 9 | ||||
-rw-r--r-- | mesonbuild/mesonmain.py | 94 | ||||
-rw-r--r-- | mesonbuild/modules/python3.py | 2 | ||||
-rw-r--r-- | mesonbuild/scripts/regen_checker.py | 15 |
9 files changed, 81 insertions, 70 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index c633daf..cea1b08 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2524,7 +2524,7 @@ rule FORTRAN_DEP_HACK gcno_elem = NinjaBuildElement(self.all_outputs, 'meson-clean-gcno', 'CUSTOM_COMMAND', 'PHONY') script_root = self.environment.get_script_dir() clean_script = os.path.join(script_root, 'delwithsuffix.py') - gcno_elem.add_item('COMMAND', [sys.executable, clean_script, '.', 'gcno']) + gcno_elem.add_item('COMMAND', mesonlib.python_command + [clean_script, '.', 'gcno']) gcno_elem.add_item('description', 'Deleting gcno files.') gcno_elem.write(outfile) # Alias that runs the target defined above @@ -2533,7 +2533,7 @@ rule FORTRAN_DEP_HACK gcda_elem = NinjaBuildElement(self.all_outputs, 'meson-clean-gcda', 'CUSTOM_COMMAND', 'PHONY') script_root = self.environment.get_script_dir() clean_script = os.path.join(script_root, 'delwithsuffix.py') - gcda_elem.add_item('COMMAND', [sys.executable, clean_script, '.', 'gcda']) + gcda_elem.add_item('COMMAND', mesonlib.python_command + [clean_script, '.', 'gcda']) gcda_elem.add_item('description', 'Deleting gcda files.') gcda_elem.write(outfile) # Alias that runs the target defined above diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index e4e9696..69ee3e5 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -23,7 +23,7 @@ from .. import dependencies from .. import mlog from .. import compilers from ..compilers import CompilerArgs -from ..mesonlib import MesonException, File +from ..mesonlib import MesonException, File, python_command from ..environment import Environment def autodetect_vs_version(build): @@ -396,10 +396,11 @@ class Vs2010Backend(backends.Backend): action = ET.SubElement(root, 'ItemDefinitionGroup') customstep = ET.SubElement(action, 'PostBuildEvent') cmd_raw = [target.command] + target.args - cmd = [sys.executable, os.path.join(self.environment.get_script_dir(), 'commandrunner.py'), - self.environment.get_build_dir(), - self.environment.get_source_dir(), - self.get_target_dir(target)] + self.environment.get_build_command() + cmd = python_command + \ + [os.path.join(self.environment.get_script_dir(), 'commandrunner.py'), + self.environment.get_build_dir(), + self.environment.get_source_dir(), + self.get_target_dir(target)] + self.environment.get_build_command() for i in cmd_raw: if isinstance(i, build.BuildTarget): cmd.append(os.path.join(self.environment.get_build_dir(), self.get_target_filename(i))) diff --git a/mesonbuild/backend/xcodebackend.py b/mesonbuild/backend/xcodebackend.py index 199d7df..aca3aea 100644 --- a/mesonbuild/backend/xcodebackend.py +++ b/mesonbuild/backend/xcodebackend.py @@ -567,7 +567,7 @@ class XCodeBackend(backends.Backend): self.write_line('shellPath = /bin/sh;') script_root = self.environment.get_script_dir() test_script = os.path.join(script_root, 'meson_test.py') - cmd = [sys.executable, test_script, test_data, '--wd', self.environment.get_build_dir()] + cmd = mesonlib.python_command + [test_script, test_data, '--wd', self.environment.get_build_dir()] cmdstr = ' '.join(["'%s'" % i for i in cmd]) self.write_line('shellScript = "%s";' % cmdstr) self.write_line('showEnvVarsInLog = 0;') diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index fcc74b5..15b47bc 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -434,7 +434,7 @@ class ExternalProgram: commands = commands[1:] # Windows does not ship python3.exe, but we know the path to it if len(commands) > 0 and commands[0] == 'python3': - commands[0] = sys.executable + commands = mesonlib.python_command + commands[1:] return commands + [script] except Exception: pass diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index d9146eb..58cc9b9 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -325,14 +325,10 @@ class Environment: return self.coredata def get_build_command(self, unbuffered=False): - # If running an executable created with cx_freeze, - # Python might not be installed so don't prefix - # the command with it. - if sys.executable.endswith('meson.exe'): - return [sys.executable] - if unbuffered: - [sys.executable, '-u', self.meson_script_launcher] - return [sys.executable, self.meson_script_launcher] + cmd = mesonlib.meson_command[:] + if unbuffered and 'python' in cmd[0]: + cmd.insert(1, '-u') + return cmd def is_header(self, fname): return is_header(fname) diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index c8eea4d..e9cf6cf 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -22,6 +22,15 @@ import collections from glob import glob +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] + + # Put this in objects that should not get dumped to pickle files # by accident. import threading diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 8d5fb85..fa8c9e3 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -23,12 +23,9 @@ from . import mlog, coredata from .mesonlib import MesonException from .wrap import WrapMode, wraptool - -parser = argparse.ArgumentParser(prog='meson') - default_warning = '1' -def add_builtin_argument(name, **kwargs): +def add_builtin_argument(p, name, **kwargs): k = kwargs.get('dest', name.replace('-', '_')) c = coredata.get_builtin_option_choices(k) b = True if kwargs.get('action', None) in ['store_true', 'store_false'] else False @@ -42,31 +39,45 @@ def add_builtin_argument(name, **kwargs): kwargs['default'] = default else: kwargs['default'] = argparse.SUPPRESS - parser.add_argument('--' + name, help=h, **kwargs) + p.add_argument('--' + name, help=h, **kwargs) -add_builtin_argument('prefix') -add_builtin_argument('libdir') -add_builtin_argument('libexecdir') -add_builtin_argument('bindir') -add_builtin_argument('sbindir') -add_builtin_argument('includedir') -add_builtin_argument('datadir') -add_builtin_argument('mandir') -add_builtin_argument('infodir') -add_builtin_argument('localedir') -add_builtin_argument('sysconfdir') -add_builtin_argument('localstatedir') -add_builtin_argument('sharedstatedir') -add_builtin_argument('backend') -add_builtin_argument('buildtype') -add_builtin_argument('strip', action='store_true') -add_builtin_argument('unity') -add_builtin_argument('werror', action='store_true') -add_builtin_argument('layout') -add_builtin_argument('default-library') -add_builtin_argument('warnlevel', dest='warning_level') -add_builtin_argument('stdsplit', action='store_false') -add_builtin_argument('errorlogs', action='store_false') +def create_parser(): + p = argparse.ArgumentParser(prog='meson') + add_builtin_argument(p, 'prefix') + add_builtin_argument(p, 'libdir') + add_builtin_argument(p, 'libexecdir') + add_builtin_argument(p, 'bindir') + add_builtin_argument(p, 'sbindir') + add_builtin_argument(p, 'includedir') + add_builtin_argument(p, 'datadir') + add_builtin_argument(p, 'mandir') + add_builtin_argument(p, 'infodir') + add_builtin_argument(p, 'localedir') + add_builtin_argument(p, 'sysconfdir') + add_builtin_argument(p, 'localstatedir') + add_builtin_argument(p, 'sharedstatedir') + add_builtin_argument(p, 'backend') + add_builtin_argument(p, 'buildtype') + add_builtin_argument(p, 'strip', action='store_true') + add_builtin_argument(p, 'unity') + add_builtin_argument(p, 'werror', action='store_true') + add_builtin_argument(p, 'layout') + add_builtin_argument(p, 'default-library') + add_builtin_argument(p, 'warnlevel', dest='warning_level') + add_builtin_argument(p, 'stdsplit', action='store_false') + add_builtin_argument(p, 'errorlogs', action='store_false') + p.add_argument('--cross-file', default=None, + help='File describing cross compilation environment.') + p.add_argument('-D', action='append', dest='projectoptions', default=[], metavar="option", + help='Set the value of an option, can be used several times to set multiple options.') + p.add_argument('-v', '--version', action='version', + version=coredata.version) + # See the mesonlib.WrapMode enum for documentation + p.add_argument('--wrap-mode', default=WrapMode.default, + type=wrapmodetype, choices=WrapMode, + help='Special wrap mode to use') + p.add_argument('directories', nargs='*') + return p def wrapmodetype(string): try: @@ -76,18 +87,6 @@ def wrapmodetype(string): msg = 'invalid argument {!r}, use one of {}'.format(string, msg) raise argparse.ArgumentTypeError(msg) -parser.add_argument('--cross-file', default=None, - help='File describing cross compilation environment.') -parser.add_argument('-D', action='append', dest='projectoptions', default=[], metavar="option", - help='Set the value of an option, can be used several times to set multiple options.') -parser.add_argument('-v', '--version', action='version', - version=coredata.version) -# See the mesonlib.WrapMode enum for documentation -parser.add_argument('--wrap-mode', default=WrapMode.default, - type=wrapmodetype, choices=WrapMode, - help='Special wrap mode to use') -parser.add_argument('directories', nargs='*') - class MesonApp: def __init__(self, dir1, dir2, script_launcher, handshake, options, original_cmd_line_args): @@ -155,7 +154,7 @@ class MesonApp: def _generate(self, env): mlog.debug('Build started at', datetime.datetime.now().isoformat()) - mlog.debug('Python binary:', sys.executable) + mlog.debug('Main binary:', sys.executable) mlog.debug('Python system:', platform.system()) mlog.log(mlog.bold('The Meson build system')) self.check_pkgconfig_envvar(env) @@ -278,12 +277,13 @@ def run_script_command(args): raise MesonException('Unknown internal command {}.'.format(cmdname)) return cmdfunc(cmdargs) -def run(args, mainfile=None): +def run(original_args, mainfile=None): if sys.version_info < (3, 4): print('Meson works correctly only with python 3.4+.') print('You have python %s.' % sys.version) print('Please update your environment') return 1 + args = original_args[:] if len(args) > 0: # First check if we want to run a subcommand. cmd_name = args[0] @@ -303,6 +303,12 @@ def run(args, mainfile=None): return mconf.run(remaining_args) elif cmd_name == 'wrap': return wraptool.run(remaining_args) + elif cmd_name == 'runpython': + import runpy + script_file = remaining_args[0] + sys.argv[1:] = remaining_args[1:] + runpy.run_path(script_file, run_name='__main__') + sys.exit(0) # No special command? Do the basic setup/reconf. if len(args) >= 2 and args[0] == '--internal': @@ -319,6 +325,8 @@ def run(args, mainfile=None): else: handshake = False + parser = create_parser() + args = mesonlib.expand_arguments(args) options = parser.parse_args(args) args = options.directories @@ -342,7 +350,7 @@ def run(args, mainfile=None): try: if mainfile is None: raise AssertionError('I iz broken. Sorry.') - app = MesonApp(dir1, dir2, mainfile, handshake, options, sys.argv) + app = MesonApp(dir1, dir2, mainfile, handshake, options, original_args) except Exception as e: # Log directory does not exist, so just print # to stdout. diff --git a/mesonbuild/modules/python3.py b/mesonbuild/modules/python3.py index 4fae88b..989e839 100644 --- a/mesonbuild/modules/python3.py +++ b/mesonbuild/modules/python3.py @@ -52,7 +52,7 @@ class Python3Module(ExtensionModule): @noKwargs def find_python(self, state, args, kwargs): - py3 = dependencies.ExternalProgram('python3', sys.executable, silent=True) + py3 = dependencies.ExternalProgram('python3', mesonlib.python_command, silent=True) return ModuleReturnValue(py3, [py3]) @noKwargs diff --git a/mesonbuild/scripts/regen_checker.py b/mesonbuild/scripts/regen_checker.py index 53c5428..a9b00c7 100644 --- a/mesonbuild/scripts/regen_checker.py +++ b/mesonbuild/scripts/regen_checker.py @@ -14,6 +14,7 @@ import sys, os import pickle, subprocess +from mesonbuild.mesonlib import meson_command # This could also be used for XCode. @@ -32,15 +33,11 @@ def need_regen(regeninfo, regen_timestamp): return False def regen(regeninfo, mesonscript, backend): - if sys.executable.lower().endswith('meson.exe'): - cmd_exe = [sys.executable] - else: - cmd_exe = [sys.executable, mesonscript] - cmd = cmd_exe + ['--internal', - 'regenerate', - regeninfo.build_dir, - regeninfo.source_dir, - '--backend=' + backend] + cmd = meson_command + ['--internal', + 'regenerate', + regeninfo.build_dir, + regeninfo.source_dir, + '--backend=' + backend] subprocess.check_call(cmd) def run(args): |