Allow WriteCompilerBuildLine to take multiple source files

Some compilers (notably swiftc) need to be passed the full
list of source files in a single invocation, thus needs to
be passed a list of files.

Since the generated ninja output is similar in both case,
change WriteCompilerBuildLine to take a std::vector<> of
SourceFile instead of a single instance.

Bug: 121
Change-Id: I4df2976aa82b57ba5a23ad05be52bce1321100ce
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/9460
Commit-Queue: Brett Wilson <brettw@chromium.org>
Reviewed-by: Brett Wilson <brettw@chromium.org>
diff --git a/src/gn/ninja_binary_target_writer.cc b/src/gn/ninja_binary_target_writer.cc
index 4379ca0..da7733b 100644
--- a/src/gn/ninja_binary_target_writer.cc
+++ b/src/gn/ninja_binary_target_writer.cc
@@ -255,7 +255,7 @@
 }
 
 void NinjaBinaryTargetWriter::WriteCompilerBuildLine(
-    const SourceFile& source,
+    const std::vector<SourceFile>& sources,
     const std::vector<OutputFile>& extra_deps,
     const std::vector<OutputFile>& order_only_deps,
     const char* tool_name,
@@ -264,8 +264,7 @@
   path_output_.WriteFiles(out_, outputs);
 
   out_ << ": " << rule_prefix_ << tool_name;
-  out_ << " ";
-  path_output_.WriteFile(out_, source);
+  path_output_.WriteFiles(out_, sources);
 
   if (!extra_deps.empty()) {
     out_ << " |";
diff --git a/src/gn/ninja_binary_target_writer.h b/src/gn/ninja_binary_target_writer.h
index 50d1151..a9d10d5 100644
--- a/src/gn/ninja_binary_target_writer.h
+++ b/src/gn/ninja_binary_target_writer.h
@@ -57,7 +57,7 @@
   OutputFile WriteStampAndGetDep(const UniqueVector<const SourceFile*>& files,
                                  const std::string& stamp_ext) const;
 
-  void WriteCompilerBuildLine(const SourceFile& source,
+  void WriteCompilerBuildLine(const std::vector<SourceFile>& sources,
                               const std::vector<OutputFile>& extra_deps,
                               const std::vector<OutputFile>& order_only_deps,
                               const char* tool_name,
diff --git a/src/gn/ninja_c_binary_target_writer.cc b/src/gn/ninja_c_binary_target_writer.cc
index 2773577..721b67c 100644
--- a/src/gn/ninja_c_binary_target_writer.cc
+++ b/src/gn/ninja_c_binary_target_writer.cc
@@ -312,7 +312,7 @@
             std::back_inserter(extra_deps));
 
   // Build line to compile the file.
-  WriteCompilerBuildLine(target_->config_values().precompiled_source(),
+  WriteCompilerBuildLine({target_->config_values().precompiled_source()},
                          extra_deps, order_only_deps, tool_name, outputs);
 
   // This build line needs a custom language-specific flags value. Rule-specific
@@ -364,7 +364,7 @@
             std::back_inserter(extra_deps));
 
   // Build line to compile the file.
-  WriteCompilerBuildLine(target_->config_values().precompiled_source(),
+  WriteCompilerBuildLine({target_->config_values().precompiled_source()},
                          extra_deps, order_only_deps, tool_name, outputs);
 
   // This build line needs a custom language-specific flags value. Rule-specific
@@ -433,7 +433,7 @@
           }
         }
       }
-      WriteCompilerBuildLine(source, deps, order_only_deps, tool_name,
+      WriteCompilerBuildLine({source}, deps, order_only_deps, tool_name,
                              tool_outputs);
     }
 
diff --git a/src/gn/ninja_rust_binary_target_writer.cc b/src/gn/ninja_rust_binary_target_writer.cc
index 74371e0..70b0f1d 100644
--- a/src/gn/ninja_rust_binary_target_writer.cc
+++ b/src/gn/ninja_rust_binary_target_writer.cc
@@ -188,7 +188,7 @@
   std::vector<OutputFile> tool_outputs;
   SubstitutionWriter::ApplyListToLinkerAsOutputFile(
       target_, tool_, tool_->outputs(), &tool_outputs);
-  WriteCompilerBuildLine(target_->rust_values().crate_root(),
+  WriteCompilerBuildLine({target_->rust_values().crate_root()},
                          implicit_deps.vector(), order_only_deps, tool_->name(),
                          tool_outputs);
 
diff --git a/src/gn/path_output.cc b/src/gn/path_output.cc
index ff9a5bc..c89e061 100644
--- a/src/gn/path_output.cc
+++ b/src/gn/path_output.cc
@@ -75,6 +75,14 @@
 }
 
 void PathOutput::WriteFiles(std::ostream& out,
+                            const std::vector<SourceFile>& files) const {
+  for (const auto& file : files) {
+    out << " ";
+    WriteFile(out, file);
+  }
+}
+
+void PathOutput::WriteFiles(std::ostream& out,
                             const std::vector<OutputFile>& files) const {
   for (const auto& file : files) {
     out << " ";
diff --git a/src/gn/path_output.h b/src/gn/path_output.h
index a815308..729ba98 100644
--- a/src/gn/path_output.h
+++ b/src/gn/path_output.h
@@ -53,8 +53,9 @@
   void WriteFile(std::ostream& out, const OutputFile& file) const;
   void WriteFile(std::ostream& out, const base::FilePath& file) const;
 
-  // Writes the given OutputFiles with spaces separating them. This will also
-  // write an initial space before the first item.
+  // Writes the given SourceFiles/OutputFiles with spaces separating them. This
+  // will also write an initial space before the first item.
+  void WriteFiles(std::ostream& out, const std::vector<SourceFile>& file) const;
   void WriteFiles(std::ostream& out,
                   const std::vector<OutputFile>& files) const;
   void WriteFiles(std::ostream& out,