Fix autoninja to allow compiling one source file

This is the second attempt at fixing autoninja to allow passing '^^' to
it to specify that ninja should build the outputs of the specified file
instead of building that file itself. The problem is that '^' is a
special character and when extra layers of indirection are added the
number of '^' characters needed grows exponentially in some poorly
understood way. The first fix attempt just quoted the arguments that
autoninja.bat passed to autoninja.py, but that meant they came in as
one argument. This fix expands on that by modifying autoninja.py to
understand how to deal with the monolithic argument. With this change
this once again works:

    autoninja -C out\debug_component ..\..\base\win\enum_variant.cc^^

It can be convenient to have a ninja.bat file which starts goma and lets
users keep typing the same build commands. However even with this fix
the previously recommended ninja.bat file must be invoked with four
'^' characters. If that is too much then the new recommended ninja.bat
is to copy autoninja.bat and modify as needed, perhaps like this:

    @echo off
    call python c:\goma\goma-win64\goma_ctl.py ensure_start >nul
    FOR /f "usebackq tokens=*" %%a in (`python c:\src\depot_tools\autoninja.py "%*"`) do echo %%a & %%a

BUG: 758725
Change-Id: Ieee9cf343ee5f22e9988a1969cb7a7a90687666b
Reviewed-on: https://chromium-review.googlesource.com/656478
Reviewed-by: Sébastien Marchand <sebmarchand@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
changes/78/656478/2
Bruce Dawson 8 years ago committed by Commit Bot
parent 0a1f3f6ab3
commit f3b4f060e2

@ -5,5 +5,5 @@
REM Execute whatever is printed by autoninja.py.
REM Also print it to reassure that the right settings are being used.
FOR /f "usebackq tokens=*" %%a in (`python %~dp0autoninja.py %*`) do echo %%a & %%a
FOR /f "usebackq tokens=*" %%a in (`python %~dp0autoninja.py "%*"`) do echo %%a & %%a

@ -19,14 +19,25 @@ import sys
t_specified = False
j_specified = False
output_dir = '.'
for index, arg in enumerate(sys.argv[1:]):
input_args = sys.argv
# On Windows the autoninja.bat script passes along the arguments enclosed in
# double quotes. This prevents multiple levels of parsing of the special '^'
# characters needed when compiling a single file but means that this script gets
# called with a single argument containing all of the actual arguments,
# separated by spaces. When this case is detected we need to do argument
# splitting ourselves. This means that arguments containing actual spaces are
# not supported by autoninja, but that is not a real limitation.
if (sys.platform.startswith('win') and len(sys.argv) == 2 and
input_args[1].count(' ') > 0):
input_args = sys.argv[:1] + sys.argv[1].split()
for index, arg in enumerate(input_args[1:]):
if arg == '-j':
j_specified = True
if arg == '-t':
t_specified = True
if arg == '-C':
# + 1 to get the next argument and +1 because we trimmed off sys.argv[0]
output_dir = sys.argv[index + 2]
# + 1 to get the next argument and +1 because we trimmed off input_args[0]
output_dir = input_args[index + 2]
use_goma = False
try:
@ -42,9 +53,9 @@ except IOError:
if sys.platform.startswith('win'):
# Specify ninja.exe on Windows so that ninja.bat can call autoninja and not
# be called back.
args = ['ninja.exe'] + sys.argv[1:]
args = ['ninja.exe'] + input_args[1:]
else:
args = ['ninja'] + sys.argv[1:]
args = ['ninja'] + input_args[1:]
num_cores = multiprocessing.cpu_count()
if not j_specified and not t_specified:

Loading…
Cancel
Save