backends: create ExecutableSerialisation in meson_exe if possible

If meson_exe is only being used to capture the output of the command,
we can skip going through a pickled ExecutableSerialization object.
This makes "ninja -v" output more useful.
pull/5644/head
Paolo Bonzini 5 years ago
parent 2912f44e9c
commit 8239d71025
  1. 16
      mesonbuild/backend/backends.py
  2. 33
      mesonbuild/scripts/meson_exe.py

@ -69,12 +69,12 @@ class TargetInstallData:
self.optional = optional self.optional = optional
class ExecutableSerialisation: class ExecutableSerialisation:
def __init__(self, name, fname, cmd_args, env, is_cross, exe_wrapper, def __init__(self, name, fname, cmd_args, env=None, is_cross=False, exe_wrapper=None,
workdir, extra_paths, capture, needs_exe_wrapper: bool): workdir=None, extra_paths=None, capture=None, needs_exe_wrapper: bool = False):
self.name = name self.name = name
self.fname = fname self.fname = fname
self.cmd_args = cmd_args self.cmd_args = cmd_args
self.env = env self.env = env or {}
self.is_cross = is_cross self.is_cross = is_cross
if exe_wrapper is not None: if exe_wrapper is not None:
assert(isinstance(exe_wrapper, dependencies.ExternalProgram)) assert(isinstance(exe_wrapper, dependencies.ExternalProgram))
@ -345,6 +345,7 @@ class Backend:
else: else:
exe_cmd = [exe] exe_cmd = [exe]
exe_for_machine = MachineChoice.BUILD exe_for_machine = MachineChoice.BUILD
is_cross_built = not self.environment.machines.matches_build_machine(exe_for_machine) is_cross_built = not self.environment.machines.matches_build_machine(exe_for_machine)
if is_cross_built and self.environment.need_exe_wrapper(): if is_cross_built and self.environment.need_exe_wrapper():
exe_wrapper = self.environment.get_exe_wrapper() exe_wrapper = self.environment.get_exe_wrapper()
@ -356,10 +357,13 @@ class Backend:
else: else:
exe_wrapper = None exe_wrapper = None
force_serialize = force_serialize or extra_paths or capture or workdir or \ force_serialize = force_serialize or extra_paths or workdir or \
exe_wrapper or any('\n' in c for c in cmd_args) exe_wrapper or any('\n' in c for c in cmd_args)
if not force_serialize: if not force_serialize:
return None if not capture:
return None
return (self.environment.get_build_command() +
['--internal', 'exe', '--capture', capture, '--'] + exe_cmd + cmd_args)
workdir = workdir or self.environment.get_build_dir() workdir = workdir or self.environment.get_build_dir()
env = {} env = {}
@ -384,7 +388,7 @@ class Backend:
extra_paths, capture, extra_paths, capture,
self.environment.need_exe_wrapper()) self.environment.need_exe_wrapper())
pickle.dump(es, f) pickle.dump(es, f)
return self.environment.get_build_command() + ['--internal', 'exe', exe_data] return self.environment.get_build_command() + ['--internal', 'exe', '--unpickle', exe_data]
def serialize_tests(self): def serialize_tests(self):
test_data = os.path.join(self.environment.get_scratch_dir(), 'meson_test_setup.dat') test_data = os.path.join(self.environment.get_scratch_dir(), 'meson_test_setup.dat')

@ -20,12 +20,14 @@ import platform
import subprocess import subprocess
from .. import mesonlib from .. import mesonlib
from ..backend.backends import ExecutableSerialisation
options = None options = None
def buildparser(): def buildparser():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser(description='Custom executable wrapper for Meson. Do not run on your own, mmm\'kay?')
parser.add_argument('args', nargs='+') parser.add_argument('--unpickle')
parser.add_argument('--capture')
return parser return parser
def is_windows(): def is_windows():
@ -101,13 +103,26 @@ def run_exe(exe):
def run(args): def run(args):
global options global options
options = buildparser().parse_args(args) parser = buildparser()
if len(options.args) != 1: options, cmd_args = parser.parse_known_args(args)
print('Test runner for Meson. Do not run on your own, mmm\'kay?') # argparse supports double dash to separate options and positional arguments,
print(sys.argv[0] + ' [data file]') # but the user has to remove it manually.
exe_data_file = options.args[0] if cmd_args and cmd_args[0] == '--':
with open(exe_data_file, 'rb') as f: cmd_args = cmd_args[1:]
exe = pickle.load(f) if not options.unpickle and not cmd_args:
parser.error('either --unpickle or executable and arguments are required')
if options.unpickle:
if cmd_args or options.capture:
parser.error('no other arguments can be used with --unpickle')
with open(options.unpickle, 'rb') as f:
exe = pickle.load(f)
else:
exe_cmd = cmd_args[0]
cmd_args = cmd_args[1:]
basename = os.path.basename(exe_cmd)
exe = ExecutableSerialisation(basename, [exe_cmd], cmd_args,
capture=options.capture)
return run_exe(exe) return run_exe(exe)
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save