Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 626a8ad9 authored by Spandan Das's avatar Spandan Das
Browse files

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
parent 44ac6dad
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -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
+5 −5
Original line number Diff line number Diff line
@@ -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
	}

+3 −3
Original line number Diff line number Diff line
@@ -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")
+8 −12
Original line number Diff line number Diff line
@@ -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)