Introduce BOARD_CURRENT_API_LEVEL_FOR_VENDOR_MODULES
If BOARD_CURRENT_API_LEVEL_FOR_VENDOR_MODULES has a numeric value, it replaces "current" or "system_current" with the version which the flag indicates. Bug: 163009188 Test: BOARD_CURRENT_API_LEVEL_FOR_VENDOR_MODULES=29 m, and then check if every vendor java module's sdk_version is 29 if its sdk_version was current. Change-Id: I17b49b8e02caf2d1bc57b91648d4420f3ad9fcb9
This commit is contained in:
parent
03333d0e2f
commit
219141c6bb
|
@ -35,6 +35,7 @@ import (
|
||||||
|
|
||||||
var Bool = proptools.Bool
|
var Bool = proptools.Bool
|
||||||
var String = proptools.String
|
var String = proptools.String
|
||||||
|
var StringDefault = proptools.StringDefault
|
||||||
|
|
||||||
const FutureApiLevel = 10000
|
const FutureApiLevel = 10000
|
||||||
|
|
||||||
|
@ -958,6 +959,10 @@ func (c *deviceConfig) VndkVersion() string {
|
||||||
return String(c.config.productVariables.DeviceVndkVersion)
|
return String(c.config.productVariables.DeviceVndkVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *deviceConfig) CurrentApiLevelForVendorModules() string {
|
||||||
|
return StringDefault(c.config.productVariables.DeviceCurrentApiLevelForVendorModules, "current")
|
||||||
|
}
|
||||||
|
|
||||||
func (c *deviceConfig) PlatformVndkVersion() string {
|
func (c *deviceConfig) PlatformVndkVersion() string {
|
||||||
return String(c.config.productVariables.Platform_vndk_version)
|
return String(c.config.productVariables.Platform_vndk_version)
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,6 +172,7 @@ type productVariables struct {
|
||||||
DeviceCpuVariant *string `json:",omitempty"`
|
DeviceCpuVariant *string `json:",omitempty"`
|
||||||
DeviceAbi []string `json:",omitempty"`
|
DeviceAbi []string `json:",omitempty"`
|
||||||
DeviceVndkVersion *string `json:",omitempty"`
|
DeviceVndkVersion *string `json:",omitempty"`
|
||||||
|
DeviceCurrentApiLevelForVendorModules *string `json:",omitempty"`
|
||||||
DeviceSystemSdkVersions []string `json:",omitempty"`
|
DeviceSystemSdkVersions []string `json:",omitempty"`
|
||||||
|
|
||||||
DeviceSecondaryArch *string `json:",omitempty"`
|
DeviceSecondaryArch *string `json:",omitempty"`
|
||||||
|
|
128
java/app_test.go
128
java/app_test.go
|
@ -1038,6 +1038,35 @@ func TestAndroidResources(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkSdkVersion(t *testing.T, config android.Config, expectedSdkVersion string) {
|
||||||
|
ctx := testContext()
|
||||||
|
|
||||||
|
run(t, ctx, config)
|
||||||
|
|
||||||
|
foo := ctx.ModuleForTests("foo", "android_common")
|
||||||
|
link := foo.Output("package-res.apk")
|
||||||
|
linkFlags := strings.Split(link.Args["flags"], " ")
|
||||||
|
min := android.IndexList("--min-sdk-version", linkFlags)
|
||||||
|
target := android.IndexList("--target-sdk-version", linkFlags)
|
||||||
|
|
||||||
|
if min == -1 || target == -1 || min == len(linkFlags)-1 || target == len(linkFlags)-1 {
|
||||||
|
t.Fatalf("missing --min-sdk-version or --target-sdk-version in link flags: %q", linkFlags)
|
||||||
|
}
|
||||||
|
|
||||||
|
gotMinSdkVersion := linkFlags[min+1]
|
||||||
|
gotTargetSdkVersion := linkFlags[target+1]
|
||||||
|
|
||||||
|
if gotMinSdkVersion != expectedSdkVersion {
|
||||||
|
t.Errorf("incorrect --min-sdk-version, expected %q got %q",
|
||||||
|
expectedSdkVersion, gotMinSdkVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
if gotTargetSdkVersion != expectedSdkVersion {
|
||||||
|
t.Errorf("incorrect --target-sdk-version, expected %q got %q",
|
||||||
|
expectedSdkVersion, gotTargetSdkVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAppSdkVersion(t *testing.T) {
|
func TestAppSdkVersion(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -1107,38 +1136,85 @@ func TestAppSdkVersion(t *testing.T) {
|
||||||
config.TestProductVariables.Platform_sdk_version = &test.platformSdkInt
|
config.TestProductVariables.Platform_sdk_version = &test.platformSdkInt
|
||||||
config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename
|
config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename
|
||||||
config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal
|
config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal
|
||||||
|
checkSdkVersion(t, config, test.expectedMinSdkVersion)
|
||||||
|
|
||||||
ctx := testContext()
|
|
||||||
|
|
||||||
run(t, ctx, config)
|
|
||||||
|
|
||||||
foo := ctx.ModuleForTests("foo", "android_common")
|
|
||||||
link := foo.Output("package-res.apk")
|
|
||||||
linkFlags := strings.Split(link.Args["flags"], " ")
|
|
||||||
min := android.IndexList("--min-sdk-version", linkFlags)
|
|
||||||
target := android.IndexList("--target-sdk-version", linkFlags)
|
|
||||||
|
|
||||||
if min == -1 || target == -1 || min == len(linkFlags)-1 || target == len(linkFlags)-1 {
|
|
||||||
t.Fatalf("missing --min-sdk-version or --target-sdk-version in link flags: %q", linkFlags)
|
|
||||||
}
|
|
||||||
|
|
||||||
gotMinSdkVersion := linkFlags[min+1]
|
|
||||||
gotTargetSdkVersion := linkFlags[target+1]
|
|
||||||
|
|
||||||
if gotMinSdkVersion != test.expectedMinSdkVersion {
|
|
||||||
t.Errorf("incorrect --min-sdk-version, expected %q got %q",
|
|
||||||
test.expectedMinSdkVersion, gotMinSdkVersion)
|
|
||||||
}
|
|
||||||
|
|
||||||
if gotTargetSdkVersion != test.expectedMinSdkVersion {
|
|
||||||
t.Errorf("incorrect --target-sdk-version, expected %q got %q",
|
|
||||||
test.expectedMinSdkVersion, gotTargetSdkVersion)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVendorAppSdkVersion(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
sdkVersion string
|
||||||
|
platformSdkInt int
|
||||||
|
platformSdkCodename string
|
||||||
|
platformSdkFinal bool
|
||||||
|
deviceCurrentApiLevelForVendorModules string
|
||||||
|
expectedMinSdkVersion string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "current final SDK",
|
||||||
|
sdkVersion: "current",
|
||||||
|
platformSdkInt: 29,
|
||||||
|
platformSdkCodename: "REL",
|
||||||
|
platformSdkFinal: true,
|
||||||
|
deviceCurrentApiLevelForVendorModules: "29",
|
||||||
|
expectedMinSdkVersion: "29",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "current final SDK",
|
||||||
|
sdkVersion: "current",
|
||||||
|
platformSdkInt: 29,
|
||||||
|
platformSdkCodename: "REL",
|
||||||
|
platformSdkFinal: true,
|
||||||
|
deviceCurrentApiLevelForVendorModules: "28",
|
||||||
|
expectedMinSdkVersion: "28",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "current final SDK",
|
||||||
|
sdkVersion: "current",
|
||||||
|
platformSdkInt: 29,
|
||||||
|
platformSdkCodename: "Q",
|
||||||
|
platformSdkFinal: false,
|
||||||
|
deviceCurrentApiLevelForVendorModules: "current",
|
||||||
|
expectedMinSdkVersion: "Q",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "current final SDK",
|
||||||
|
sdkVersion: "current",
|
||||||
|
platformSdkInt: 29,
|
||||||
|
platformSdkCodename: "Q",
|
||||||
|
platformSdkFinal: false,
|
||||||
|
deviceCurrentApiLevelForVendorModules: "28",
|
||||||
|
expectedMinSdkVersion: "28",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, moduleType := range []string{"android_app", "android_library"} {
|
||||||
|
for _, sdkKind := range []string{"", "system_"} {
|
||||||
|
for _, test := range testCases {
|
||||||
|
t.Run(moduleType+" "+test.name, func(t *testing.T) {
|
||||||
|
bp := fmt.Sprintf(`%s {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
sdk_version: "%s%s",
|
||||||
|
vendor: true,
|
||||||
|
}`, moduleType, sdkKind, test.sdkVersion)
|
||||||
|
|
||||||
|
config := testAppConfig(nil, bp, nil)
|
||||||
|
config.TestProductVariables.Platform_sdk_version = &test.platformSdkInt
|
||||||
|
config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename
|
||||||
|
config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal
|
||||||
|
config.TestProductVariables.DeviceCurrentApiLevelForVendorModules = &test.deviceCurrentApiLevelForVendorModules
|
||||||
|
config.TestProductVariables.DeviceSystemSdkVersions = []string{"28", "29"}
|
||||||
|
checkSdkVersion(t, config, test.expectedMinSdkVersion)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestJNIABI(t *testing.T) {
|
func TestJNIABI(t *testing.T) {
|
||||||
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
|
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
|
||||||
cc_library {
|
cc_library {
|
||||||
|
|
28
java/sdk.go
28
java/sdk.go
|
@ -191,6 +191,26 @@ func (s sdkSpec) prebuiltSdkAvailableForUnbundledBuild() bool {
|
||||||
return s.kind != sdkPrivate && s.kind != sdkNone && s.kind != sdkCorePlatform
|
return s.kind != sdkPrivate && s.kind != sdkNone && s.kind != sdkCorePlatform
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
// usePrebuilt determines whether prebuilt SDK should be used for this sdkSpec with the given context.
|
// usePrebuilt determines whether prebuilt SDK should be used for this sdkSpec with the given context.
|
||||||
func (s sdkSpec) usePrebuilt(ctx android.EarlyModuleContext) bool {
|
func (s sdkSpec) usePrebuilt(ctx android.EarlyModuleContext) bool {
|
||||||
if s.version.isCurrent() {
|
if s.version.isCurrent() {
|
||||||
|
@ -216,6 +236,10 @@ func (s sdkSpec) effectiveVersion(ctx android.EarlyModuleContext) (sdkVersion, e
|
||||||
if !s.valid() {
|
if !s.valid() {
|
||||||
return s.version, fmt.Errorf("invalid sdk version %q", s.raw)
|
return s.version, fmt.Errorf("invalid sdk version %q", s.raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.DeviceSpecific() || ctx.SocSpecific() {
|
||||||
|
s = s.forVendorPartition(ctx)
|
||||||
|
}
|
||||||
if s.version.isNumbered() {
|
if s.version.isNumbered() {
|
||||||
return s.version, nil
|
return s.version, nil
|
||||||
}
|
}
|
||||||
|
@ -330,6 +354,10 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext sdkContext) sdkDep
|
||||||
return sdkDep{}
|
return sdkDep{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.DeviceSpecific() || ctx.SocSpecific() {
|
||||||
|
sdkVersion = sdkVersion.forVendorPartition(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
if !sdkVersion.validateSystemSdk(ctx) {
|
if !sdkVersion.validateSystemSdk(ctx) {
|
||||||
return sdkDep{}
|
return sdkDep{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,9 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
|
||||||
"prebuilts/sdk/17/public/android.jar": nil,
|
"prebuilts/sdk/17/public/android.jar": nil,
|
||||||
"prebuilts/sdk/17/public/framework.aidl": nil,
|
"prebuilts/sdk/17/public/framework.aidl": nil,
|
||||||
"prebuilts/sdk/17/system/android.jar": nil,
|
"prebuilts/sdk/17/system/android.jar": nil,
|
||||||
|
"prebuilts/sdk/28/public/android.jar": nil,
|
||||||
|
"prebuilts/sdk/28/public/framework.aidl": nil,
|
||||||
|
"prebuilts/sdk/28/system/android.jar": nil,
|
||||||
"prebuilts/sdk/29/public/android.jar": nil,
|
"prebuilts/sdk/29/public/android.jar": nil,
|
||||||
"prebuilts/sdk/29/public/framework.aidl": nil,
|
"prebuilts/sdk/29/public/framework.aidl": nil,
|
||||||
"prebuilts/sdk/29/system/android.jar": nil,
|
"prebuilts/sdk/29/system/android.jar": nil,
|
||||||
|
|
Loading…
Reference in New Issue