Move coverage builds prebuilt special case to make

Having this in make has the following advantages
- allows this to be used in other places in make that are sensitive to
  prebuilt selection, e.g. apex boot jars that are present in source but
  not in prebuilt apexes
- collocates the various prebuilt special edge cases

Test: presubmits
Test: in internal, lunch cf_x86_64_phone-next-userdebug
Test: EMMA_INSTRUMENT_FRAMEWORK=true get_build_var PRODUCT_BUILD_IGNORE_APEX_CONTRIBUTION_CONTENTS
true

Bug: 308188056
Change-Id: I3e81b348e9f1e72e6d120a881d37356c413b005b
diff --git a/core/product_config.mk b/core/product_config.mk
index 4eeac95..f21c1c4 100644
--- a/core/product_config.mk
+++ b/core/product_config.mk
@@ -314,6 +314,14 @@
 ifeq (true,$(PRODUCT_MODULE_BUILD_FROM_SOURCE))
   ignore_apex_contributions := true
 endif
+ifneq ($(EMMA_INSTRUMENT)$(EMMA_INSTRUMENT_STATIC)$(EMMA_INSTRUMENT_FRAMEWORK)$(CLANG_COVERAGE)$(NATIVE_COVERAGE_PATHS),)
+# Coverage builds for TARGET_RELEASE=foo should always build from source,
+# even if TARGET_RELEASE=foo uses prebuilt mainline modules.
+# This is necessary because the checked-in prebuilts were generated with
+# instrumentation turned off.
+  ignore_apex_contributions := true
+endif
+
 ifeq (true, $(ignore_apex_contributions))
 PRODUCT_BUILD_IGNORE_APEX_CONTRIBUTION_CONTENTS := true
 endif