Merge remote-tracking branch 'aosp/upstream' into master

* aosp/upstream:
  Implement "phony_output" feature in ninja

Test: treehugger
Change-Id: Ia22358ec998b1ab2a808038dafb9827d5dd09d2d
diff --git a/flags.cc b/flags.cc
index ab84269..148d59a 100644
--- a/flags.cc
+++ b/flags.cc
@@ -106,6 +106,8 @@
       no_builtin_rules = true;
     } else if (!strcmp(arg, "--no_ninja_prelude")) {
       no_ninja_prelude = true;
+    } else if (!strcmp(arg, "--use_ninja_phony_output")) {
+      use_ninja_phony_output = true;
     } else if (!strcmp(arg, "--werror_find_emulator")) {
       werror_find_emulator = true;
     } else if (!strcmp(arg, "--werror_overriding_commands")) {
diff --git a/flags.h b/flags.h
index 1791a55..ee16c4f 100644
--- a/flags.h
+++ b/flags.h
@@ -43,6 +43,7 @@
   bool color_warnings;
   bool no_builtin_rules;
   bool no_ninja_prelude;
+  bool use_ninja_phony_output;
   bool werror_find_emulator;
   bool werror_overriding_commands;
   bool warn_implicit_rules;
diff --git a/ninja.cc b/ninja.cc
index c11bc56..1a8332e 100644
--- a/ninja.cc
+++ b/ninja.cc
@@ -557,7 +557,7 @@
     }
     *o << ": " << rule_name;
     vector<Symbol> order_onlys;
-    if (node->is_phony) {
+    if (node->is_phony && !g_flags.use_ninja_phony_output) {
       *o << " _kati_always_build_";
     }
     for (auto const& d : node->deps) {
@@ -585,6 +585,9 @@
     } else if (use_local_pool) {
       *o << " pool = local_pool\n";
     }
+    if (node->is_phony && g_flags.use_ninja_phony_output) {
+      *o << " phony_output = true\n";
+    }
     if (node->is_default_target) {
       unique_lock<mutex> lock(mu_);
       default_target_ = node;
@@ -618,7 +621,9 @@
       fprintf(fp_, "pool local_pool\n");
       fprintf(fp_, " depth = %d\n\n", g_flags.num_jobs);
 
-      fprintf(fp_, "build _kati_always_build_: phony\n\n");
+      if (!g_flags.use_ninja_phony_output) {
+        fprintf(fp_, "build _kati_always_build_: phony\n\n");
+      }
     }
 
     unique_ptr<ThreadPool> tp(NewThreadPool(g_flags.num_jobs));