From 7eee6cca715c4b79304436df23ba33d87b6121bc Mon Sep 17 00:00:00 2001 From: Tony Allevato Date: Wed, 22 Apr 2020 12:47:57 -0700 Subject: [PATCH] Rewrite the `swiftc` params file if an argument contains a space. Bazel does not quote arguments when it writes a multiline params file, but LLVM's command line parser does not distinguish between newlines and other kinds of whitespace, and we don't want to use the shell-quoted params file format from Bazel because it would be more difficult for us to parse. This change ensures that if a line in the incoming params file contains a space, it causes a rewrite which triggers the defensive "quote everything" logic. RELNOTES: None. PiperOrigin-RevId: 307876851 --- tools/worker/swift_runner.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/worker/swift_runner.cc b/tools/worker/swift_runner.cc index cd6279913..eca0f2993 100644 --- a/tools/worker/swift_runner.cc +++ b/tools/worker/swift_runner.cc @@ -203,7 +203,11 @@ bool SwiftRunner::ProcessArgument( // Apply any other text substitutions needed in the argument (i.e., for // Apple toolchains). auto new_arg = arg; - changed = MakeSubstitutions(&new_arg, bazel_placeholder_substitutions_); + // Bazel doesn't quote arguments in multi-line params files, so we need to + // ensure that our defensive quoting kicks in if an argument contains a + // space, even if no other changes would have been made. + changed = MakeSubstitutions(&new_arg, bazel_placeholder_substitutions_) || + new_arg.find_first_of(' ') != std::string::npos; consumer(new_arg); }