Support Soong native coverage

Soong (or any other prebuilt) can provide a .gcnodir file using
LOCAL_PREBUILT_COVERAGE_ARCHIVE. Just like today, if one isn't provided
for static libraries, an empty one will be created for Make modules to
use.

Also fixes a problem I noticed including whole static libs having
coverage into static libs. It was trying to write to /WHOLE since
PRIVATE_INTERMEDIATES_DIR was not set.

Bug: 32749731
Test: See build/soong change for soong-side tests
Test: Enabled coverage of a soong static lib, then include it in a make
static lib with LOCAL_WHOLE_STATIC_LIBRARIES and ensure that the any
shared libraries using the make static lib get the embedded coverage
information.
Change-Id: I32762f099c9757074fec922ee4822f819c9ceaf5
diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk
index 10512ff..997f971 100644
--- a/core/prebuilt_internal.mk
+++ b/core/prebuilt_internal.mk
@@ -174,6 +174,19 @@
 endif  # my_strip_module not true
 
 ifeq ($(NATIVE_COVERAGE),true)
+ifneq (,$(strip $(LOCAL_PREBUILT_COVERAGE_ARCHIVE)))
+  $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(intermediates)/$(LOCAL_MODULE).gcnodir))
+  ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true)
+    ifdef LOCAL_IS_HOST_MODULE
+      my_coverage_path := $($(my_prefix)OUT_COVERAGE)/$(patsubst $($(my_prefix)OUT)/%,%,$(my_module_path))
+    else
+      my_coverage_path := $(TARGET_OUT_COVERAGE)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
+    endif
+    my_coverage_path := $(my_coverage_path)/$(basename $(my_installed_module_stem)).gcnodir
+    $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(my_coverage_path)))
+    $(LOCAL_BUILT_MODULE): $(my_coverage_path)
+  endif
+else
 # Coverage information is needed when static lib is a dependency of another
 # coverage-enabled module.
 ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS))
@@ -186,6 +199,7 @@
 	$(transform-o-to-static-lib)
 endif
 endif
+endif
 
 ifeq ($(LOCAL_MODULE_CLASS),APPS)
 PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))