diff options
author | 2024-09-25 23:42:30 +0000 | |
---|---|---|
committer | 2024-09-26 17:49:18 +0000 | |
commit | 98e9ac6075d23ac9e06e87bf881bebccbef4505c (patch) | |
tree | 56d552843c626db25d4bd75e4f2cb28cfd0cc579 /java | |
parent | 1c4625a5ec6f6726ca44962947e6e353077c05de (diff) |
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
Diffstat (limited to 'java')
-rw-r--r-- | java/app.go | 17 | ||||
-rw-r--r-- | java/base.go | 5 | ||||
-rw-r--r-- | java/droiddoc.go | 3 | ||||
-rw-r--r-- | java/hiddenapi_modular.go | 13 | ||||
-rw-r--r-- | java/java.go | 4 | ||||
-rw-r--r-- | java/sdk_library.go | 155 |
6 files changed, 73 insertions, 124 deletions
diff --git a/java/app.go b/java/app.go index 4ac42a750..7707a7e76 100644 --- a/java/app.go +++ b/java/app.go @@ -1781,16 +1781,15 @@ func (u *usesLibrary) classLoaderContextForUsesLibDeps(ctx android.ModuleContext } } - // 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 b64eb5b61..df523b7e3 100644 --- a/java/base.go +++ b/java/base.go @@ -2414,10 +2414,9 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { 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 @@ func collectDirectDepsProviders(ctx android.ModuleContext) (result *JarJarProvid 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 a7e92d9ef..2980d91de 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -373,8 +373,7 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { 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 4144de82b..365005835 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -298,13 +298,12 @@ func hiddenAPIAddStubLibDependencies(ctx android.BottomUpMutatorContext, apiScop // 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 @@ func (i *HiddenAPIFlagInput) gatherStubLibInfo(ctx android.ModuleContext, conten 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 91c4d6dfc..7ccf91c8d 100644 --- a/java/java.go +++ b/java/java.go @@ -2700,7 +2700,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { 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 @@ func addCLCFromDep(ctx android.ModuleContext, depModule android.Module, 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 c2b1c4f31..8a4f1f85e 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -922,7 +922,7 @@ func (c *commonToSdkLibraryAndImport) initCommon(module commonSdkLibraryAndImpor 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 @@ func (c *commonToSdkLibraryAndImport) uniqueApexVariations() bool { 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 @@ func (c *commonToSdkLibraryAndImport) findClosestScopePath(scope *apiScope) *sco 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 @@ func sdkKindToApiScope(kind android.SdkKind) *apiScope { 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 = (*Import)(nil) 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 @@ type SdkLibrary struct { 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 @@ func (module *SdkLibrary) DexJarBuildPath(ctx android.ModuleErrorfContext) Optio 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 @@ func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) module.HideFromMake() } - module.generateCommonBuildActions(ctx) - module.stem = proptools.StringDefault(module.overridableProperties.Stem, ctx.ModuleName()) module.provideHiddenAPIPropertyInfo(ctx) @@ -1487,6 +1442,7 @@ func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) } }) + sdkLibInfo := module.generateCommonBuildActions(ctx) apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) if !apexInfo.IsForPlatform() { module.hideApexVariantFromMake = true @@ -1570,9 +1526,8 @@ func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) 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 @@ func SdkLibraryFactory() android.Module { module.commonSdkLibraryProperties.Shared_library = proptools.BoolPtr(false) } - if module.initCommonAfterDefaultsApplied(ctx) { + if module.initCommonAfterDefaultsApplied() { module.CreateInternalModules(ctx) } }) @@ -1962,8 +1917,6 @@ type SdkLibraryImport struct { 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 @@ func sdkLibraryImportFactory() android.Module { InitJavaModule(module, android.HostAndDeviceSupported) module.SetDefaultableHook(func(mctx android.DefaultableHookContext) { - if module.initCommonAfterDefaultsApplied(mctx) { + if module.initCommonAfterDefaultsApplied() { module.createInternalModules(mctx) } }) @@ -2140,8 +2093,6 @@ func (module *SdkLibraryImport) MinSdkVersion(ctx android.EarlyModuleContext) an 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 @@ func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo } } }) + sdkLibInfo := module.generateCommonBuildActions(ctx) // Populate the scope paths with information from the properties. for apiScope, scopeProperties := range module.scopeProperties { @@ -2212,11 +2164,12 @@ func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo 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 @@ func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMembe 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) } |