Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / tools / gn / ninja_target_writer.cc
index a5a6e67..ade81a0 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "base/file_util.h"
 #include "tools/gn/err.h"
-#include "tools/gn/file_template.h"
 #include "tools/gn/ninja_action_target_writer.h"
 #include "tools/gn/ninja_binary_target_writer.h"
 #include "tools/gn/ninja_copy_target_writer.h"
@@ -26,9 +25,7 @@ NinjaTargetWriter::NinjaTargetWriter(const Target* target,
       target_(target),
       toolchain_(toolchain),
       out_(out),
-      path_output_(settings_->build_settings()->build_dir(),
-                   ESCAPE_NINJA,
-                   false),
+      path_output_(settings_->build_settings()->build_dir(), ESCAPE_NINJA),
       helper_(settings_->build_settings()) {
 }
 
@@ -88,12 +85,19 @@ std::string NinjaTargetWriter::WriteInputDepsStampAndGetDep(
     const std::vector<const Target*>& extra_hard_deps) const {
   // For an action (where we run a script only once) the sources are the same
   // as the source prereqs.
-  bool list_sources_as_input_deps = target_->output_type() == Target::ACTION;
+  bool list_sources_as_input_deps = (target_->output_type() == Target::ACTION);
 
-  if (extra_hard_deps.empty() &&
-      target_->source_prereqs().empty() &&
+  // Actions get implicit dependencies on the script itself.
+  bool add_script_source_as_dep =
+      (target_->output_type() == Target::ACTION) ||
+      (target_->output_type() == Target::ACTION_FOREACH);
+
+  if (!add_script_source_as_dep &&
+      extra_hard_deps.empty() &&
+      target_->inputs().empty() &&
       target_->recursive_hard_deps().empty() &&
-      (!list_sources_as_input_deps || target_->sources().empty()))
+      (!list_sources_as_input_deps || target_->sources().empty()) &&
+      toolchain_->deps().empty())
     return std::string();  // No input/hard deps.
 
   // One potential optimization is if there are few input dependencies (or
@@ -111,10 +115,17 @@ std::string NinjaTargetWriter::WriteInputDepsStampAndGetDep(
   path_output_.WriteFile(stamp_file_stream, input_stamp_file);
   std::string stamp_file_string = stamp_file_stream.str();
 
-  out_ << "build " << stamp_file_string << ": stamp";
+  out_ << "build " << stamp_file_string << ": " +
+      helper_.GetRulePrefix(settings_) + "stamp";
+
+  // Script file (if applicable).
+  if (add_script_source_as_dep) {
+    out_ << " ";
+    path_output_.WriteFile(out_, target_->action_values().script());
+  }
 
   // Input files are order-only deps.
-  const Target::FileList& prereqs = target_->source_prereqs();
+  const Target::FileList& prereqs = target_->inputs();
   for (size_t i = 0; i < prereqs.size(); i++) {
     out_ << " ";
     path_output_.WriteFile(out_, prereqs[i]);
@@ -135,6 +146,17 @@ std::string NinjaTargetWriter::WriteInputDepsStampAndGetDep(
     path_output_.WriteFile(out_, helper_.GetTargetOutputFile(*i));
   }
 
+  // Toolchain dependencies. These must be resolved before doing anything.
+  // This just writs all toolchain deps for simplicity. If we find that
+  // toolchains often have more than one dependency, we could consider writing
+  // a toolchain-specific stamp file and only include the stamp here.
+  const LabelTargetVector& toolchain_deps = toolchain_->deps();
+  for (size_t i = 0; i < toolchain_deps.size(); i++) {
+    out_ << " ";
+    path_output_.WriteFile(out_,
+                           helper_.GetTargetOutputFile(toolchain_deps[i].ptr));
+  }
+
   // Extra hard deps passed in.
   for (size_t i = 0; i < extra_hard_deps.size(); i++) {
     out_ << " ";
@@ -145,15 +167,3 @@ std::string NinjaTargetWriter::WriteInputDepsStampAndGetDep(
   out_ << "\n";
   return " | " + stamp_file_string;
 }
-
-FileTemplate NinjaTargetWriter::GetOutputTemplate() const {
-  const Target::FileList& outputs = target_->action_values().outputs();
-  std::vector<std::string> output_template_args;
-  for (size_t i = 0; i < outputs.size(); i++) {
-    // All outputs should be in the output dir.
-    output_template_args.push_back(
-        RemovePrefix(outputs[i].value(),
-                     settings_->build_settings()->build_dir().value()));
-  }
-  return FileTemplate(output_template_args);
-}