am 8c212ebe: Merge "Only use  if it exists and is writable."

# Via Elliott Hughes (1) and Gerrit Code Review (1)
* commit '8c212ebe53bb2baab3575f03069016f1fb11e449':
  Only use $EXTERNAL_STORAGE if it exists and is writable.
diff --git a/src/Android.mk b/src/Android.mk
index dbbf779..52c8a0a 100644
--- a/src/Android.mk
+++ b/src/Android.mk
@@ -29,8 +29,6 @@
 LOCAL_PATH := $(call my-dir)
 
 libgtest_target_includes := \
-    bionic/libstdc++/include \
-    external/stlport/stlport \
     $(LOCAL_PATH)/.. \
     $(LOCAL_PATH)/../include
 
@@ -77,16 +75,21 @@
 
 include $(CLEAR_VARS)
 
+ifeq ($(TARGET_ARCH), arm)
+   LOCAL_SDK_VERSION := 8
+else
+# NDK support of other archs (ie. x86 and mips) are only available after android-9
+   LOCAL_SDK_VERSION := 9
+endif
+
+LOCAL_NDK_STL_VARIANT := stlport_static
+
 LOCAL_CPP_EXTENSION := .cc
 
 LOCAL_SRC_FILES := gtest-all.cc
 
 LOCAL_C_INCLUDES := $(libgtest_target_includes)
 
-ifneq ($(BUILD_WITH_ASTL),true)
-include external/stlport/libstlport.mk
-endif
-
 LOCAL_MODULE := libgtest
 
 include $(BUILD_STATIC_LIBRARY)
@@ -96,16 +99,21 @@
 
 include $(CLEAR_VARS)
 
+ifeq ($(TARGET_ARCH), arm)
+   LOCAL_SDK_VERSION := 8
+else
+# NDK support of other archs (ie. x86 and mips) are only available after android-9
+   LOCAL_SDK_VERSION := 9
+endif
+
+LOCAL_NDK_STL_VARIANT := stlport_static
+
 LOCAL_CPP_EXTENSION := .cc
 
 LOCAL_SRC_FILES := gtest_main.cc
 
 LOCAL_C_INCLUDES := $(libgtest_target_includes)
 
-ifneq ($(BUILD_WITH_ASTL),true)
-include external/stlport/libstlport.mk
-endif
-
 LOCAL_MODULE := libgtest_main
 
 include $(BUILD_STATIC_LIBRARY)
diff --git a/test/Android.mk b/test/Android.mk
index d642db9..1fb1d2d 100644
--- a/test/Android.mk
+++ b/test/Android.mk
@@ -23,67 +23,51 @@
 # TODO: Refactor these as 1st class build templates as suggested in
 # review of the original import.
 
-# Gtest depends on STLPort which does not build on host/simulator.
+libgtest_test_common_includes := \
+    $(LOCAL_PATH)/../include \
+    $(LOCAL_PATH)/..
 
-ifeq ($(BUILD_WITH_ASTL),true)
-libgtest_test_includes := \
-    bionic/libstdc++/include \
-    external/astl/include \
-	$(LOCAL_PATH)/../include \
-	$(LOCAL_PATH)/..
-libgtest_test_static_lib := libgtest_main libgtest libastl
-libgtest_test_shared_lib :=
-libgtest_test_host_static_lib := libgtest_main_host libgtest_host libastl_host
-libgtest_test_host_shared_lib :=
-else
-# BUILD_WITH_ASTL could be undefined, force it to false (for the guard
-# before the test-target call).
-BUILD_WITH_ASTL := false
-libgtest_test_includes := \
-    bionic \
-    external/stlport/stlport \
-	$(LOCAL_PATH)/../include \
-	$(LOCAL_PATH)/..
+libgtest_test_includes := $(libgtest_test_common_includes) bionic external/stlport/stlport
 libgtest_test_static_lib := libgtest_main libgtest
 libgtest_test_shared_lib := libstlport
-libgtest_test_host_static_lib :=
+
+libgtest_test_host_includes := $(libgtest_test_common_includes)
+libgtest_test_host_static_lib := libgtest_main_host libgtest_host
 libgtest_test_host_shared_lib :=
-endif
 
 # $(2) and $(4) must be set or cleared in sync. $(2) is used to
 # generate the right make target (host vs device). $(4) is used in the
 # module's name and to have different module names for the host vs
-# device builds. Finally $(4) is used to pickup the right set of
+# device builds. Finally $(4) is used to pick up the right set of
 # libraries, typically the host libs have a _host suffix in their
 # names.
 # $(1): source list
 # $(2): "HOST_" or empty
 # $(3): extra CFLAGS or empty
 # $(4): "_host" or empty
+# $(5): "TARGET_OUT_DATA_NATIVE_TESTS" or empty (where to install)
 define _define-test
 $(foreach file,$(1), \
   $(eval include $(CLEAR_VARS)) \
   $(eval LOCAL_CPP_EXTENSION := .cc) \
   $(eval LOCAL_SRC_FILES := $(file)) \
-  $(eval LOCAL_C_INCLUDES := $(libgtest_test_includes)) \
+  $(eval LOCAL_C_INCLUDES := $(libgtest_test$(4)_includes)) \
   $(eval LOCAL_MODULE := $(notdir $(file:%.cc=%))$(4)) \
   $(eval LOCAL_CFLAGS += $(3)) \
   $(eval LOCAL_STATIC_LIBRARIES := $(libgtest_test$(4)_static_lib)) \
   $(eval LOCAL_SHARED_LIBRARIES := $(libgtest_test$(4)_shared_lib)) \
-  $(eval LOCAL_MODULE_TAGS := tests) \
-  $(eval LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_NATIVE_TESTS)) \
+  $(if $(2),,$(eval LOCAL_MODULE_TAGS := tests)) \
+  $(eval LOCAL_MODULE_PATH := $($(5))) \
   $(eval include $(BUILD_$(2)EXECUTABLE)) \
 )
 endef
 
-ifeq ($(HOST_OS)-$(BUILD_WITH_ASTL),linux-true)
 define host-test
-$(call _define-test,$(1),HOST_,-O0,_host)
+$(call _define-test,$(1),HOST_,-O0,_host,)
 endef
-endif
 
 define target-test
-$(call _define-test,$(1))
+$(call _define-test,$(1),,,,TARGET_OUT_DATA_NATIVE_TESTS)
 endef
 
 sources := \
@@ -104,8 +88,5 @@
   gtest_unittest.cc \
   gtest_prod_test.cc
 
-ifeq ($(HOST_OS)-$(BUILD_WITH_ASTL),linux-true)
 $(call host-test, $(sources))
-endif
-
 $(call target-test, $(sources))