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

* aosp/upstream:
  Support the implicit "-a" in find

Test: OUT_DIR=out DIST_DIR=dist prebuilts/build-tools/build-prebuilts.sh
Change-Id: Ia1bf168a3ee4c7c01d66a810cacf648ab42e6edd
diff --git a/find.cc b/find.cc
index 1b9e23f..1bf0b9e 100644
--- a/find.cc
+++ b/find.cc
@@ -526,12 +526,16 @@
     while (true) {
       if (!GetNextToken(&tok))
         return NULL;
-      if (tok != "-and" && tok != "-a") {
-        UngetToken(tok);
-        return c.release();
+      if (tok == "-and" || tok == "-a") {
+        if (!GetNextToken(&tok) || tok.empty())
+          return NULL;
+      } else {
+        if (tok != "-not" && tok != "\\!" && tok != "\\(" && tok != "-name" &&
+            tok != "-type") {
+          UngetToken(tok);
+          return c.release();
+        }
       }
-      if (!GetNextToken(&tok) || tok.empty())
-        return NULL;
       unique_ptr<FindCond> r(ParseFact(tok));
       if (!r.get()) {
         return NULL;
@@ -562,7 +566,7 @@
   }
 
   // <expr> ::= <term> {<or> <term>}
-  // <term> ::= <fact> {<and> <fact>}
+  // <term> ::= <fact> {[<and>] <fact>}
   // <fact> ::= <not> <fact> | '\(' <expr> '\)' | <pred>
   // <not> ::= '-not' | '\!'
   // <and> ::= '-and' | '-a'
diff --git a/testcase/find_command.mk b/testcase/find_command.mk
index c3e8a07..b714879 100644
--- a/testcase/find_command.mk
+++ b/testcase/find_command.mk
@@ -67,6 +67,7 @@
 	$(call run_find, find testdir -name "file1")
 	$(call run_find, find testdir -name "file1")
 	$(call run_find, find testdir -name "*1")
+	$(call run_find, find testdir -name "*1" -name "file*")
 	$(call run_find, find testdir -name "*1" -and -name "file*")
 	$(call run_find, find testdir -name "*1" -or -name "file*")
 	$(call run_find, find testdir -name "*1" -or -type f)