Merge "Change sdk_library child visibility semantics" am: 3652018b83

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1416192

Change-Id: I6d013916d33618dab06447fbfd7ee0d9e2d09d7a
This commit is contained in:
Anton Hansson 2020-09-02 15:56:58 +00:00 committed by Automerger Merge Worker
commit 847ca7514e

View file

@ -1089,11 +1089,25 @@ func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) stri
return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest" 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 // Creates the implementation java library
func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) { func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) {
moduleNamePtr := proptools.StringPtr(module.BaseModuleName()) moduleNamePtr := proptools.StringPtr(module.BaseModuleName())
visibility := childModuleVisibility(module.sdkLibraryProperties.Impl_library_visibility)
props := struct { props := struct {
Name *string Name *string
Visibility []string Visibility []string
@ -1101,7 +1115,7 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext)
ConfigurationName *string ConfigurationName *string
}{ }{
Name: proptools.StringPtr(module.implLibraryModuleName()), 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. // Set the instrument property to ensure it is instrumented when instrumentation is required.
Instrument: true, Instrument: true,
@ -1148,12 +1162,7 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext
}{} }{}
props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope))
props.Visibility = childModuleVisibility(module.sdkLibraryProperties.Stubs_library_visibility)
// 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
// sources are generated from the droiddoc // sources are generated from the droiddoc
props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)} props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)}
sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope)
@ -1234,12 +1243,7 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC
// * libs (static_libs/libs) // * libs (static_libs/libs)
props.Name = proptools.StringPtr(name) props.Name = proptools.StringPtr(name)
props.Visibility = childModuleVisibility(module.sdkLibraryProperties.Stubs_source_visibility)
// 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.Srcs = append(props.Srcs, module.properties.Srcs...) props.Srcs = append(props.Srcs, module.properties.Srcs...)
props.Sdk_version = module.deviceProperties.Sdk_version props.Sdk_version = module.deviceProperties.Sdk_version
props.System_modules = module.deviceProperties.System_modules props.System_modules = module.deviceProperties.System_modules