From 626a8ad9348066fdca52aefe25ce004d8ae56e44 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Mon, 20 Mar 2023 18:52:50 +0000 Subject: [PATCH] Cleanup hardcoded references to android_*stubs_current These hardcoded refs will need to be updated when we start using .txt stub equivalent (single-tree/multi-tree). Instead of strewing this logic all over the codebase, create a helper function that contains the replacement logic. All other places should call this helper function instead of calculating the name of .txt equivalent soong module by itself. (Will do a similar cleanup in build/make) Test: no change in ninja file Change-Id: I6bf999eb4aeaba6ac2a44b9016bae4ec8c79ce19 --- android/sdk_version.go | 34 ++++++++++++++++++++++++++++++++++ java/base.go | 10 +++++----- java/hiddenapi_modular.go | 6 +++--- java/sdk.go | 20 ++++++++------------ 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/android/sdk_version.go b/android/sdk_version.go index a7e03dcd8..cace88a01 100644 --- a/android/sdk_version.go +++ b/android/sdk_version.go @@ -84,6 +84,40 @@ func (k SdkKind) String() string { } } +// JavaLibraryName returns the soong module containing the Java APIs of that API surface. +func (k SdkKind) JavaLibraryName(c Config) string { + name := k.defaultJavaLibraryName() + return JavaLibraryNameFromText(c, name) +} + +// JavaLibraryNameFromText returns the name of .txt equivalent of a java_library, but does +// not check if either module exists. +// TODO: Return .txt (single-tree or multi-tree equivalents) based on config +func JavaLibraryNameFromText(c Config, name string) string { + // This returns the default for now. + // TODO: Implement this + return name +} + +func (k SdkKind) defaultJavaLibraryName() string { + switch k { + case SdkPublic: + return "android_stubs_current" + case SdkSystem: + return "android_system_stubs_current" + case SdkTest: + return "android_test_stubs_current" + case SdkCore: + return "core.current.stubs" + case SdkModule: + return "android_module_lib_stubs_current" + case SdkSystemServer: + return "android_system_server_stubs_current" + default: + panic(fmt.Errorf("APIs of API surface %v cannot be provided by a single Soong module\n", k)) + } +} + // SdkSpec represents the kind and the version of an SDK for a module to build against type SdkSpec struct { Kind SdkKind diff --git a/java/base.go b/java/base.go index 85f4a5e06..7e95abd02 100644 --- a/java/base.go +++ b/java/base.go @@ -1924,15 +1924,15 @@ func (m *Module) getSdkLinkType(ctx android.BaseModuleContext, name string) (ret "stub-annotations", "private-stub-annotations-jar", "core-lambda-stubs", "core-generated-annotation-stubs": return javaCore, true - case "android_stubs_current": + case android.SdkPublic.JavaLibraryName(ctx.Config()): return javaSdk, true - case "android_system_stubs_current": + case android.SdkSystem.JavaLibraryName(ctx.Config()): return javaSystem, true - case "android_module_lib_stubs_current": + case android.SdkModule.JavaLibraryName(ctx.Config()): return javaModule, true - case "android_system_server_stubs_current": + case android.SdkSystemServer.JavaLibraryName(ctx.Config()): return javaSystemServer, true - case "android_test_stubs_current": + case android.SdkTest.JavaLibraryName(ctx.Config()): return javaSystem, true } diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index be4a48e5b..e2db0cd6b 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -236,9 +236,9 @@ func hiddenAPIComputeMonolithicStubLibModules(config android.Config) map[*Hidden testStubModules = append(testStubModules, "sdk_test_current_android") } else { // Use stub modules built from source - publicStubModules = append(publicStubModules, "android_stubs_current") - systemStubModules = append(systemStubModules, "android_system_stubs_current") - testStubModules = append(testStubModules, "android_test_stubs_current") + publicStubModules = append(publicStubModules, android.SdkPublic.JavaLibraryName(config)) + systemStubModules = append(systemStubModules, android.SdkSystem.JavaLibraryName(config)) + testStubModules = append(testStubModules, android.SdkTest.JavaLibraryName(config)) } // We do not have prebuilts of the core platform api yet corePlatformStubModules = append(corePlatformStubModules, "legacy.core.platform.api.stubs") diff --git a/java/sdk.go b/java/sdk.go index 1e7727b49..72a50067c 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -191,12 +191,8 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) bootclasspath: corePlatformBootclasspathLibraries(ctx), noFrameworksLibs: true, } - case android.SdkPublic: - return toModule("android_stubs_current", sdkFrameworkAidlPath(ctx)) - case android.SdkSystem: - return toModule("android_system_stubs_current", sdkFrameworkAidlPath(ctx)) - case android.SdkTest: - return toModule("android_test_stubs_current", sdkFrameworkAidlPath(ctx)) + case android.SdkPublic, android.SdkSystem, android.SdkTest: + return toModule(sdkVersion.Kind.JavaLibraryName(ctx.Config()), sdkFrameworkAidlPath(ctx)) case android.SdkCore: return sdkDep{ useModule: true, @@ -206,10 +202,10 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) } case android.SdkModule: // TODO(146757305): provide .apk and .aidl that have more APIs for modules - return toModule("android_module_lib_stubs_current", nonUpdatableFrameworkAidlPath(ctx)) + return toModule(sdkVersion.Kind.JavaLibraryName(ctx.Config()), nonUpdatableFrameworkAidlPath(ctx)) case android.SdkSystemServer: // TODO(146757305): provide .apk and .aidl that have more APIs for modules - return toModule("android_system_server_stubs_current", sdkFrameworkAidlPath(ctx)) + return toModule(sdkVersion.Kind.JavaLibraryName(ctx.Config()), sdkFrameworkAidlPath(ctx)) default: panic(fmt.Errorf("invalid sdk %q", sdkVersion.Raw)) } @@ -272,9 +268,9 @@ func (sdkSingleton) GenerateBuildActions(ctx android.SingletonContext) { // Create framework.aidl by extracting anything that implements android.os.Parcelable from the SDK stubs modules. func createSdkFrameworkAidl(ctx android.SingletonContext) { stubsModules := []string{ - "android_stubs_current", - "android_test_stubs_current", - "android_system_stubs_current", + android.SdkPublic.JavaLibraryName(ctx.Config()), + android.SdkTest.JavaLibraryName(ctx.Config()), + android.SdkSystem.JavaLibraryName(ctx.Config()), } combinedAidl := sdkFrameworkAidlPath(ctx) @@ -289,7 +285,7 @@ func createSdkFrameworkAidl(ctx android.SingletonContext) { // Creates a version of framework.aidl for the non-updatable part of the platform. func createNonUpdatableFrameworkAidl(ctx android.SingletonContext) { - stubsModules := []string{"android_module_lib_stubs_current"} + stubsModules := []string{android.SdkModule.JavaLibraryName(ctx.Config())} combinedAidl := nonUpdatableFrameworkAidlPath(ctx) tempPath := tempPathForRestat(ctx, combinedAidl)