From 2c20726d44708bdb739f4cd67e0d20332315fc8e Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Fri, 30 Aug 2024 18:56:39 +0000 Subject: [PATCH] Change visibility of module sdk prebuilts to //visibility:public To reduce pains introduced by visiblity skew between source and prebuilts, mark them with //visibility:public Bug: 239189932 Test: go test ./sdk Change-Id: I47dd63bd03337bc9ec6fa364bbdcdfdfcd70b0d9 --- sdk/sdk_test.go | 39 +++------------------------------------ sdk/update.go | 30 ++++++++++++++++-------------- 2 files changed, 19 insertions(+), 50 deletions(-) diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 057b370d3..416dce62c 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -131,11 +131,7 @@ apex_contributions_defaults { java_import { name: "myjavalib", prefer: false, - visibility: [ - "//other/foo", - "//package", - "//prebuilts/mysdk", - ], + visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], jars: ["java/myjavalib.jar"], } @@ -151,11 +147,7 @@ java_import { java_import { name: "mydefaultedjavalib", prefer: false, - visibility: [ - "//other/bar", - "//package", - "//prebuilts/mysdk", - ], + visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], jars: ["java/mydefaultedjavalib.jar"], } @@ -163,10 +155,7 @@ java_import { java_import { name: "myprivatejavalib", prefer: false, - visibility: [ - "//package", - "//prebuilts/mysdk", - ], + visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], jars: ["java/myprivatejavalib.jar"], } @@ -185,28 +174,6 @@ func TestPrebuiltVisibilityProperty_IsValidated(t *testing.T) { `) } -func TestPrebuiltVisibilityProperty_AddPrivate(t *testing.T) { - testSdkError(t, `prebuilt_visibility: "//visibility:private" does not widen the visibility`, ` - sdk { - name: "mysdk", - prebuilt_visibility: [ - "//visibility:private", - ], - java_header_libs: [ - "myjavalib", - ], - } - - java_library { - name: "myjavalib", - // Uses package default visibility - srcs: ["Test.java"], - system_modules: "none", - sdk_version: "none", - } -`) -} - func TestSdkInstall(t *testing.T) { sdk := ` sdk { diff --git a/sdk/update.go b/sdk/update.go index a4b1967af..2a054e7d7 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -1109,20 +1109,22 @@ func (s *snapshotBuilder) AddPrebuiltModule(member android.SdkMember, moduleType // same package so can be marked as private. m.AddProperty("visibility", []string{"//visibility:private"}) } else { - // Extract visibility information from a member variant. All variants have the same - // visibility so it doesn't matter which one is used. - visibilityRules := android.EffectiveVisibilityRules(s.ctx, variant) - - // Add any additional visibility rules needed for the prebuilts to reference each other. - err := visibilityRules.Widen(s.sdk.properties.Prebuilt_visibility) - if err != nil { - s.ctx.PropertyErrorf("prebuilt_visibility", "%s", err) - } - - visibility := visibilityRules.Strings() - if len(visibility) != 0 { - m.AddProperty("visibility", visibility) - } + // Change the visibility of the module SDK prebuilts to public. + // This includes + // 1. Stub libraries of `sdk` modules + // 2. Binaries and libraries of `module_exports` modules + // + // This is a workaround to improve maintainlibility of the module SDK. + // Since module sdks are generated from release branches and dropped to development + // branches, there might be a visibility skew between the sources and prebuilts + // of a specific module. + // To reconcile this potential skew, change the visibility to public + // + // This is safe for (1) since these are stub libraries. + // This is ok for (2) since these are host and test exports and are intended for + // ART development. + // TODO (b/361303067): This can be removed if ART uses full manifests. + m.AddProperty("visibility", []string{"//visibility:public"}) } // Where available copy apex_available properties from the member.