From 944e77d2191322dd76d4f62aa72458975b9ca2f3 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Wed, 19 Aug 2020 11:40:22 +0100 Subject: [PATCH] Change sdk_library child visibility semantics If specified, the more specific *_visibility attribute override the visibility attribute. This is a temporary solution local to java_sdk_library. Ideally this should be applied to all modules that create child modules. Bug: 165017290 Test: m Change-Id: Ia8c5ae119623a83d8ac583c602320915bb8c7f33 --- java/sdk_library.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/java/sdk_library.go b/java/sdk_library.go index a5db56c2b..d6c3ee486 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1086,11 +1086,25 @@ func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) stri return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest" } +func childModuleVisibility(childVisibility []string) []string { + if childVisibility == nil { + // No child visibility set. The child will use the visibility of the sdk_library. + return nil + } + + // Prepend an override to ignore the sdk_library's visibility, and rely on the child visibility. + var visibility []string + visibility = append(visibility, "//visibility:override") + visibility = append(visibility, childVisibility...) + return visibility +} + // Creates the implementation java library func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) { - moduleNamePtr := proptools.StringPtr(module.BaseModuleName()) + visibility := childModuleVisibility(module.sdkLibraryProperties.Impl_library_visibility) + props := struct { Name *string Visibility []string @@ -1098,7 +1112,7 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) ConfigurationName *string }{ Name: proptools.StringPtr(module.implLibraryModuleName()), - Visibility: module.sdkLibraryProperties.Impl_library_visibility, + Visibility: visibility, // Set the instrument property to ensure it is instrumented when instrumentation is required. Instrument: true, @@ -1145,12 +1159,7 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext }{} props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) - - // If stubs_library_visibility is not set then the created module will use the - // visibility of this module. - visibility := module.sdkLibraryProperties.Stubs_library_visibility - props.Visibility = visibility - + props.Visibility = childModuleVisibility(module.sdkLibraryProperties.Stubs_library_visibility) // sources are generated from the droiddoc props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)} sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) @@ -1225,12 +1234,7 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC // * libs (static_libs/libs) props.Name = proptools.StringPtr(name) - - // If stubs_source_visibility is not set then the created module will use the - // visibility of this module. - visibility := module.sdkLibraryProperties.Stubs_source_visibility - props.Visibility = visibility - + props.Visibility = childModuleVisibility(module.sdkLibraryProperties.Stubs_source_visibility) props.Srcs = append(props.Srcs, module.properties.Srcs...) props.Sdk_version = module.deviceProperties.Sdk_version props.System_modules = module.deviceProperties.System_modules