diff options
Diffstat (limited to 'java/sdk.go')
| -rw-r--r-- | java/sdk.go | 115 |
1 files changed, 68 insertions, 47 deletions
diff --git a/java/sdk.go b/java/sdk.go index f96ecded4..56fa12b3e 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -53,7 +53,7 @@ type sdkContext interface { func UseApiFingerprint(ctx android.BaseModuleContext) bool { if ctx.Config().UnbundledBuild() && - !ctx.Config().UnbundledBuildUsePrebuiltSdks() && + !ctx.Config().AlwaysUsePrebuiltSdks() && ctx.Config().IsEnvTrue("UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT") { return true } @@ -94,9 +94,9 @@ func (k sdkKind) String() string { case sdkCorePlatform: return "core_platform" case sdkModule: - return "module" + return "module-lib" case sdkSystemServer: - return "system_server" + return "system-server" default: return "invalid" } @@ -191,19 +191,22 @@ func (s sdkSpec) prebuiltSdkAvailableForUnbundledBuild() bool { return s.kind != sdkPrivate && s.kind != sdkNone && s.kind != sdkCorePlatform } -// forPdkBuild converts this sdkSpec into another sdkSpec that is for the PDK builds. -func (s sdkSpec) forPdkBuild(ctx android.EarlyModuleContext) sdkSpec { - // For PDK builds, use the latest SDK version instead of "current" or "" - if s.kind == sdkPrivate || s.kind == sdkPublic { - kind := s.kind - if kind == sdkPrivate { - // We don't have prebuilt SDK for private APIs, so use the public SDK - // instead. This looks odd, but that's how it has been done. - // TODO(b/148271073): investigate the need for this. - kind = sdkPublic +func (s sdkSpec) forVendorPartition(ctx android.EarlyModuleContext) sdkSpec { + // If BOARD_CURRENT_API_LEVEL_FOR_VENDOR_MODULES has a numeric value, + // use it instead of "current" for the vendor partition. + currentSdkVersion := ctx.DeviceConfig().CurrentApiLevelForVendorModules() + if currentSdkVersion == "current" { + return s + } + + if s.kind == sdkPublic || s.kind == sdkSystem { + if s.version.isCurrent() { + if i, err := strconv.Atoi(currentSdkVersion); err == nil { + version := sdkVersion(i) + return sdkSpec{s.kind, version, s.raw} + } + panic(fmt.Errorf("BOARD_CURRENT_API_LEVEL_FOR_VENDOR_MODULES must be either \"current\" or a number, but was %q", currentSdkVersion)) } - version := sdkVersion(LatestSdkVersionInt(ctx)) - return sdkSpec{kind, version, s.raw} } return s } @@ -212,9 +215,9 @@ func (s sdkSpec) forPdkBuild(ctx android.EarlyModuleContext) sdkSpec { func (s sdkSpec) usePrebuilt(ctx android.EarlyModuleContext) bool { if s.version.isCurrent() { // "current" can be built from source and be from prebuilt SDK - return ctx.Config().UnbundledBuildUsePrebuiltSdks() + return ctx.Config().AlwaysUsePrebuiltSdks() } else if s.version.isNumbered() { - // sanity check + // validation check if s.kind != sdkPublic && s.kind != sdkSystem && s.kind != sdkTest { panic(fmt.Errorf("prebuilt SDK is not not available for sdkKind=%q", s.kind)) return false @@ -233,8 +236,9 @@ func (s sdkSpec) effectiveVersion(ctx android.EarlyModuleContext) (sdkVersion, e if !s.valid() { return s.version, fmt.Errorf("invalid sdk version %q", s.raw) } - if ctx.Config().IsPdkBuild() { - s = s.forPdkBuild(ctx) + + if ctx.DeviceSpecific() || ctx.SocSpecific() { + s = s.forVendorPartition(ctx) } if s.version.isNumbered() { return s.version, nil @@ -321,6 +325,28 @@ func sdkSpecFrom(str string) sdkSpec { } } +func (s sdkSpec) validateSystemSdk(ctx android.EarlyModuleContext) bool { + // Ensures that the specified system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor/product Java module) + // Assuming that BOARD_SYSTEMSDK_VERSIONS := 28 29, + // sdk_version of the modules in vendor/product that use system sdk must be either system_28, system_29 or system_current + if s.kind != sdkSystem || !s.version.isNumbered() { + return true + } + allowedVersions := ctx.DeviceConfig().PlatformSystemSdkVersions() + if ctx.DeviceSpecific() || ctx.SocSpecific() || (ctx.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { + systemSdkVersions := ctx.DeviceConfig().SystemSdkVersions() + if len(systemSdkVersions) > 0 { + allowedVersions = systemSdkVersions + } + } + if len(allowedVersions) > 0 && !android.InList(s.version.String(), allowedVersions) { + ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q", + s.raw, allowedVersions) + return false + } + return true +} + func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep { sdkVersion := sdkContext.sdkVersion() if !sdkVersion.valid() { @@ -328,8 +354,12 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep return sdkDep{} } - if ctx.Config().IsPdkBuild() { - sdkVersion = sdkVersion.forPdkBuild(ctx) + if ctx.DeviceSpecific() || ctx.SocSpecific() { + sdkVersion = sdkVersion.forVendorPartition(ctx) + } + + if !sdkVersion.validateSystemSdk(ctx) { + return sdkDep{} } if sdkVersion.usePrebuilt(ctx) { @@ -384,25 +414,13 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep } } - // Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks) - // or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set) - if sdkVersion.kind == sdkSystem && sdkVersion.version.isNumbered() { - allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions() - if ctx.DeviceSpecific() || ctx.SocSpecific() { - if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 { - allowed_versions = ctx.DeviceConfig().SystemSdkVersions() - } - } - if len(allowed_versions) > 0 && !android.InList(sdkVersion.version.String(), allowed_versions) { - ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q", - sdkVersion.raw, allowed_versions) - } - } - switch sdkVersion.kind { case sdkPrivate: return sdkDep{ - useDefaultLibs: true, + useModule: true, + systemModules: corePlatformSystemModules(ctx), + bootclasspath: corePlatformBootclasspathLibraries(ctx), + classpath: config.FrameworkLibraries, frameworkResModule: "framework-res", } case sdkNone: @@ -424,9 +442,10 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep } case sdkCorePlatform: return sdkDep{ - useDefaultLibs: true, - frameworkResModule: "framework-res", - noFrameworksLibs: true, + useModule: true, + systemModules: corePlatformSystemModules(ctx), + bootclasspath: corePlatformBootclasspathLibraries(ctx), + noFrameworksLibs: true, } case sdkPublic: return toModule([]string{"android_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx)) @@ -435,7 +454,12 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep case sdkTest: return toModule([]string{"android_test_stubs_current"}, "framework-res", sdkFrameworkAidlPath(ctx)) case sdkCore: - return toModule([]string{"core.current.stubs"}, "", nil) + return sdkDep{ + useModule: true, + bootclasspath: []string{"core.current.stubs", config.DefaultLambdaStubsLibrary}, + systemModules: "core-current-stubs-system-modules", + noFrameworksLibs: true, + } case sdkModule: // TODO(146757305): provide .apk and .aidl that have more APIs for modules return toModule([]string{"android_module_lib_stubs_current"}, "framework-res", nonUpdatableFrameworkAidlPath(ctx)) @@ -492,7 +516,7 @@ func sdkSingletonFactory() android.Singleton { type sdkSingleton struct{} func (sdkSingleton) GenerateBuildActions(ctx android.SingletonContext) { - if ctx.Config().UnbundledBuildUsePrebuiltSdks() || ctx.Config().IsPdkBuild() { + if ctx.Config().AlwaysUsePrebuiltSdks() { return } @@ -612,10 +636,7 @@ func createAPIFingerprint(ctx android.SingletonContext) { if ctx.Config().PlatformSdkCodename() == "REL" { cmd.Text("echo REL >").Output(out) - } else if ctx.Config().IsPdkBuild() { - // TODO: get this from the PDK artifacts? - cmd.Text("echo PDK >").Output(out) - } else if !ctx.Config().UnbundledBuildUsePrebuiltSdks() { + } else if !ctx.Config().AlwaysUsePrebuiltSdks() { in, err := ctx.GlobWithDeps("frameworks/base/api/*current.txt", nil) if err != nil { ctx.Errorf("error globbing API files: %s", err) @@ -644,7 +665,7 @@ func ApiFingerprintPath(ctx android.PathContext) android.OutputPath { } func sdkMakeVars(ctx android.MakeVarsContext) { - if ctx.Config().UnbundledBuildUsePrebuiltSdks() || ctx.Config().IsPdkBuild() { + if ctx.Config().AlwaysUsePrebuiltSdks() { return } |