Use ResolvedTargetData::GetTargetDeps() in Ninja target writers.

Use the new NinjaTargetWriter::resolved() method to parse
target dependencies. This is the first CL in a series that
will move computations from Target to ResolvedTargetData and
modify the Ninja writers to use instances of the latter.

Bug: 331
Change-Id: I053f7f62f3525f58d94ffbfd1c170d429327ccd7
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/15322
Reviewed-by: Takuto Ikuta <tikuta@google.com>
Commit-Queue: David Turner <digit@google.com>
diff --git a/src/gn/ninja_action_target_writer.cc b/src/gn/ninja_action_target_writer.cc
index f4f0867..644b845 100644
--- a/src/gn/ninja_action_target_writer.cc
+++ b/src/gn/ninja_action_target_writer.cc
@@ -36,11 +36,13 @@
   // serialize these.
   std::vector<const Target*> additional_hard_deps;
   std::vector<OutputFile> data_outs;
-  for (const auto& pair : target_->GetDeps(Target::DEPS_LINKED)) {
-    if (pair.ptr->IsDataOnly()) {
-      data_outs.push_back(pair.ptr->dependency_output_file());
+  const auto& target_deps = resolved().GetTargetDeps(target_);
+
+  for (const Target* dep : target_deps.linked_deps()) {
+    if (dep->IsDataOnly()) {
+      data_outs.push_back(dep->dependency_output_file());
     } else {
-      additional_hard_deps.push_back(pair.ptr);
+      additional_hard_deps.push_back(dep);
     }
   }
 
@@ -97,8 +99,8 @@
   // done before we run the action.
   // TODO(thakis): If the action has just a single output, make things depend
   // on that output directly without writing a stamp file.
-  for (const auto& dep : target_->data_deps())
-    data_outs.push_back(dep.ptr->dependency_output_file());
+  for (const Target* data_dep : target_deps.data_deps())
+    data_outs.push_back(data_dep->dependency_output_file());
   WriteStampForTarget(output_files, data_outs);
 }
 
diff --git a/src/gn/ninja_binary_target_writer.cc b/src/gn/ninja_binary_target_writer.cc
index e14954d..b9ecc21 100644
--- a/src/gn/ninja_binary_target_writer.cc
+++ b/src/gn/ninja_binary_target_writer.cc
@@ -129,9 +129,11 @@
 NinjaBinaryTargetWriter::GetClassifiedDeps() const {
   ClassifiedDeps classified_deps;
 
+  const auto& target_deps = resolved().GetTargetDeps(target_);
+
   // Normal public/private deps.
-  for (const auto& pair : target_->GetDeps(Target::DEPS_LINKED)) {
-    ClassifyDependency(pair.ptr, &classified_deps);
+  for (const Target* dep : target_deps.linked_deps()) {
+    ClassifyDependency(dep, &classified_deps);
   }
 
   // Inherited libraries.
@@ -140,8 +142,8 @@
   }
 
   // Data deps.
-  for (const auto& data_dep_pair : target_->data_deps())
-    classified_deps.non_linkable_deps.push_back(data_dep_pair.ptr);
+  for (const Target* data_dep : target_deps.data_deps())
+    classified_deps.non_linkable_deps.push_back(data_dep);
 
   return classified_deps;
 }
diff --git a/src/gn/ninja_bundle_data_target_writer.cc b/src/gn/ninja_bundle_data_target_writer.cc
index 0e3bcb0..da3bb4e 100644
--- a/src/gn/ninja_bundle_data_target_writer.cc
+++ b/src/gn/ninja_bundle_data_target_writer.cc
@@ -26,8 +26,8 @@
   output_files.insert(output_files.end(), input_deps.begin(), input_deps.end());
 
   std::vector<OutputFile> order_only_deps;
-  for (const auto& pair : target_->data_deps())
-    order_only_deps.push_back(pair.ptr->dependency_output_file());
+  for (const Target* data_dep : resolved().GetDataDeps(target_))
+    order_only_deps.push_back(data_dep->dependency_output_file());
 
   WriteStampForTarget(output_files, order_only_deps);
 }
diff --git a/src/gn/ninja_c_binary_target_writer.cc b/src/gn/ninja_c_binary_target_writer.cc
index 1ef0475..c0f73b8 100644
--- a/src/gn/ninja_c_binary_target_writer.cc
+++ b/src/gn/ninja_c_binary_target_writer.cc
@@ -83,7 +83,9 @@
   return nullptr;
 }
 
-std::vector<ModuleDep> GetModuleDepsInformation(const Target* target) {
+std::vector<ModuleDep> GetModuleDepsInformation(
+    const Target* target,
+    const ResolvedTargetData& resolved) {
   std::vector<ModuleDep> ret;
 
   auto add = [&ret](const Target* t, bool is_self) {
@@ -107,10 +109,10 @@
     add(target, true);
   }
 
-  for (const auto& pair: target->GetDeps(Target::DEPS_LINKED)) {
+  for (const Target* dep : resolved.GetLinkedDeps(target)) {
     // Having a .modulemap source means that the dependency is modularized.
-    if (pair.ptr->source_types_used().Get(SourceFile::SOURCE_MODULEMAP)) {
-      add(pair.ptr, false);
+    if (dep->source_types_used().Get(SourceFile::SOURCE_MODULEMAP)) {
+      add(dep, false);
     }
   }
 
@@ -127,7 +129,8 @@
 NinjaCBinaryTargetWriter::~NinjaCBinaryTargetWriter() = default;
 
 void NinjaCBinaryTargetWriter::Run() {
-  std::vector<ModuleDep> module_dep_info = GetModuleDepsInformation(target_);
+  std::vector<ModuleDep> module_dep_info =
+      GetModuleDepsInformation(target_, resolved());
 
   WriteCompilerVars(module_dep_info);
 
diff --git a/src/gn/ninja_copy_target_writer.cc b/src/gn/ninja_copy_target_writer.cc
index 9299223..8a95cea 100644
--- a/src/gn/ninja_copy_target_writer.cc
+++ b/src/gn/ninja_copy_target_writer.cc
@@ -74,8 +74,8 @@
       std::vector<const Target*>(), num_stamp_uses);
 
   std::vector<OutputFile> data_outs;
-  for (const auto& dep : target_->data_deps())
-    data_outs.push_back(dep.ptr->dependency_output_file());
+  for (const Target* data_dep : resolved().GetDataDeps(target_))
+    data_outs.push_back(data_dep->dependency_output_file());
 
   // Note that we don't write implicit deps for copy steps. "copy" only
   // depends on the output files themselves, rather than having includes
diff --git a/src/gn/ninja_create_bundle_target_writer.cc b/src/gn/ninja_create_bundle_target_writer.cc
index d05f5f0..23936ab 100644
--- a/src/gn/ninja_create_bundle_target_writer.cc
+++ b/src/gn/ninja_create_bundle_target_writer.cc
@@ -89,8 +89,8 @@
   WriteCompileAssetsCatalogStep(order_only_deps, &output_files);
   WriteCodeSigningStep(code_signing_rule_name, order_only_deps, &output_files);
 
-  for (const auto& pair : target_->data_deps())
-    order_only_deps.push_back(pair.ptr->dependency_output_file());
+  for (const Target* data_dep : resolved().GetDataDeps(target_))
+    order_only_deps.push_back(data_dep->dependency_output_file());
   WriteStampForTarget(output_files, order_only_deps);
 
   // Write a phony target for the outer bundle directory. This allows other
diff --git a/src/gn/ninja_generated_file_target_writer.cc b/src/gn/ninja_generated_file_target_writer.cc
index 3e07090..1abdc05 100644
--- a/src/gn/ninja_generated_file_target_writer.cc
+++ b/src/gn/ninja_generated_file_target_writer.cc
@@ -31,17 +31,17 @@
   // done at gen time, and so ninja doesn't need to know about it.
   std::vector<OutputFile> output_files;
   std::vector<OutputFile> data_output_files;
-  for (const auto& pair : target_->GetDeps(Target::DEPS_LINKED)) {
-    if (pair.ptr->IsDataOnly()) {
-      data_output_files.push_back(pair.ptr->dependency_output_file());
+  const auto& target_deps = resolved().GetTargetDeps(target_);
+  for (const Target* dep : target_deps.linked_deps()) {
+    if (dep->IsDataOnly()) {
+      data_output_files.push_back(dep->dependency_output_file());
     } else {
-      output_files.push_back(pair.ptr->dependency_output_file());
+      output_files.push_back(dep->dependency_output_file());
     }
   }
 
-  const LabelTargetVector& data_deps = target_->data_deps();
-  for (const auto& pair : data_deps)
-    data_output_files.push_back(pair.ptr->dependency_output_file());
+  for (const Target* data_dep : target_deps.data_deps())
+    data_output_files.push_back(data_dep->dependency_output_file());
 
   WriteStampForTarget(output_files, data_output_files);
 }
diff --git a/src/gn/ninja_group_target_writer.cc b/src/gn/ninja_group_target_writer.cc
index beeb54a..58d6ce7 100644
--- a/src/gn/ninja_group_target_writer.cc
+++ b/src/gn/ninja_group_target_writer.cc
@@ -21,17 +21,18 @@
   // the deps and data_deps in the group.
   std::vector<OutputFile> output_files;
   std::vector<OutputFile> data_output_files;
-  for (const auto& pair : target_->GetDeps(Target::DEPS_LINKED)) {
-    if (pair.ptr->IsDataOnly()) {
-      data_output_files.push_back(pair.ptr->dependency_output_file());
+  const auto& target_deps = resolved().GetTargetDeps(target_);
+
+  for (const Target* dep : target_deps.linked_deps()) {
+    if (dep->IsDataOnly()) {
+      data_output_files.push_back(dep->dependency_output_file());
     } else {
-      output_files.push_back(pair.ptr->dependency_output_file());
+      output_files.push_back(dep->dependency_output_file());
     }
   }
 
-  const LabelTargetVector& data_deps = target_->data_deps();
-  for (const auto& pair : data_deps)
-    data_output_files.push_back(pair.ptr->dependency_output_file());
+  for (const Target* data_dep : target_deps.data_deps())
+    data_output_files.push_back(data_dep->dependency_output_file());
 
   WriteStampForTarget(output_files, data_output_files);
 }