Disable most ART source modules when ART prebuilts are enabled.

After libdexfile_external was merged into libdexfile, libdexfile is an
APEX stub when prebuilts are enabled, and that cannot be used to build
libart and all the other internal modules that depend on it.

This CL:

- Changes art_defaults to disable native modules when building from
  prebuilts. Some other modules that depends on them, like the
  art-script sh_binary, also get disabled.
- Consolidates the makefile sections that are disabled when building
  from prebuilts so that only a small bit is still enabled then.
- Temporarily removes the prebuilt for libctstiagent and activates its
  source even when prebuilts are used, to work around sdk_version
  problem (b/187288515).
- Removes explicit "enabled: true" in a couple of places that would
  override the inherited flag that lets us disable them in builds from
  prebuilts.
- Makes some Soong defaults available to libcore.

Cherry-picked from https://r.android.com/1711019.

Test: m checkbuild
Test: art/build/build-art-module.sh --skip-apex
      packages/modules/ArtPrebuilt/update-art-module-prebuilts.py \
        --local-dist out/dist/ --skip-apex
      m SOONG_CONFIG_art_module_source_build=false droid
      m SOONG_CONFIG_art_module_source_build=false checkbuild
Bug: 172480615
Change-Id: Ief60b933cd6273fc8b85fe7637b99ba1b78505f6
Merged-In: Ief60b933cd6273fc8b85fe7637b99ba1b78505f6
diff --git a/Android.mk b/Android.mk
index 3bdcc5f..4889d34 100644
--- a/Android.mk
+++ b/Android.mk
@@ -18,6 +18,8 @@
 
 art_path := $(LOCAL_PATH)
 
+include $(art_path)/tools/veridex/Android.mk
+
 ########################################################################
 # clean-oat rules
 #
@@ -54,12 +56,64 @@
 include $(art_path)/build/Android.cpplint.mk
 
 ########################################################################
+# The art-tools package depends on helpers and tools that are useful for developers. Similar
+# dependencies exist for the APEX builds for these tools (see build/apex/Android.bp).
+
+ifneq ($(HOST_OS),darwin)
+include $(CLEAR_VARS)
+LOCAL_MODULE := art-tools
+LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD SPDX-license-identifier-GPL-2.0
+LOCAL_LICENSE_CONDITIONS := notice restricted
+LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
+LOCAL_IS_HOST_MODULE := true
+
+ifeq (true,$(my_art_module_source_build))
+
+LOCAL_REQUIRED_MODULES := \
+    ahat \
+    dexdump \
+    hprof-conv \
+
+# A subset of the tools are disabled when HOST_PREFER_32_BIT is defined as make reports that
+# they are not supported on host (b/129323791). This is likely due to art_apex disabling host
+# APEX builds when HOST_PREFER_32_BIT is set (b/120617876).
+ifneq ($(HOST_PREFER_32_BIT),true)
+LOCAL_REQUIRED_MODULES += \
+    dexdiag \
+    dexlist \
+    oatdump \
+
+endif
+
+else
+
+# The developer tools available as prebuilts.
+LOCAL_REQUIRED_MODULES := \
+    dexdump \
+    oatdump \
+
+endif # ifeq (true,$(my_art_module_source_build))
+
+include $(BUILD_PHONY_PACKAGE)
+endif # HOST_OS != darwin
+
+
+########################################################################
+# Everything below is only available in ART source builds
+# (SOONG_CONFIG_art_module_source_build=true).
+########################################################################
+
+# TODO(b/172480617): Clean up the platform dependencies on everything above and
+# remove this condition.
+ifeq (true,$(my_art_module_source_build))
+
+
+########################################################################
 # product rules
 
 include $(art_path)/oatdump/Android.mk
 include $(art_path)/tools/ahat/Android.mk
 include $(art_path)/tools/dexfuzz/Android.mk
-include $(art_path)/tools/veridex/Android.mk
 
 ART_HOST_DEPENDENCIES := \
   $(ART_HOST_EXECUTABLES) \
@@ -112,8 +166,6 @@
 ########################################################################
 # host test rules
 
-ifeq (true,$(my_art_module_source_build))
-
 test-art: test-art-host
 test-art-gtest: test-art-host-gtest
 test-art-run-test: test-art-host-run-test
@@ -207,8 +259,6 @@
 test-art-host-dexdump: $(addprefix $(HOST_OUT_EXECUTABLES)/, dexdump dexlist)
 	ANDROID_HOST_OUT=$(realpath $(HOST_OUT)) art/test/dexdump/run-all-tests
 
-endif # ifeq (true,$(my_art_module_source_build))
-
 ########################################################################
 # target test rules
 
@@ -400,35 +450,6 @@
 
 include $(BUILD_PHONY_PACKAGE)
 
-# The art-tools package depends on helpers and tools that are useful for developers. Similar
-# dependencies exist for the APEX builds for these tools (see build/apex/Android.bp).
-
-ifneq ($(HOST_OS),darwin)
-include $(CLEAR_VARS)
-LOCAL_MODULE := art-tools
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD SPDX-license-identifier-GPL-2.0
-LOCAL_LICENSE_CONDITIONS := notice restricted
-LOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICE
-LOCAL_IS_HOST_MODULE := true
-LOCAL_REQUIRED_MODULES := \
-    ahat \
-    dexdump \
-    hprof-conv \
-
-# A subset of the tools are disabled when HOST_PREFER_32_BIT is defined as make reports that
-# they are not supported on host (b/129323791). This is likely due to art_apex disabling host
-# APEX builds when HOST_PREFER_32_BIT is set (b/120617876).
-ifneq ($(HOST_PREFER_32_BIT),true)
-LOCAL_REQUIRED_MODULES += \
-    dexdiag \
-    dexlist \
-    oatdump \
-
-endif
-
-include $(BUILD_PHONY_PACKAGE)
-endif # HOST_OS != darwin
-
 ####################################################################################################
 # Fake packages to ensure generation of libopenjdkd when one builds with mm/mmm/mmma.
 #
@@ -458,8 +479,6 @@
 # "m build-art" for quick minimal build
 .PHONY: build-art
 
-ifeq (true,$(my_art_module_source_build))
-
 build-art: build-art-host
 
 # For host, we extract the ICU data from the apex and install it to HOST_OUT/I18N_APEX.
@@ -480,8 +499,6 @@
 .PHONY: build-art-host
 build-art-host:   $(HOST_OUT_EXECUTABLES)/art $(ART_HOST_DEPENDENCIES) $(HOST_CORE_IMG_OUTS) $(HOST_I18N_DATA) $(HOST_TZDATA_DATA)
 
-endif # ifeq (true,$(my_art_module_source_build))
-
 build-art: build-art-target
 
 .PHONY: build-art-target
@@ -709,8 +726,6 @@
 ########################################################################
 # Phony target for building what go/lem requires on host.
 
-ifeq (true,$(my_art_module_source_build))
-
 .PHONY: build-art-host-golem
 # Also include libartbenchmark, we always include it when running golem.
 ART_HOST_SHARED_LIBRARY_BENCHMARK := $(ART_HOST_OUT_SHARED_LIBRARIES)/libartbenchmark.so
@@ -718,8 +733,6 @@
                       $(ART_HOST_SHARED_LIBRARY_BENCHMARK) \
                       $(HOST_OUT_EXECUTABLES)/dex2oat_wrapper
 
-endif # ifeq (true,$(my_art_module_source_build))
-
 ########################################################################
 # Phony target for building what go/lem requires for syncing /system to target.
 .PHONY: build-art-unbundled-golem
@@ -729,13 +742,9 @@
 ########################################################################
 # Rules for building all dependencies for tests.
 
-ifeq (true,$(my_art_module_source_build))
-
 .PHONY: build-art-host-tests
 build-art-host-tests:   build-art-host $(TEST_ART_RUN_TEST_DEPENDENCIES) $(ART_TEST_HOST_RUN_TEST_DEPENDENCIES) $(ART_TEST_HOST_GTEST_DEPENDENCIES) | $(TEST_ART_RUN_TEST_ORDERONLY_DEPENDENCIES)
 
-endif # ifeq (true,$(my_art_module_source_build))
-
 .PHONY: build-art-target-tests
 build-art-target-tests:   build-art-target $(TEST_ART_RUN_TEST_DEPENDENCIES) $(ART_TEST_TARGET_RUN_TEST_DEPENDENCIES) $(ART_TEST_TARGET_GTEST_DEPENDENCIES) | $(TEST_ART_RUN_TEST_ORDERONLY_DEPENDENCIES)
 
@@ -902,3 +911,5 @@
 
 MIN_SDK_VERSION :=
 SDK_VERSIONS :=
+
+endif # ifeq (true,$(my_art_module_source_build))
diff --git a/build/Android.bp b/build/Android.bp
index c3f71f3..9236074 100644
--- a/build/Android.bp
+++ b/build/Android.bp
@@ -63,11 +63,30 @@
     "-modernize-pass-by-value",
 ]
 
-art_global_defaults {
+soong_config_module_type_import {
+    from: "art/build/SoongConfig.bp",
+    module_types: [
+        "art_module_art_global_defaults",
+        "art_module_cc_defaults",
+        "art_module_java_defaults",
+    ],
+}
+
+art_module_art_global_defaults {
     // Additional flags are computed by art.go
 
     name: "art_defaults",
 
+    // Disable all ART Soong modules by default when ART prebuilts are in use.
+    // TODO(b/172480617): Clean up when sources are gone from the platform tree
+    // and we no longer need to support sources present when prebuilts are used.
+    enabled: false,
+    soong_config_variables: {
+        source_build: {
+            enabled: true,
+        },
+    },
+
     // This is the default visibility for the //art package, but we repeat it
     // here so that it gets merged with other visibility rules in modules
     // extending these defaults.
@@ -180,6 +199,13 @@
         darwin: {
             enabled: false,
         },
+        windows: {
+            // When the module is enabled globally in the soong_config_variables
+            // stanza above, it may get enabled on windows too for some module
+            // types. Hence we need to disable it explicitly.
+            // TODO(b/172480617): Clean up with that.
+            enabled: false,
+        },
         host: {
             cflags: [
                 // Bug: 15446488. We don't omit the frame pointer to work around
@@ -290,14 +316,6 @@
     min_sdk_version: "S",
 }
 
-soong_config_module_type_import {
-    from: "art/build/SoongConfig.bp",
-    module_types: [
-        "art_module_cc_defaults",
-        "art_module_java_defaults",
-    ],
-}
-
 // Use this to enable a cc_* module only when building ART from sources.
 // TODO(b/172480617): Clean up when sources are gone from the platform tree and
 // we no longer need to support sources present when prebuilts are used.
@@ -305,6 +323,7 @@
     name: "art_module_source_build_defaults",
     defaults_visibility: [
         "//art:__subpackages__",
+        "//libcore:__subpackages__",
         "//libnativehelper:__subpackages__",
     ],
 
@@ -330,6 +349,7 @@
     name: "art_module_source_build_java_defaults",
     defaults_visibility: [
         "//art:__subpackages__",
+        "//libcore:__subpackages__",
         "//libnativehelper:__subpackages__",
     ],
 
diff --git a/build/Android.common_path.mk b/build/Android.common_path.mk
index d485518..c6f4819 100644
--- a/build/Android.common_path.mk
+++ b/build/Android.common_path.mk
@@ -30,6 +30,8 @@
   $(error SOONG_CONFIG_art_module_source_build is neither true nor false - mk file ordering problem?)
 endif
 
+ifeq (true,$(my_art_module_source_build))
+
 include art/build/Android.common.mk
 include art/build/Android.common_build.mk
 
@@ -61,8 +63,6 @@
 HOST_CORE_IMG_DEX_FILES   := $(foreach jar,$(HOST_CORE_IMG_JARS),  $(call intermediates-dir-for,JAVA_LIBRARIES,$(jar),t,COMMON)/javalib.jar)
 TARGET_CORE_IMG_DEX_FILES := $(foreach jar,$(TARGET_CORE_IMG_JARS),$(call intermediates-dir-for,JAVA_LIBRARIES,$(jar).com.android.art.testing, ,COMMON)/javalib.jar)
 
-ifeq (true,$(my_art_module_source_build))
-
 # Also copy the jar files next to host boot.art image.
 HOST_BOOT_IMAGE_JARS := $(foreach jar,$(CORE_IMG_JARS),$(HOST_OUT)/apex/com.android.art/javalib/$(jar).jar)
 $(HOST_BOOT_IMAGE_JARS): $(HOST_OUT)/apex/com.android.art/javalib/%.jar : $(HOST_OUT_JAVA_LIBRARIES)/%-hostdex.jar
@@ -75,8 +75,6 @@
 $(HOST_OUT)/apex/com.android.i18n/javalib/core-icu4j.jar : $(HOST_OUT_JAVA_LIBRARIES)/core-icu4j-hostdex.jar
 	$(copy-file-to-target)
 
-endif # ifeq (true,$(my_art_module_source_build))
-
 HOST_CORE_IMG_OUTS += $(HOST_BOOT_IMAGE_JARS) $(HOST_BOOT_IMAGE) $(2ND_HOST_BOOT_IMAGE)
 
 HOST_TEST_CORE_JARS   := $(addsuffix -hostdex,$(CORE_IMG_JARS) core-icu4j conscrypt)
@@ -150,4 +148,6 @@
 # A phony file to create the tz data file for host.
 HOST_TZDATA_DATA := $(HOST_OUT)/$(TZDATA_APEX)/timestamp
 
+endif # ifeq (true,$(my_art_module_source_build))
+
 endif # ART_ANDROID_COMMON_PATH_MK
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index cb1d2eb..c83b3d1 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -17,8 +17,6 @@
 # Build rules are excluded from Mac, since we can not run ART tests there in the first place.
 ifneq ($(HOST_OS),darwin)
 
-ifeq (true,$(my_art_module_source_build))
-
 LOCAL_PATH := $(call my-dir)
 
 ###################################################################################################
@@ -95,8 +93,6 @@
 include $(CLEAR_VARS)
 ###################################################################################################
 
-endif # ifeq (true,$(my_art_module_source_build))
-
 # The path for which all the dex files are relative, not actually the current directory.
 LOCAL_PATH := art/test
 
@@ -361,15 +357,13 @@
     com.android.art.testing \
     com.android.conscrypt
 endif
-ifeq (true,$(my_art_module_source_build))
-  ifeq ($(ART_BUILD_HOST),true)
-    $(foreach file,$(ART_HOST_GTEST_FILES), $(eval $(call define-art-gtest-host,$(file),)))
-    ifneq ($(HOST_PREFER_32_BIT),true)
-      $(foreach file,$(2ND_ART_HOST_GTEST_FILES), $(eval $(call define-art-gtest-host,$(file),2ND_)))
-    endif
-    # Rules to run the different architecture versions of the gtest.
-    $(foreach file,$(ART_HOST_GTEST_FILES), $(eval $(call define-art-gtest-host-both,$$(notdir $$(basename $$(file))))))
+ifeq ($(ART_BUILD_HOST),true)
+  $(foreach file,$(ART_HOST_GTEST_FILES), $(eval $(call define-art-gtest-host,$(file),)))
+  ifneq ($(HOST_PREFER_32_BIT),true)
+    $(foreach file,$(2ND_ART_HOST_GTEST_FILES), $(eval $(call define-art-gtest-host,$(file),2ND_)))
   endif
+  # Rules to run the different architecture versions of the gtest.
+  $(foreach file,$(ART_HOST_GTEST_FILES), $(eval $(call define-art-gtest-host-both,$$(notdir $$(basename $$(file))))))
 endif
 
 # Define all the combinations of host/target and suffix such as:
diff --git a/build/SoongConfig.bp b/build/SoongConfig.bp
index 38c0d97..3e2d8fc 100644
--- a/build/SoongConfig.bp
+++ b/build/SoongConfig.bp
@@ -11,6 +11,14 @@
 }
 
 soong_config_module_type {
+    name: "art_module_art_global_defaults",
+    module_type: "art_global_defaults",
+    config_namespace: "art_module",
+    bool_variables: ["source_build"],
+    properties: ["enabled"],
+}
+
+soong_config_module_type {
     name: "art_module_apex_defaults",
     module_type: "apex_defaults",
     config_namespace: "art_module",
@@ -30,6 +38,14 @@
 }
 
 soong_config_module_type {
+    name: "art_module_cc_genrule",
+    module_type: "cc_genrule",
+    config_namespace: "art_module",
+    bool_variables: ["source_build"],
+    properties: ["enabled"],
+}
+
+soong_config_module_type {
     name: "art_module_exports",
     module_type: "module_exports",
     config_namespace: "art_module",
@@ -60,3 +76,11 @@
     bool_variables: ["source_build"],
     properties: ["enabled"],
 }
+
+soong_config_module_type {
+    name: "art_module_sh_binary",
+    module_type: "sh_binary",
+    config_namespace: "art_module",
+    bool_variables: ["source_build"],
+    properties: ["enabled"],
+}
diff --git a/build/sdk/Android.bp b/build/sdk/Android.bp
index f6b37e7..35fd017 100644
--- a/build/sdk/Android.bp
+++ b/build/sdk/Android.bp
@@ -263,6 +263,9 @@
         "libjavacoretests",
     ],
     native_static_libs: [
-        "libctstiagent",
+        // TODO(b/187288515): Providing this as a prebuilt introduces an issue
+        // with sdk_version propagation. Temporarily use the source library
+        // instead.
+        //"libctstiagent",
     ],
 }
diff --git a/dexdump/Android.bp b/dexdump/Android.bp
index 87abfc1..eb33b26 100644
--- a/dexdump/Android.bp
+++ b/dexdump/Android.bp
@@ -46,7 +46,6 @@
         // Use static libs on host: required for Windows build and
         // static_sdk_tools build.
         host: {
-            enabled: true,
             stl: "libc++_static",
             static_libs: [
                 "libdexfile",
diff --git a/libdexfile/Android.bp b/libdexfile/Android.bp
index 1a3c7bd..b8cdd8b 100644
--- a/libdexfile/Android.bp
+++ b/libdexfile/Android.bp
@@ -330,7 +330,10 @@
 
 art_cc_test {
     name: "art_libdexfile_external_tests",
-    defaults: ["art_test_defaults"],
+    defaults: [
+        "art_module_source_build_defaults",
+        "art_test_defaults",
+    ],
     test_suites: ["general-tests"],
     srcs: [
         "external/dex_file_ext_c_test.c",
@@ -382,6 +385,7 @@
 art_cc_test {
     name: "art_libdexfile_support_tests",
     defaults: [
+        "art_module_source_build_defaults",
         "art_test_defaults",
     ],
     host_supported: true,
@@ -434,6 +438,7 @@
     name: "art_libdexfile_support_static_tests",
     test_suites: ["general-tests"],
     defaults: [
+        "art_module_source_build_defaults",
         "art_test_defaults",
         "libdexfile_support_static_defaults",
     ],
diff --git a/libnativeloader/Android.bp b/libnativeloader/Android.bp
index 2cc6b80..8b8fb27 100644
--- a/libnativeloader/Android.bp
+++ b/libnativeloader/Android.bp
@@ -118,7 +118,10 @@
 
 art_cc_test {
     name: "libnativeloader_test",
-    defaults: ["art_test_defaults"],
+    defaults: [
+        "art_module_source_build_defaults",
+        "art_test_defaults",
+    ],
     host_supported: false,
 
     srcs: [
diff --git a/odrefresh/Android.bp b/odrefresh/Android.bp
index e504064..10845c5 100644
--- a/odrefresh/Android.bp
+++ b/odrefresh/Android.bp
@@ -52,9 +52,6 @@
             // Use the 32-bit version of odrefresh on devices.
             compile_multilib: "prefer32",
         },
-        linux: {
-            enabled: true,
-        },
         host: {
             shared_libs: [
                 // Both these libraries for libxml2 on host for code derived from apex-info-list.
diff --git a/test/Android.bp b/test/Android.bp
index ec96ce6..82027a7 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -560,6 +560,14 @@
 cc_library_static {
     name: "libctstiagent",
     defaults: ["libtiagent-base-defaults"],
+
+    // TODO(b/187288515): Providing this as a prebuilt introduces an issue with
+    // sdk_version propagation. Temporarily use the source library instead,
+    // which means we need to override the logic inherited from art_defaults and
+    // art_test_internal_library_defaults that disables sources when not
+    // building ART from sources.
+    enabled: true,
+
     visibility: [
         "//cts/hostsidetests/jvmti:__subpackages__",
     ],
diff --git a/test/Android.run-test.mk b/test/Android.run-test.mk
index 5480860..8b5aae4 100644
--- a/test/Android.run-test.mk
+++ b/test/Android.run-test.mk
@@ -94,13 +94,11 @@
 
 endif
 
-ifeq (true,$(my_art_module_source_build))
-  test-art-host-run-test-dependencies : \
-	$(ART_TEST_HOST_RUN_TEST_DEPENDENCIES) $(TEST_ART_RUN_TEST_DEPENDENCIES) \
-	$(HOST_BOOT_IMAGE_JARS) $(HOST_BOOT_IMAGE) $(2ND_HOST_BOOT_IMAGE)
-  .PHONY: test-art-host-run-test-dependencies
-  test-art-run-test-dependencies : test-art-host-run-test-dependencies
-endif
+test-art-host-run-test-dependencies : \
+      $(ART_TEST_HOST_RUN_TEST_DEPENDENCIES) $(TEST_ART_RUN_TEST_DEPENDENCIES) \
+      $(HOST_BOOT_IMAGE_JARS) $(HOST_BOOT_IMAGE) $(2ND_HOST_BOOT_IMAGE)
+.PHONY: test-art-host-run-test-dependencies
+test-art-run-test-dependencies : test-art-host-run-test-dependencies
 
 test-art-target-run-test-dependencies :
 .PHONY: test-art-target-run-test-dependencies
@@ -123,10 +121,7 @@
 endef  # define-test-art-host-or-target-run-test-group
 
 $(eval $(call define-test-art-host-or-target-run-test-group,target))
-
-ifeq (true,$(my_art_module_source_build))
-  $(eval $(call define-test-art-host-or-target-run-test-group,host))
-endif
+$(eval $(call define-test-art-host-or-target-run-test-group,host))
 
 define-test-art-host-or-target-run-test-group :=
 LOCAL_PATH :=
diff --git a/tools/Android.bp b/tools/Android.bp
index c154dc8..9b9d3a7 100644
--- a/tools/Android.bp
+++ b/tools/Android.bp
@@ -38,9 +38,28 @@
     },
 }
 
+soong_config_module_type_import {
+    from: "art/build/SoongConfig.bp",
+    module_types: [
+        "art_module_sh_binary",
+    ],
+}
+
 // Copy the art shell script to the host and target's bin directory
-sh_binary {
+art_module_sh_binary {
     name: "art-script",
+
+    // Disable this script in prebuilt mode since it depends on dalvikvm which
+    // isn't a prebuilt.
+    // TODO(b/172480617): Clean up when sources are gone from the platform tree
+    // and we no longer need to support sources present when prebuilts are used.
+    enabled: false,
+    soong_config_variables: {
+        source_build: {
+            enabled: true,
+        },
+    },
+
     host_supported: true,
     src: "art",
     filename_from_src: true,
@@ -57,6 +76,13 @@
         darwin: {
             enabled: false,
         },
+        windows: {
+            // When the module is enabled globally in the soong_config_variables
+            // stanza above, it gets enabled on windows too. Hence we need to
+            // disable it explicitly.
+            // TODO(b/172480617): Clean up with that.
+            enabled: false,
+        },
     },
 }
 
diff --git a/tools/ahat/Android.mk b/tools/ahat/Android.mk
index 014e24e..16f1712 100644
--- a/tools/ahat/Android.mk
+++ b/tools/ahat/Android.mk
@@ -22,7 +22,6 @@
 # doesn't run on darwin. Only build and run the tests for linux.
 # There are also issues with running under instrumentation.
 ifeq ($(HOST_OS),linux)
-ifeq (true,$(my_art_module_source_build))
 ifneq ($(EMMA_INSTRUMENT),true)
 
 # Determine the location of the test-dump.jar, test-dump.hprof, and proguard
@@ -123,7 +122,6 @@
 AHAT_TEST_JAR := $(LOCAL_BUILT_MODULE)
 
 endif # EMMA_INSTRUMENT
-endif # my_art_module_source_build
 endif # linux
 
 # Clean up local variables.
diff --git a/tools/cpp-define-generator/Android.bp b/tools/cpp-define-generator/Android.bp
index 5c9e4f9..a436430 100644
--- a/tools/cpp-define-generator/Android.bp
+++ b/tools/cpp-define-generator/Android.bp
@@ -55,9 +55,28 @@
     ],
 }
 
+soong_config_module_type_import {
+    from: "art/build/SoongConfig.bp",
+    module_types: [
+        "art_module_cc_genrule",
+    ],
+}
+
 // This extracts the compile-time constants from asm_defines.s and creates the header.
-cc_genrule {
+art_module_cc_genrule {
     name: "cpp-define-generator-asm-support",
+
+    // :asm_defines.s is only available when building ART from source, so do the
+    // same here.
+    // TODO(b/172480617): Clean up when sources are gone from the platform tree
+    // and we no longer need to support sources present when prebuilts are used.
+    enabled: false,
+    soong_config_variables: {
+        source_build: {
+            enabled: true,
+        },
+    },
+
     host_supported: true,
     device_supported: true,
     srcs: [":asm_defines.s"],
@@ -68,6 +87,13 @@
         darwin: {
             enabled: false,
         },
+        windows: {
+            // When the module is enabled globally in the soong_config_variables
+            // stanza above, it gets enabled on windows too. Hence we need to
+            // disable it explicitly.
+            // TODO(b/172480617): Clean up with that.
+            enabled: false,
+        },
     },
 
     apex_available: [
diff --git a/tools/dexfuzz/Android.mk b/tools/dexfuzz/Android.mk
index 6894841..929b687 100644
--- a/tools/dexfuzz/Android.mk
+++ b/tools/dexfuzz/Android.mk
@@ -19,10 +19,4 @@
 # --- dexfuzz script with core image dependencies ----------------
 .PHONY: fuzzer
 
-# We cannot depend on host core image files from prebuilts.
-# TODO(b/172480617): Remove this when ART sources are no longer in platform manifests.
-ifeq (true,$(SOONG_CONFIG_art_module_source_build))
-
 fuzzer: dexfuzz-script $(HOST_CORE_IMG_OUTS)
-
-endif
diff --git a/tools/veridex/Android.mk b/tools/veridex/Android.mk
index c510a51..a298af4 100644
--- a/tools/veridex/Android.mk
+++ b/tools/veridex/Android.mk
@@ -14,6 +14,8 @@
 # limitations under the License.
 #
 
+# TODO(b/172480617): Clean up the platform dependencies on this.
+
 LOCAL_PATH := $(call my-dir)
 
 # The veridex tool takes stub dex files as input, so we generate both the system and oahl