Have `make` report a failing gtest run as a top-level target.

Before, if an individual gtest such (as
`test-art-host-gtest-output_stream_test64`) was invoked as
`make`'s top-level target and failing, `make` would not
report it as such through its exit status (it would be 0
whatever the result). However, when run as part of a
compound test target (such as
`test-art-host-gtest-output_stream_test` or
`test-art-host-gtest`), `make` would actually report this
test's (and maybe others') failure with a non-zero exit
status. This CL forces `make` to report a non-zero exit
status in the former case without breaking the latter one.

Test: Amend a gtest such as compiler/linker/output_stream_test.cc
    to make it artificially fail, and run it with:
      make test-art-host-gtest-output_stream_test
      make test-art-host-gtest-output_stream_test64
Bug: 31755702

Change-Id: Icbb6fef592f14d73808576e7fcb0e9d7079ec9a2
diff --git a/build/Android.common_test.mk b/build/Android.common_test.mk
index d2e3371..291db8b 100644
--- a/build/Android.common_test.mk
+++ b/build/Android.common_test.mk
@@ -124,12 +124,17 @@
 ART_TEST_RUN_TEST_MULTI_IMAGE ?= $(ART_TEST_FULL)
 
 # Define the command run on test failure. $(1) is the name of the test. Executed by the shell.
+# If the test was a top-level make target (e.g. `test-art-host-gtest-codegen_test64`), the command
+# fails with exit status 1 (returned by the last `grep` statement below).
+# Otherwise (e.g., if the test was run as a prerequisite of a compound test command, such as
+# `test-art-host-gtest-codegen_test`), the command does not fail, as this would break rules running
+# ART_TEST_PREREQ_FINISHED as one of their actions, which expects *all* prerequisites *not* to fail.
 define ART_TEST_FAILED
   ( [ -f $(ART_HOST_TEST_DIR)/skipped/$(1) ] || \
     (mkdir -p $(ART_HOST_TEST_DIR)/failed/ && touch $(ART_HOST_TEST_DIR)/failed/$(1) && \
       echo $(ART_TEST_KNOWN_FAILING) | grep -q $(1) \
         && (echo -e "$(1) \e[91mKNOWN FAILURE\e[0m") \
-        || (echo -e "$(1) \e[91mFAILED\e[0m" >&2 )))
+        || (echo -e "$(1) \e[91mFAILED\e[0m" >&2; echo $(MAKECMDGOALS) | grep -q -v $(1))))
 endef
 
 ifeq ($(ART_TEST_QUIET),true)