commandrunner: make run handle python options
Currently, commandrunner breaks when we give options to python because
it assumes python commands are in the form "python script.py", rather
than "python -u script.py" or "python -u -m module script.py". Extend it
to be more resilient and correctly parse python options.
@@ -59,9 +59,27 @@ def run(args):
subdir = args[2]
meson_command = args[3]
if 'python' in meson_command: # Hack.
- meson_command = [meson_command, args[4]]
- command = args[5]
- arguments = args[6:]
+ # Handle any of these:
+ # python meson.py ...
+ # python -m mesonbuild.mesonmain ...
+ # python ARGS -m mesonbuild.mesonmain ...
+ # python -m mesonbuild.mesonmain ARGS ...
+ i = 4
+ while i < len(args):
+ arg = args[i]
+ # Skip past optional arguments.
+ if arg[0] == '-':
+ if arg == '-m':
+ # Skip past -m PYTHONFILE.
+ i += 2
+ else:
+ i += 1
+ else:
+ break
+ end = i
+ meson_command = args[3:end]
+ command = args[end]
+ arguments = args[end + 1:]
else:
meson_command = [meson_command]
command = args[4]
