diff options
author | Colin Cross <ccross@android.com> | 2019-01-09 22:17:55 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2019-01-10 07:09:29 +0000 |
commit | fb6d78120233e5aff492fa827c27ba87354fc9e8 (patch) | |
tree | c6164fe2c9a88320aee84a78a9967ba4d0a99f0e /java/java.go | |
parent | c33514e3b68bf36ddca57624edbaed8005314c0c (diff) |
Split out sdk.go from java.go
Split out SDK handling functions from java.go to sdk.go and tests
from java_test.go to sdk.go.
Test: sdk_test.go
Change-Id: I83ef48cbe5230572c1d4ecc0e89021d2f7c71b76
Diffstat (limited to 'java/java.go')
-rw-r--r-- | java/java.go | 148 |
1 files changed, 0 insertions, 148 deletions
diff --git a/java/java.go b/java/java.go index 8b8e4ba50..9955be9c6 100644 --- a/java/java.go +++ b/java/java.go @@ -430,154 +430,6 @@ func (j *Module) targetSdkVersion() string { return j.sdkVersion() } -type sdkContext interface { - // sdkVersion eturns the sdk_version property of the current module, or an empty string if it is not set. - sdkVersion() string - // minSdkVersion returns the min_sdk_version property of the current module, or sdkVersion() if it is not set. - minSdkVersion() string - // targetSdkVersion returns the target_sdk_version property of the current module, or sdkVersion() if it is not set. - targetSdkVersion() string -} - -func sdkVersionOrDefault(ctx android.BaseContext, v string) string { - switch v { - case "", "current", "system_current", "test_current", "core_current": - return ctx.Config().DefaultAppTargetSdk() - default: - return v - } -} - -// Returns a sdk version as a number. For modules targeting an unreleased SDK (meaning it does not yet have a number) -// it returns android.FutureApiLevel (10000). -func sdkVersionToNumber(ctx android.BaseContext, v string) (int, error) { - switch v { - case "", "current", "test_current", "system_current", "core_current": - return ctx.Config().DefaultAppTargetSdkInt(), nil - default: - n := android.GetNumericSdkVersion(v) - if i, err := strconv.Atoi(n); err != nil { - return -1, fmt.Errorf("invalid sdk version %q", n) - } else { - return i, nil - } - } -} - -func sdkVersionToNumberAsString(ctx android.BaseContext, v string) (string, error) { - n, err := sdkVersionToNumber(ctx, v) - if err != nil { - return "", err - } - return strconv.Itoa(n), nil -} - -func decodeSdkDep(ctx android.BaseContext, sdkContext sdkContext) sdkDep { - v := sdkContext.sdkVersion() - i, err := sdkVersionToNumber(ctx, v) - if err != nil { - ctx.PropertyErrorf("sdk_version", "%s", err) - return 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 strings.HasPrefix(v, "system_") && i != android.FutureApiLevel { - allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions() - if ctx.DeviceSpecific() || ctx.SocSpecific() { - if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 { - allowed_versions = ctx.DeviceConfig().SystemSdkVersions() - } - } - version := strings.TrimPrefix(v, "system_") - if len(allowed_versions) > 0 && !android.InList(version, allowed_versions) { - ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q", - v, allowed_versions) - } - } - - toPrebuilt := func(sdk string) sdkDep { - var api, v string - if strings.Contains(sdk, "_") { - t := strings.Split(sdk, "_") - api = t[0] - v = t[1] - } else { - api = "public" - v = sdk - } - dir := filepath.Join("prebuilts", "sdk", v, api) - jar := filepath.Join(dir, "android.jar") - // There's no aidl for other SDKs yet. - // TODO(77525052): Add aidl files for other SDKs too. - public_dir := filepath.Join("prebuilts", "sdk", v, "public") - aidl := filepath.Join(public_dir, "framework.aidl") - jarPath := android.ExistentPathForSource(ctx, jar) - aidlPath := android.ExistentPathForSource(ctx, aidl) - lambdaStubsPath := android.PathForSource(ctx, config.SdkLambdaStubsPath) - - if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.Config().AllowMissingDependencies() { - return sdkDep{ - invalidVersion: true, - modules: []string{fmt.Sprintf("sdk_%s_%s_android", api, v)}, - } - } - - if !jarPath.Valid() { - ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar) - return sdkDep{} - } - - if !aidlPath.Valid() { - ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl) - return sdkDep{} - } - - return sdkDep{ - useFiles: true, - jars: android.Paths{jarPath.Path(), lambdaStubsPath}, - aidl: aidlPath.Path(), - } - } - - toModule := func(m, r string) sdkDep { - ret := sdkDep{ - useModule: true, - modules: []string{m, config.DefaultLambdaStubsLibrary}, - systemModules: m + "_system_modules", - frameworkResModule: r, - } - if m == "core.current.stubs" { - ret.systemModules = "core-system-modules" - } else if m == "core.platform.api.stubs" { - ret.systemModules = "core-platform-api-stubs-system-modules" - } - return ret - } - - if ctx.Config().UnbundledBuildPrebuiltSdks() && v != "" { - return toPrebuilt(v) - } - - switch v { - case "": - return sdkDep{ - useDefaultLibs: true, - frameworkResModule: "framework-res", - } - case "current": - return toModule("android_stubs_current", "framework-res") - case "system_current": - return toModule("android_system_stubs_current", "framework-res") - case "test_current": - return toModule("android_test_stubs_current", "framework-res") - case "core_current": - return toModule("core.current.stubs", "") - default: - return toPrebuilt(v) - } -} - func (j *Module) deps(ctx android.BottomUpMutatorContext) { if ctx.Device() { if !Bool(j.properties.No_standard_libs) { |