Use prebuilt_visibility property on sdk/module_exports

When the ART sdk/module_exports snapshots are unpacked in a prebuilts
directory they need some additional visibility rules to be added to
ensure that the prebuilts are visible to each other. Previously, those
were added on a case by case basis to the individual modules. This
change replaces them by using the prebuilt_visibility property that
specifies additional visibility rules to be added to all prebuilt
modules in the snapshots.

Currently, the additional visibility added to the prebuilts makes them
visible to anything in //prebuilts or beneath which is not restrictive
enough. Specifying the rule in a single place will make that easier to
restrict in future.

Bug: 155921753
Bug: 168301990
Test: build sdk/snapshot, install them in prebuilts/module_sdk/art
      and run m nothing to ensure the visibility rules are valid.
Change-Id: I751ed6d488038214ac9df35849babe69a3c79a31
diff --git a/build/sdk/Android.bp b/build/sdk/Android.bp
index 3766ad4..c15df7d 100644
--- a/build/sdk/Android.bp
+++ b/build/sdk/Android.bp
@@ -12,10 +12,22 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// Additional visibility to add to the prebuilt modules that are part of
+// the snapshots of the ART sdk/module_exports to ensure that they are
+// visible to each other.
+prebuilt_visibility = [
+    // TODO(b/155921753): Restrict this when prebuilts are in their proper
+    // locations.
+    "//prebuilts:__subpackages__",
+]
+
 // The SDK for the art module apex.
 sdk {
     name: "art-module-sdk",
     host_supported: true,
+
+    prebuilt_visibility: prebuilt_visibility,
+
     native_header_libs: [
         "jni_headers",
         "libnativehelper_header_only",
@@ -73,6 +85,9 @@
     name: "art-module-host-exports",
     host_supported: true,
     device_supported: false,
+
+    prebuilt_visibility: prebuilt_visibility,
+
     target: {
         host: {
             // Set in target.host because the top level compile_multilib
@@ -107,6 +122,9 @@
 module_exports {
     name: "art-module-test-exports",
     host_supported: true,
+
+    prebuilt_visibility: prebuilt_visibility,
+
     java_libs: [
         // The following bouncycastle modules are required by:
         // * conscrypt-benchmarks (all)
diff --git a/compiler/Android.bp b/compiler/Android.bp
index 3ec2a38..ffe5133 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -22,12 +22,6 @@
 art_cc_defaults {
     name: "libart-compiler-defaults",
     defaults: ["art_defaults"],
-    visibility: [
-        // Visibility for prebuilt binaries from the prebuilt of this module.
-        // TODO(b/155921753): Restrict this when prebuilts are in their proper
-        // locations.
-        "//prebuilts:__subpackages__",
-    ],
     host_supported: true,
     srcs: [
         "compiled_method.cc",
diff --git a/dexlayout/Android.bp b/dexlayout/Android.bp
index 07ee8f9..04068e1 100644
--- a/dexlayout/Android.bp
+++ b/dexlayout/Android.bp
@@ -15,12 +15,6 @@
 art_cc_defaults {
     name: "libart-dexlayout-defaults",
     defaults: ["art_defaults"],
-    visibility: [
-        // Visibility for prebuilt binaries from the prebuilt of this module.
-        // TODO(b/155921753): Restrict this when prebuilts are in their proper
-        // locations.
-        "//prebuilts:__subpackages__",
-    ],
     host_supported: true,
     srcs: [
         "compact_dex_writer.cc",
diff --git a/libartbase/Android.bp b/libartbase/Android.bp
index e3ae6dd..f2a15a4 100644
--- a/libartbase/Android.bp
+++ b/libartbase/Android.bp
@@ -17,12 +17,6 @@
 cc_defaults {
     name: "libartbase_defaults",
     defaults: ["art_defaults"],
-    visibility: [
-        // Visibility for prebuilt binaries from the prebuilt of this module.
-        // TODO(b/155921753): Restrict this when prebuilts are in their proper
-        // locations.
-        "//prebuilts:__subpackages__",
-    ],
     host_supported: true,
     srcs: [
         "arch/instruction_set.cc",
diff --git a/libartpalette/Android.bp b/libartpalette/Android.bp
index 1ccc5e4..1cdc270 100644
--- a/libartpalette/Android.bp
+++ b/libartpalette/Android.bp
@@ -17,12 +17,6 @@
 cc_defaults {
     name: "libartpalette_defaults",
     defaults: ["art_defaults"],
-    visibility: [
-        // Visibility for prebuilt binaries from the prebuilt of this module.
-        // TODO(b/155921753): Restrict this when prebuilts are in their proper
-        // locations.
-        "//prebuilts:__subpackages__",
-    ],
     host_supported: true,
     export_include_dirs: ["include"],
 }
diff --git a/libdexfile/Android.bp b/libdexfile/Android.bp
index c80dc4d..c08a244 100644
--- a/libdexfile/Android.bp
+++ b/libdexfile/Android.bp
@@ -17,12 +17,6 @@
 cc_defaults {
     name: "libdexfile_defaults",
     defaults: ["art_defaults"],
-    visibility: [
-        // Visibility for prebuilt dex2oat(d) from the prebuilt of this module.
-        // TODO(b/155921753): Restrict this when prebuilts are in their proper
-        // locations.
-        "//prebuilts:__subpackages__",
-    ],
     host_supported: true,
     srcs: [
         "dex/art_dex_file_loader.cc",
diff --git a/libprofile/Android.bp b/libprofile/Android.bp
index aaf1a69..d210afa 100644
--- a/libprofile/Android.bp
+++ b/libprofile/Android.bp
@@ -17,12 +17,6 @@
 cc_defaults {
     name: "libprofile_defaults",
     defaults: ["art_defaults"],
-    visibility: [
-        // Visibility for prebuilt binaries from the prebuilt of this module.
-        // TODO(b/155921753): Restrict this when prebuilts are in their proper
-        // locations.
-        "//prebuilts:__subpackages__",
-    ],
     host_supported: true,
     srcs: [
         "profile/profile_boot_info.cc",
diff --git a/runtime/Android.bp b/runtime/Android.bp
index a0f0c09..1f8e857e 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -60,12 +60,6 @@
 libart_cc_defaults {
     name: "libart_defaults",
     defaults: ["art_defaults"],
-    visibility: [
-        // Visibility for prebuilt binaries from the prebuilt of this module.
-        // TODO(b/155921753): Restrict this when prebuilts are in their proper
-        // locations.
-        "//prebuilts:__subpackages__",
-    ],
     host_supported: true,
     srcs: [
         "aot_class_linker.cc",
diff --git a/sigchainlib/Android.bp b/sigchainlib/Android.bp
index e42bb8e..3fb21b9 100644
--- a/sigchainlib/Android.bp
+++ b/sigchainlib/Android.bp
@@ -18,10 +18,6 @@
     name: "libsigchain",
     defaults: ["art_defaults"],
     visibility: [
-        // Visibility for prebuilt binaries from the prebuilt of this module.
-        // TODO(b/155921753): Restrict this when prebuilts are in their proper
-        // locations.
-        "//prebuilts:__subpackages__",
         // TODO(b/142944043, b/133140750): Clean this up.
         "//frameworks/base/cmds/app_process",
     ],