Remove the SdkLibraryDependency interface
Instead, provide the information of the source/prebuilt java_sdk_library
to the rdeps via the SdkLibraryInfoProvider.
Test: m nothing --no-skip-soong-tests && diff ninja file
Bug: 348040422
Change-Id: If6cd3cd260a8ce8dccead7f302840cabf68a9fae
diff --git a/java/app.go b/java/app.go
index 4ac42a7..7707a7e 100644
--- a/java/app.go
+++ b/java/app.go
@@ -1781,16 +1781,15 @@
}
}
- // Skip java_sdk_library dependencies that provide stubs, but not an implementation.
- // This will be restricted to optional_uses_libs
- if sdklib, ok := m.(SdkLibraryDependency); ok {
- if tag == usesLibOptTag && sdklib.DexJarBuildPath(ctx).PathOrNil() == nil {
- u.shouldDisableDexpreopt = true
- return
- }
- }
-
if lib, ok := m.(UsesLibraryDependency); ok {
+ if _, ok := android.OtherModuleProvider(ctx, m, SdkLibraryInfoProvider); ok {
+ // Skip java_sdk_library dependencies that provide stubs, but not an implementation.
+ // This will be restricted to optional_uses_libs
+ if tag == usesLibOptTag && lib.DexJarBuildPath(ctx).PathOrNil() == nil {
+ u.shouldDisableDexpreopt = true
+ return
+ }
+ }
libName := dep
if ulib, ok := m.(ProvidesUsesLib); ok && ulib.ProvidesUsesLib() != nil {
libName = *ulib.ProvidesUsesLib()
diff --git a/java/base.go b/java/base.go
index b64eb5b..df523b7 100644
--- a/java/base.go
+++ b/java/base.go
@@ -2414,10 +2414,9 @@
return
}
- if _, ok := module.(SdkLibraryDependency); ok {
+ if sdkInfo, ok := android.OtherModuleProvider(ctx, module, SdkLibraryInfoProvider); ok {
switch tag {
case sdkLibTag, libTag, staticLibTag:
- sdkInfo, _ := android.OtherModuleProvider(ctx, module, SdkLibraryInfoProvider)
generatingLibsString := android.PrettyConcat(
getGeneratingLibs(ctx, j.SdkVersion(ctx), module.Name(), sdkInfo), true, "or")
ctx.ModuleErrorf("cannot depend directly on java_sdk_library %q; try depending on %s instead", module.Name(), generatingLibsString)
@@ -2749,7 +2748,7 @@
if IsJniDepTag(tag) || tag == certificateTag || tag == proguardRaiseTag {
return RenameUseExclude, "tags"
}
- if _, ok := m.(SdkLibraryDependency); ok {
+ if _, ok := android.OtherModuleProvider(ctx, m, SdkLibraryInfoProvider); ok {
switch tag {
case sdkLibTag, libTag:
return RenameUseExclude, "sdklibdep" // matches collectDeps()
diff --git a/java/droiddoc.go b/java/droiddoc.go
index a7e92d9..2980d91 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -373,8 +373,7 @@
panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
}
case libTag, sdkLibTag:
- if _, ok := module.(SdkLibraryDependency); ok {
- sdkInfo, _ := android.OtherModuleProvider(ctx, module, SdkLibraryInfoProvider)
+ if sdkInfo, ok := android.OtherModuleProvider(ctx, module, SdkLibraryInfoProvider); ok {
generatingLibsString := android.PrettyConcat(
getGeneratingLibs(ctx, j.SdkVersion(ctx), module.Name(), sdkInfo), true, "or")
ctx.ModuleErrorf("cannot depend directly on java_sdk_library %q; try depending on %s instead", module.Name(), generatingLibsString)
diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go
index 4144de8..3650058 100644
--- a/java/hiddenapi_modular.go
+++ b/java/hiddenapi_modular.go
@@ -298,13 +298,12 @@
// available, or reports an error.
func hiddenAPIRetrieveDexJarBuildPath(ctx android.ModuleContext, module android.Module, kind android.SdkKind) android.Path {
var dexJar OptionalDexJarPath
- if sdkLibrary, ok := module.(SdkLibraryDependency); ok {
+ if sdkLibrary, ok := android.OtherModuleProvider(ctx, module, SdkLibraryInfoProvider); ok {
if ctx.Config().ReleaseHiddenApiExportableStubs() {
- dexJar = sdkLibrary.SdkApiExportableStubDexJar(ctx, kind)
+ dexJar = sdkLibrary.ExportableStubDexJarPaths[kind]
} else {
- dexJar = sdkLibrary.SdkApiStubDexJar(ctx, kind)
+ dexJar = sdkLibrary.EverythingStubDexJarPaths[kind]
}
-
} else if j, ok := module.(UsesLibraryDependency); ok {
dexJar = j.DexJarBuildPath(ctx)
} else {
@@ -853,15 +852,15 @@
i.StubDexJarsByScope.addStubDexJar(ctx, module, apiScope, dexJar)
}
- if sdkLibrary, ok := module.(SdkLibraryDependency); ok {
- removedTxtFile := sdkLibrary.SdkRemovedTxtFile(ctx, sdkKind)
+ if sdkLibrary, ok := android.OtherModuleProvider(ctx, module, SdkLibraryInfoProvider); ok {
+ removedTxtFile := sdkLibrary.RemovedTxtFiles[sdkKind]
i.RemovedTxtFiles = append(i.RemovedTxtFiles, removedTxtFile.AsPaths()...)
}
}
// If the contents includes any java_sdk_library modules then add them to the stubs.
for _, module := range contents {
- if _, ok := module.(SdkLibraryDependency); ok {
+ if _, ok := android.OtherModuleProvider(ctx, module, SdkLibraryInfoProvider); ok {
// Add information for every possible API scope needed by hidden API.
for _, apiScope := range hiddenAPISdkLibrarySupportedScopes {
addFromModule(ctx, module, apiScope)
diff --git a/java/java.go b/java/java.go
index 91c4d6d..7ccf91c 100644
--- a/java/java.go
+++ b/java/java.go
@@ -2700,7 +2700,7 @@
transitiveBootClasspathHeaderJars = append(transitiveBootClasspathHeaderJars, dep.TransitiveStaticLibsHeaderJars)
}
}
- } else if _, ok := module.(SdkLibraryDependency); ok {
+ } else if _, ok := android.OtherModuleProvider(ctx, module, SdkLibraryInfoProvider); ok {
switch tag {
case libTag, sdkLibTag:
sdkInfo, _ := android.OtherModuleProvider(ctx, module, SdkLibraryInfoProvider)
@@ -3315,7 +3315,7 @@
depName := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(depModule))
var sdkLib *string
- if lib, ok := depModule.(SdkLibraryDependency); ok && lib.sharedLibrary() {
+ if lib, ok := android.OtherModuleProvider(ctx, depModule, SdkLibraryInfoProvider); ok && lib.SharedLibrary {
// A shared SDK library. This should be added as a top-level CLC element.
sdkLib = &depName
} else if lib, ok := depModule.(SdkLibraryComponentDependency); ok && lib.OptionalSdkLibraryImplementation() != nil {
diff --git a/java/sdk_library.go b/java/sdk_library.go
index c2b1c4f..8a4f1f8 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -922,7 +922,7 @@
c.initSdkLibraryComponent(module)
}
-func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android.DefaultableHookContext) bool {
+func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied() bool {
namePtr := proptools.StringPtr(c.module.RootLibraryName())
c.sdkLibraryComponentProperties.SdkLibraryName = namePtr
@@ -944,12 +944,32 @@
return c.sharedLibrary()
}
-func (c *commonToSdkLibraryAndImport) generateCommonBuildActions(ctx android.ModuleContext) {
+func (c *commonToSdkLibraryAndImport) generateCommonBuildActions(ctx android.ModuleContext) SdkLibraryInfo {
c.doctagPaths = android.PathsForModuleSrc(ctx, c.commonSdkLibraryProperties.Doctag_files)
-}
-func (c *commonToSdkLibraryAndImport) getImplLibraryModule() *Library {
- return c.implLibraryModule
+ everythingStubPaths := make(map[android.SdkKind]OptionalDexJarPath)
+ exportableStubPaths := make(map[android.SdkKind]OptionalDexJarPath)
+ removedApiFilePaths := make(map[android.SdkKind]android.OptionalPath)
+ for kind := android.SdkNone; kind <= android.SdkPrivate; kind += 1 {
+ everythingStubPath := makeUnsetDexJarPath()
+ exportableStubPath := makeUnsetDexJarPath()
+ removedApiFilePath := android.OptionalPath{}
+ if scopePath := c.findClosestScopePath(sdkKindToApiScope(kind)); scopePath != nil {
+ everythingStubPath = scopePath.stubsDexJarPath
+ exportableStubPath = scopePath.exportableStubsDexJarPath
+ removedApiFilePath = scopePath.removedApiFilePath
+ }
+ everythingStubPaths[kind] = everythingStubPath
+ exportableStubPaths[kind] = exportableStubPath
+ removedApiFilePaths[kind] = removedApiFilePath
+ }
+
+ return SdkLibraryInfo{
+ EverythingStubDexJarPaths: everythingStubPaths,
+ ExportableStubDexJarPaths: exportableStubPaths,
+ RemovedTxtFiles: removedApiFilePaths,
+ SharedLibrary: c.sharedLibrary(),
+ }
}
// The component names for different outputs of the java_sdk_library.
@@ -1023,29 +1043,6 @@
return nil
}
-// selectScopePaths returns the *scopePaths appropriate for the specific kind.
-//
-// If the module does not support the specific kind then it will return the *scopePaths for the
-// closest kind which is a subset of the requested kind. e.g. if requesting android.SdkModule then
-// it will return *scopePaths for android.SdkSystem if available or android.SdkPublic of not.
-func (c *commonToSdkLibraryAndImport) selectScopePaths(ctx android.BaseModuleContext, kind android.SdkKind) *scopePaths {
- apiScope := sdkKindToApiScope(kind)
-
- paths := c.findClosestScopePath(apiScope)
- if paths == nil {
- var scopes []string
- for _, s := range AllApiScopes {
- if c.findScopePaths(s) != nil {
- scopes = append(scopes, s.name)
- }
- }
- ctx.ModuleErrorf("requires api scope %s from %s but it only has %q available", apiScope.name, c.module.RootLibraryName(), scopes)
- return nil
- }
-
- return paths
-}
-
// sdkKindToApiScope maps from android.SdkKind to apiScope.
func sdkKindToApiScope(kind android.SdkKind) *apiScope {
var apiScope *apiScope
@@ -1064,37 +1061,6 @@
return apiScope
}
-// to satisfy SdkLibraryDependency interface
-func (c *commonToSdkLibraryAndImport) SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath {
- paths := c.selectScopePaths(ctx, kind)
- if paths == nil {
- return makeUnsetDexJarPath()
- }
-
- return paths.stubsDexJarPath
-}
-
-// to satisfy SdkLibraryDependency interface
-func (c *commonToSdkLibraryAndImport) SdkApiExportableStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath {
- paths := c.selectScopePaths(ctx, kind)
- if paths == nil {
- return makeUnsetDexJarPath()
- }
-
- return paths.exportableStubsDexJarPath
-}
-
-// to satisfy SdkLibraryDependency interface
-func (c *commonToSdkLibraryAndImport) SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath {
- apiScope := sdkKindToApiScope(kind)
- paths := c.findScopePaths(apiScope)
- if paths == nil {
- return android.OptionalPath{}
- }
-
- return paths.removedApiFilePath
-}
-
func (c *commonToSdkLibraryAndImport) sdkComponentPropertiesForChildLibrary() interface{} {
componentProps := &struct {
SdkLibraryName *string
@@ -1185,36 +1151,25 @@
var _ SdkLibraryComponentDependency = (*SdkLibrary)(nil)
var _ SdkLibraryComponentDependency = (*SdkLibraryImport)(nil)
-// Provides access to sdk_version related files, e.g. header and implementation jars.
-type SdkLibraryDependency interface {
- SdkLibraryComponentDependency
-
- // SdkApiStubDexJar returns the dex jar for the stubs for the prebuilt
- // java_sdk_library_import module. It is needed by the hiddenapi processing tool which
- // processes dex files.
- SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath
-
- // SdkApiExportableStubDexJar returns the exportable dex jar for the stubs for
- // java_sdk_library module. It is needed by the hiddenapi processing tool which processes
- // dex files.
- SdkApiExportableStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath
-
- // SdkRemovedTxtFile returns the optional path to the removed.txt file for the specified sdk kind.
- SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath
-
- // sharedLibrary returns true if this can be used as a shared library.
- sharedLibrary() bool
-
- // getImplLibraryModule returns the pointer to the implementation library submodule of this
- // sdk library.
- getImplLibraryModule() *Library
-}
-
type SdkLibraryInfo struct {
// GeneratingLibs is the names of the library modules that this sdk library
// generates. Note that this only includes the name of the modules that other modules can
// depend on, and is not a holistic list of generated modules.
GeneratingLibs []string
+
+ // Map of sdk kind to the dex jar for the "everything" stubs.
+ // It is needed by the hiddenapi processing tool which processes dex files.
+ EverythingStubDexJarPaths map[android.SdkKind]OptionalDexJarPath
+
+ // Map of sdk kind to the dex jar for the "exportable" stubs.
+ // It is needed by the hiddenapi processing tool which processes dex files.
+ ExportableStubDexJarPaths map[android.SdkKind]OptionalDexJarPath
+
+ // Map of sdk kind to the optional path to the removed.txt file.
+ RemovedTxtFiles map[android.SdkKind]android.OptionalPath
+
+ // Whether if this can be used as a shared library.
+ SharedLibrary bool
}
var SdkLibraryInfoProvider = blueprint.NewProvider[SdkLibraryInfo]()
@@ -1248,12 +1203,13 @@
builtInstalledForApex []dexpreopterInstall
}
-var _ SdkLibraryDependency = (*SdkLibrary)(nil)
-
func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool {
return module.sdkLibraryProperties.Generate_system_and_test_apis
}
+var _ UsesLibraryDependency = (*SdkLibrary)(nil)
+
+// To satisfy the UsesLibraryDependency interface
func (module *SdkLibrary) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath {
if module.implLibraryModule != nil {
return module.implLibraryModule.DexJarBuildPath(ctx)
@@ -1261,6 +1217,7 @@
return makeUnsetDexJarPath()
}
+// To satisfy the UsesLibraryDependency interface
func (module *SdkLibrary) DexJarInstallPath() android.Path {
if module.implLibraryModule != nil {
return module.implLibraryModule.DexJarInstallPath()
@@ -1448,8 +1405,6 @@
module.HideFromMake()
}
- module.generateCommonBuildActions(ctx)
-
module.stem = proptools.StringDefault(module.overridableProperties.Stem, ctx.ModuleName())
module.provideHiddenAPIPropertyInfo(ctx)
@@ -1487,6 +1442,7 @@
}
})
+ sdkLibInfo := module.generateCommonBuildActions(ctx)
apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
if !apexInfo.IsForPlatform() {
module.hideApexVariantFromMake = true
@@ -1570,9 +1526,8 @@
setOutputFiles(ctx, module.implLibraryModule.Module)
}
- android.SetProvider(ctx, SdkLibraryInfoProvider, SdkLibraryInfo{
- GeneratingLibs: generatingLibs,
- })
+ sdkLibInfo.GeneratingLibs = generatingLibs
+ android.SetProvider(ctx, SdkLibraryInfoProvider, sdkLibInfo)
}
func (module *SdkLibrary) BuiltInstalledForApex() []dexpreopterInstall {
@@ -1883,7 +1838,7 @@
module.commonSdkLibraryProperties.Shared_library = proptools.BoolPtr(false)
}
- if module.initCommonAfterDefaultsApplied(ctx) {
+ if module.initCommonAfterDefaultsApplied() {
module.CreateInternalModules(ctx)
}
})
@@ -1962,8 +1917,6 @@
installFile android.Path
}
-var _ SdkLibraryDependency = (*SdkLibraryImport)(nil)
-
// The type of a structure that contains a field of type sdkLibraryScopeProperties
// for each apiscope in allApiScopes, e.g. something like:
//
@@ -2019,7 +1972,7 @@
InitJavaModule(module, android.HostAndDeviceSupported)
module.SetDefaultableHook(func(mctx android.DefaultableHookContext) {
- if module.initCommonAfterDefaultsApplied(mctx) {
+ if module.initCommonAfterDefaultsApplied() {
module.createInternalModules(mctx)
}
})
@@ -2140,8 +2093,6 @@
var _ hiddenAPIModule = (*SdkLibraryImport)(nil)
func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- module.generateCommonBuildActions(ctx)
-
// Assume that source module(sdk_library) is installed in /<sdk_library partition>/framework
module.installFile = android.PathForModuleInstall(ctx, "framework", module.Stem()+".jar")
@@ -2171,6 +2122,7 @@
}
}
})
+ sdkLibInfo := module.generateCommonBuildActions(ctx)
// Populate the scope paths with information from the properties.
for apiScope, scopeProperties := range module.scopeProperties {
@@ -2212,11 +2164,12 @@
setOutputFiles(ctx, module.implLibraryModule.Module)
}
- android.SetProvider(ctx, SdkLibraryInfoProvider, SdkLibraryInfo{
- GeneratingLibs: generatingLibs,
- })
+ sdkLibInfo.GeneratingLibs = generatingLibs
+ android.SetProvider(ctx, SdkLibraryInfoProvider, sdkLibInfo)
}
+var _ UsesLibraryDependency = (*SdkLibraryImport)(nil)
+
// to satisfy UsesLibraryDependency interface
func (module *SdkLibraryImport) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath {
// The dex implementation jar extracted from the .apex file should be used in preference to the
@@ -2462,7 +2415,7 @@
s.Min_device_sdk = sdk.commonSdkLibraryProperties.Min_device_sdk
s.Max_device_sdk = sdk.commonSdkLibraryProperties.Max_device_sdk
- implLibrary := sdk.getImplLibraryModule()
+ implLibrary := sdk.implLibraryModule
if implLibrary != nil && implLibrary.dexpreopter.dexpreoptProperties.Dex_preopt_result.Profile_guided {
s.DexPreoptProfileGuided = proptools.BoolPtr(true)
}