Move runtime_deps file for phony targets to /obj

For targets that use phony aliases, we generate a dependency_output in
the PHONY BuildDir. Since this doesn't actually create any files, the
"phony" directory is never actually generated. However, when the caller
requests runtime_deps files to be written, the phony target path was
being used to generate the runtime_deps file name. This resulted in
out/phony/foo/bar.runtime_deps being generated.

This CL fixes the runtime_deps file path for phony targets to be in the
OBJ BuildDir.

Change-Id: I3ac9fcc2597241b1bb4ce85cf8c57ad2a1b1e24c
Commit-Queue: Petr Hosek <>
Reviewed-by: Brett Wilson <>
diff --git a/docs/ b/docs/
index 7438d9c..93cba60 100644
--- a/docs/
+++ b/docs/
@@ -2658,7 +2658,7 @@
   source sets and groups: this will return a list containing the path of the
-  "stamp" file that Ninja will produce once all outputs are generated. This
+  phony target that Ninja completes once all outputs are generated. This
   probably isn't very useful.
diff --git a/src/gn/ b/src/gn/
index d002458..1213c35 100644
--- a/src/gn/
+++ b/src/gn/
@@ -185,9 +185,15 @@
       output_file =
           OutputFile(target->computed_outputs()[0].value() + extension);
-    } else if (target->dependency_output_file_or_phony()) {
-      output_file = OutputFile(
-          target->dependency_output_file_or_phony()->value() + extension);
+    } else if (target->dependency_output_file()) {
+      output_file =
+          OutputFile(target->dependency_output_file()->value() + extension);
+    } else if (target->dependency_output_phony()) {
+      // If the dependency is a phony target, there is no file to add an additional
+      // extension to, so we should compute our own name in the OBJ BuildDir.
+      output_file = GetBuildDirForTargetAsOutputFile(target, BuildDirType::OBJ);
+      output_file->value().append(target->GetComputedOutputName());
+      output_file->value().append(extension);
     if (output_file)
       files_to_write->push_back(std::make_pair(*output_file, target));
diff --git a/src/gn/ b/src/gn/
index abbc0e4..2b42e13 100644
--- a/src/gn/
+++ b/src/gn/
@@ -198,10 +198,12 @@
   an output file "", GN will create a file "" in the
   build directory.
-  If a source set, action, copy, or group is listed, the runtime deps file will
-  correspond to the phony alias rule corresponding to that target. This is
-  probably not useful; the use-case for this feature is generally executable
-  targets.
+  For targets that don't generate an output file (such as source set, action,
+  copy or group), the runtime deps file will be in the output directory where an
+  output file would have been located. For example, the source_set target
+  "//foo:bar" would result in a runtime dependency file being written to
+  "<output_dir>/obj/foo/bar.runtime_deps". This is probably not useful; the
+  use-case for this feature is generally executable targets.
   The runtime dependency file will list one file per line, with no escaping.
   The files will be relative to the root_build_dir. The first line of the file