Use a Soong config variable to toggle between ART Module source and
prebuilts.

When ART Module prebuilts are in use (i.e. have prefer:true), they
interfere with apex/sdk/module_exports modules and cause Soong
failures.

To work around that problem the aim is to disable those modules when
the prebuilts are preferred, and introduce a product variable to toggle
it the other way. That variable is then set in ART-specific products
which should be used in ART source builds.

That way platform builds will use the prebuilts even if ART sources are
available, without disabling all the ART source modules.

This topic does all the preparations for that except the actual flip to
start using prebuilts by default.

Test: m SKIP_BOOT_JARS_CHECK=true \
      UNSAFE_DISABLE_HIDDENAPI_FLAGS=true nothing
  on AOSP master with dexpreopting disabled and the default flipped to
  use prebuilts
Test: art/build/build-art-module.sh
      art/build/apex/runtests.sh
      art/tools/buildbot-build.sh {--host,--target}
      art/tools/run-gtests.sh (in device chroot)
      art/test/testrunner/testrunner.py --target --64 --optimizing
        (in device chroot)
  on master-art with the default flipped to use prebuilts
Test: Use NINJA_ARGS="-t query ..." to check the dependencies of
  art-runtime both when APEXes are enabled and disabled.
Bug: 172480617
Change-Id: I1126e7dc40ab55fca1df0043199da5cb449de14d
diff --git a/Android.mk b/Android.mk
index d224681..a46d41d 100644
--- a/Android.mk
+++ b/Android.mk
@@ -335,7 +335,11 @@
 LOCAL_MODULE := com.android.art-autoselect
 LOCAL_IS_HOST_MODULE := true
 ifneq ($(HOST_OS),darwin)
-  LOCAL_REQUIRED_MODULES += $(APEX_TEST_MODULE)
+  # The testing APEX is enabled only when compiling from ART Module sources,
+  # which is controlled by this Soong variable.
+  ifeq (true,$(SOONG_CONFIG_art_module_source_build))
+    LOCAL_REQUIRED_MODULES += $(APEX_TEST_MODULE)
+  endif
 endif
 include $(BUILD_PHONY_PACKAGE)
 
@@ -385,18 +389,31 @@
 include $(CLEAR_VARS)
 LOCAL_MODULE := art-runtime
 
+# Reference the libraries and binaries in the appropriate APEX module, because
+# they don't have platform variants. However if
+# SOONG_CONFIG_art_module_source_build isn't true then the APEX modules are
+# disabled, so Soong won't apply the APEX mutators to them, and then they are
+# available with their plain names.
+ifeq (true,$(SOONG_CONFIG_art_module_source_build))
+  art_module_lib = $(1).com.android.art
+  art_module_debug_lib = $(1).com.android.art.debug
+else
+  art_module_lib = $(1)
+  art_module_debug_lib = $(1)
+endif
+
 # Base requirements.
 LOCAL_REQUIRED_MODULES := \
-    dalvikvm.com.android.art \
-    dex2oat.com.android.art \
-    dexoptanalyzer.com.android.art \
-    libart.com.android.art \
-    libart-compiler.com.android.art \
-    libopenjdkjvm.com.android.art \
-    libopenjdkjvmti.com.android.art \
-    profman.com.android.art \
-    libadbconnection.com.android.art \
-    libperfetto_hprof.com.android.art \
+    $(call art_module_lib,dalvikvm) \
+    $(call art_module_lib,dex2oat) \
+    $(call art_module_lib,dexoptanalyzer) \
+    $(call art_module_lib,libart) \
+    $(call art_module_lib,libart-compiler) \
+    $(call art_module_lib,libopenjdkjvm) \
+    $(call art_module_lib,libopenjdkjvmti) \
+    $(call art_module_lib,profman) \
+    $(call art_module_lib,libadbconnection) \
+    $(call art_module_lib,libperfetto_hprof) \
 
 # Potentially add in debug variants:
 #
@@ -410,20 +427,23 @@
 endif
 ifeq (true,$(art_target_include_debug_build))
 LOCAL_REQUIRED_MODULES += \
-    dex2oatd.com.android.art.debug \
-    dexoptanalyzerd.com.android.art.debug \
-    libartd.com.android.art.debug \
-    libartd-compiler.com.android.art.debug \
-    libopenjdkd.com.android.art.debug \
-    libopenjdkjvmd.com.android.art.debug \
-    libopenjdkjvmtid.com.android.art.debug \
-    profmand.com.android.art.debug \
-    libadbconnectiond.com.android.art.debug \
-    libperfetto_hprofd.com.android.art.debug \
+    $(call art_module_debug_lib,dex2oatd) \
+    $(call art_module_debug_lib,dexoptanalyzerd) \
+    $(call art_module_debug_lib,libartd) \
+    $(call art_module_debug_lib,libartd-compiler) \
+    $(call art_module_debug_lib,libopenjdkd) \
+    $(call art_module_debug_lib,libopenjdkjvmd) \
+    $(call art_module_debug_lib,libopenjdkjvmtid) \
+    $(call art_module_debug_lib,profmand) \
+    $(call art_module_debug_lib,libadbconnectiond) \
+    $(call art_module_debug_lib,libperfetto_hprofd) \
 
 endif
 endif
 
+art_module_lib :=
+art_module_debug_lib :=
+
 include $(BUILD_PHONY_PACKAGE)
 
 # The art-tools package depends on helpers and tools that are useful for developers. Similar