Generalize the defaults module for module source builds.

It is useful in other places, as a Soong counterpart to
my_art_module_source_build in Android.common_path.mk.

Test: m nothing
Bug: 172480615
Change-Id: I9c02006148c3958b2c3af0ce0e0ea172a8c1e4cd
diff --git a/build/Android.bp b/build/Android.bp
index 6b79b58..1caf620 100644
--- a/build/Android.bp
+++ b/build/Android.bp
@@ -286,6 +286,36 @@
     },
 }
 
+soong_config_module_type_import {
+    from: "art/build/SoongConfig.bp",
+    module_types: ["art_module_cc_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.
+art_module_cc_defaults {
+    name: "art_module_source_build_defaults",
+    defaults_visibility: [
+        "//art:__subpackages__",
+        "//libnativehelper:__subpackages__",
+    ],
+
+    enabled: false,
+    soong_config_variables: {
+        source_build: {
+            enabled: true,
+        },
+    },
+    target: {
+        windows: {
+            // Windows is disabled by default, but if we set enabled:true
+            // globally above we need to disable it explicitly.
+            enabled: false,
+        },
+    },
+}
+
 // A version of conscrypt only for enabling the "-hostdex" version to test ART on host.
 java_library {
     // We need our own name to not clash with the conscrypt library.
diff --git a/test/Android.bp b/test/Android.bp
index 4ddecd4..fd6c3b4 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -1006,26 +1006,13 @@
     sdk_version: "core_current",
 }
 
-soong_config_module_type_import {
-    from: "art/build/SoongConfig.bp",
-    module_types: ["art_module_cc_defaults"],
-}
-
-art_module_cc_defaults {
-    name: "art_gtests_defaults",
-
-    // Enable gtests only in source builds, where com.android.art.testing is available.
-    enabled: false,
-    soong_config_variables: {
-        source_build: {
-            enabled: true,
-        },
-    },
-}
-
 art_cc_test {
     name: "ArtGtestsTargetInstallApex",
-    defaults: ["art_gtests_defaults"],
+    defaults: [
+        // Enable only in source builds, where com.android.art.testing is
+        // available.
+        "art_module_source_build_defaults",
+    ],
     data: [
         // We need the ART testing apex, which contains all gtest binaries.
         // Note that due to build system and linker constraints the gtests must be in the apex.
@@ -1054,7 +1041,11 @@
 
 art_cc_test {
     name: "ArtGtestsTargetChroot",
-    defaults: ["art_gtests_defaults"],
+    defaults: [
+        // Enable only in source builds, where com.android.art.testing is
+        // available.
+        "art_module_source_build_defaults",
+    ],
     data: [
         // We need the ART testing apex, which contains all gtest binaries.
         // Note that due to build system and linker constraints the gtests must be in the apex.