diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2019-07-12 17:33:50 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2019-07-19 00:17:29 +0200 |
commit | 8239d71025ad59e44e7ac7b43849554990efe9f9 (patch) | |
tree | c8f9be13f1a6d1f739c1f831d0459baecb88d933 /mesonbuild/scripts | |
parent | 2912f44e9c21aa7578bdceb0d78ba53a555c6397 (diff) | |
download | meson-8239d71025ad59e44e7ac7b43849554990efe9f9.zip meson-8239d71025ad59e44e7ac7b43849554990efe9f9.tar.gz meson-8239d71025ad59e44e7ac7b43849554990efe9f9.tar.bz2 |
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.
Diffstat (limited to 'mesonbuild/scripts')
-rw-r--r-- | mesonbuild/scripts/meson_exe.py | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/mesonbuild/scripts/meson_exe.py b/mesonbuild/scripts/meson_exe.py index c1d0d64..e5bc9dc 100644 --- a/mesonbuild/scripts/meson_exe.py +++ b/mesonbuild/scripts/meson_exe.py @@ -20,12 +20,14 @@ import platform import subprocess from .. import mesonlib +from ..backend.backends import ExecutableSerialisation options = None def buildparser(): - parser = argparse.ArgumentParser() - parser.add_argument('args', nargs='+') + parser = argparse.ArgumentParser(description='Custom executable wrapper for Meson. Do not run on your own, mmm\'kay?') + parser.add_argument('--unpickle') + parser.add_argument('--capture') return parser def is_windows(): @@ -101,13 +103,26 @@ def run_exe(exe): def run(args): global options - options = buildparser().parse_args(args) - if len(options.args) != 1: - print('Test runner for Meson. Do not run on your own, mmm\'kay?') - print(sys.argv[0] + ' [data file]') - exe_data_file = options.args[0] - with open(exe_data_file, 'rb') as f: - exe = pickle.load(f) + parser = buildparser() + options, cmd_args = parser.parse_known_args(args) + # argparse supports double dash to separate options and positional arguments, + # but the user has to remove it manually. + if cmd_args and cmd_args[0] == '--': + cmd_args = cmd_args[1:] + 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) if __name__ == '__main__': |