Copy exportable artifacts to module sdk snapshot

This change modifies the copy rules of the sdk_library when generating
the module sdk snapshots so that the exportable artifacts (annotations
zip, api file, removed api file, srcjar file) are copied instead of the
everything artifacts.

In order to satisfy the prebuilts compatibility, this feature is flag
guarded by the build flag "RELEASE_HIDDEN_API_EXPORTABLE_STUBS"

Test: m --no-skip-soong-tests
Bug: 315027929
Change-Id: I8bf5bb1f196aa9b5db78ba4677caa5f4337e3021
This commit is contained in:
Jihoon Kang
2024-01-08 08:56:20 +00:00
parent bd093457e2
commit f55a5f7b37
5 changed files with 167 additions and 97 deletions

View File

@@ -727,7 +727,9 @@ func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.Modul
func (paths *scopePaths) extractEverythingStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error {
if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok {
paths.stubsHeaderPath = lib.HeaderJars
paths.stubsImplPath = lib.ImplementationJars
if !ctx.Config().ReleaseHiddenApiExportableStubs() {
paths.stubsImplPath = lib.ImplementationJars
}
libDep := dep.(UsesLibraryDependency)
paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx)
@@ -738,7 +740,11 @@ func (paths *scopePaths) extractEverythingStubsLibraryInfoFromDependency(ctx and
}
func (paths *scopePaths) extractExportableStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error {
if _, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok {
if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok {
if ctx.Config().ReleaseHiddenApiExportableStubs() {
paths.stubsImplPath = lib.ImplementationJars
}
libDep := dep.(UsesLibraryDependency)
paths.exportableStubsDexJarPath = libDep.DexJarBuildPath(ctx)
return nil
@@ -756,6 +762,15 @@ func (paths *scopePaths) treatDepAsApiStubsProvider(dep android.Module, action f
}
}
func (paths *scopePaths) treatDepAsExportableApiStubsProvider(dep android.Module, action func(provider ExportableApiStubsProvider)) error {
if exportableApiStubsProvider, ok := dep.(ExportableApiStubsProvider); ok {
action(exportableApiStubsProvider)
return nil
} else {
return fmt.Errorf("expected module that implements ExportableApiStubsSrcProvider, e.g. droidstubs")
}
}
func (paths *scopePaths) treatDepAsApiStubsSrcProvider(dep android.Module, action func(provider ApiStubsSrcProvider)) error {
if apiStubsProvider, ok := dep.(ApiStubsSrcProvider); ok {
action(apiStubsProvider)
@@ -771,6 +786,12 @@ func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsPro
paths.removedApiFilePath = android.OptionalPathForPath(provider.RemovedApiFilePath())
}
func (paths *scopePaths) extractApiInfoFromExportableApiStubsProvider(provider ExportableApiStubsProvider) {
paths.annotationsZip = android.OptionalPathForPath(provider.ExportableAnnotationsZip())
paths.currentApiFilePath = android.OptionalPathForPath(provider.ExportableApiFilePath())
paths.removedApiFilePath = android.OptionalPathForPath(provider.ExportableRemovedApiFilePath())
}
func (paths *scopePaths) extractApiInfoFromDep(ctx android.ModuleContext, dep android.Module) error {
return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
paths.extractApiInfoFromApiStubsProvider(provider)
@@ -781,6 +802,10 @@ func (paths *scopePaths) extractStubsSourceInfoFromApiStubsProviders(provider Ap
paths.stubsSrcJar = android.OptionalPathForPath(provider.StubsSrcJar())
}
func (paths *scopePaths) extractStubsSourceInfoFromExportableApiStubsProviders(provider ExportableApiStubsSrcProvider) {
paths.stubsSrcJar = android.OptionalPathForPath(provider.ExportableStubsSrcJar())
}
func (paths *scopePaths) extractStubsSourceInfoFromDep(ctx android.ModuleContext, dep android.Module) error {
return paths.treatDepAsApiStubsSrcProvider(dep, func(provider ApiStubsSrcProvider) {
paths.extractStubsSourceInfoFromApiStubsProviders(provider)
@@ -788,6 +813,12 @@ func (paths *scopePaths) extractStubsSourceInfoFromDep(ctx android.ModuleContext
}
func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(ctx android.ModuleContext, dep android.Module) error {
if ctx.Config().ReleaseHiddenApiExportableStubs() {
return paths.treatDepAsExportableApiStubsProvider(dep, func(provider ExportableApiStubsProvider) {
paths.extractApiInfoFromExportableApiStubsProvider(provider)
paths.extractStubsSourceInfoFromExportableApiStubsProviders(provider)
})
}
return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) {
paths.extractApiInfoFromApiStubsProvider(provider)
paths.extractStubsSourceInfoFromApiStubsProviders(provider)