From 43a35d299bbc044957eea5f82eae5a2f189a2b3c Mon Sep 17 00:00:00 2001 From: Yoshisato Yanagisawa Date: Thu, 15 Nov 2018 03:00:51 +0000 Subject: [PATCH] autoninja: quote the arguments when needed. On Windows, without quote, whole return value would be treated as a command, and the execution would fail. On Linux and Mac, without quote, if depot_tools is settled under directories with ' ', command execution would fail because paths are separated in a wrong way. To make such a return value work on Linux and Mac, the shell script started to use eval. Bug: 902930 Change-Id: I9bb74585294af565988c0b844b6b113a5c685530 Reviewed-on: https://chromium-review.googlesource.com/c/1325249 Reviewed-by: Dirk Pranke Commit-Queue: Yoshisato Yanagisawa --- autoninja | 2 +- autoninja.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/autoninja b/autoninja index 408f49547..b7b6d5987 100755 --- a/autoninja +++ b/autoninja @@ -11,7 +11,7 @@ export AUTONINJA_BUILD_ID="$(python -c "import uuid; print uuid.uuid4()")" # Also print it to reassure that the right settings are being used. command=$(python $(dirname -- "$0")/autoninja.py "$@") echo $command -$command +eval $command if [ $? -eq 0 ]; then if [ "$NINJA_SUMMARIZE_BUILD" == "1" ]; then python $(dirname -- "$0")/post_build_ninja_summary.py $@ diff --git a/autoninja.py b/autoninja.py index 1706c1caa..96439f806 100755 --- a/autoninja.py +++ b/autoninja.py @@ -69,14 +69,8 @@ except IOError: # Specify ninja.exe on Windows so that ninja.bat can call autoninja and not # be called back. ninja_exe = 'ninja.exe' if sys.platform.startswith('win') else 'ninja' - ninja_exe_path = os.path.join(SCRIPT_DIR, ninja_exe) -# On Windows, fully quote the path so that the command processor doesn't think -# the whole output is the command. -if sys.platform.startswith('win'): - ninja_exe_path = '"' + ninja_exe_path + '"' - # Use absolute path for ninja path, # or fail to execute ninja if depot_tools is not in PATH. args = [ninja_exe_path] + input_args[1:] @@ -94,4 +88,14 @@ if not j_specified and not t_specified: args.append('-j') args.append('%d' % (num_cores + core_addition)) +# On Windows, fully quote the path so that the command processor doesn't think +# the whole output is the command. +# On Linux and Mac, if people put depot_tools in directories with ' ', +# shell would misunderstand ' ' as a path separation. +# TODO(yyanagisawa): provide proper quating for Windows. +# see https://cs.chromium.org/chromium/src/tools/mb/mb.py +for i in range(len(args)): + if (i == 0 and sys.platform.startswith('win')) or ' ' in args[i]: + args[i] = '"%s"' % args[i].replace('"', '\\"') + print ' '.join(args)