Merge remote-tracking branch 'aosp/upstream'

* aosp/upstream:
  Don't emit pool for phony ninja rules
  Add test for auto-detected goma pools

Bug: 143938974
Test: m checkbuild
Change-Id: I2d3dd80c231b060919d0f33da7d5d8a304c68706
diff --git a/ninja.cc b/ninja.cc
index 53810f0..c11bc56 100644
--- a/ninja.cc
+++ b/ninja.cc
@@ -580,7 +580,7 @@
       if (pool != "none") {
         *o << " pool = " << pool << "\n";
       }
-    } else if (g_flags.default_pool) {
+    } else if (g_flags.default_pool && rule_name != "phony") {
       *o << " pool = " << g_flags.default_pool << "\n";
     } else if (use_local_pool) {
       *o << " pool = local_pool\n";
diff --git a/testcase/ninja_pool.sh b/testcase/ninja_pool.sh
index 4d3d15c..2ae3240 100644
--- a/testcase/ninja_pool.sh
+++ b/testcase/ninja_pool.sh
@@ -21,7 +21,7 @@
 
 cat <<EOF > Makefile
 
-test: test_pool test_none test_default test_blank
+test: test_pool test_none test_default test_blank test_gomacc
 
 test_pool: .KATI_NINJA_POOL := test_pool
 test_pool:
@@ -38,8 +38,13 @@
 test_blank:
 	echo "PASS"
 
+test_gomacc:
+	echo ~/goma/gomacc > /dev/null
+	echo "PASS"
 EOF
 
+
+# Test with no arguments
 ${mk} 2>${log}
 if [ -e ninja.sh ]; then
   mv build.ninja kati.ninja
@@ -65,8 +70,12 @@
   if grep -A1 "build test_blank:" kati.ninja | grep -q "pool ="; then
     echo "unexpected pool present for test_blank rule in build.ninja"
   fi
+  if grep -A1 "build test_blank:" kati.ninja | grep -q "pool ="; then
+    echo "unexpected pool present for test_gomacc rule in build.ninja"
+  fi
 fi
 
+# Test with --default_pool set
 args=
 if ! echo "${mk}" | grep -qv "kati"; then
   args=--default_pool=default_pool
@@ -97,4 +106,38 @@
   if ! grep -A1 "build test_blank:" kati.ninja | grep -q "pool = default_pool"; then
     echo "default_pool not present for test_blank rule in build.ninja"
   fi
+  if ! grep -A1 "build test_gomacc:" kati.ninja | grep -q "pool = default_pool"; then
+    echo "default_pool not present for test_gomacc rule in build.ninja"
+  fi
+fi
+
+# Test with USE_GOMA=true set
+${mk} USE_GOMA=true 2>${log}
+if [ -e ninja.sh ]; then
+  mv build.ninja kati.ninja
+  cat <<EOF > build.ninja
+pool test_pool
+  depth = 1
+pool default_pool
+  depth = 1
+include kati.ninja
+EOF
+  ./ninja.sh
+fi
+if [ -e ninja.sh ]; then
+  if ! grep -A1 "build test_pool:" kati.ninja | grep -q "pool = test_pool"; then
+    echo "test_pool not present for test_pool rule in build.ninja"
+  fi
+  if grep -A1 "build test_none:" kati.ninja | grep -q "pool = "; then
+    echo "unexpected pool present for test_none rule in build.ninja"
+  fi
+  if ! grep -A1 "build test_default:" kati.ninja | grep -q "pool = local_pool"; then
+    echo "local_pool not present for test_default rule in build.ninja"
+  fi
+  if ! grep -A1 "build test_blank:" kati.ninja | grep -q "pool = local_pool"; then
+    echo "local_pool not present for test_blank rule in build.ninja"
+  fi
+  if grep -A1 "build test_gomacc:" kati.ninja | grep -q "pool = "; then
+    echo "unexpected pool present for test_gomacc rule in build.ninja"
+  fi
 fi