Merge "Fix aapt2 --min-sdk-version after finalized SDK" into pi-dev

This commit is contained in:
Colin Cross 2018-04-18 23:13:54 +00:00 committed by Android (Google) Code Review
commit e13f0fec3c
4 changed files with 107 additions and 1 deletions

View file

@ -476,6 +476,10 @@ func (c *config) PlatformSdkVersion() string {
return strconv.Itoa(c.PlatformSdkVersionInt())
}
func (c *config) PlatformSdkCodename() string {
return String(c.productVariables.Platform_sdk_codename)
}
func (c *config) MinSupportedSdkVersion() int {
return 14
}
@ -488,6 +492,14 @@ func (c *config) DefaultAppTargetSdkInt() int {
}
}
func (c *config) DefaultAppTargetSdk() string {
if Bool(c.productVariables.Platform_sdk_final) {
return c.PlatformSdkVersion()
} else {
return c.PlatformSdkCodename()
}
}
func (c *config) AppsDefaultVersionName() string {
return String(c.productVariables.AppsDefaultVersionName)
}

View file

@ -128,6 +128,7 @@ type productVariables struct {
DateFromFile *string `json:",omitempty"`
Platform_sdk_version *int `json:",omitempty"`
Platform_sdk_codename *string `json:",omitempty"`
Platform_sdk_final *bool `json:",omitempty"`
Platform_version_active_codenames []string `json:",omitempty"`
Platform_version_future_codenames []string `json:",omitempty"`

View file

@ -283,7 +283,7 @@ func (a *AndroidApp) aapt2Flags(ctx android.ModuleContext) (flags []string, deps
sdkVersion := String(a.deviceProperties.Sdk_version)
switch sdkVersion {
case "", "current", "system_current", "test_current":
sdkVersion = proptools.NinjaEscape([]string{ctx.Config().AppsDefaultVersionName()})[0]
sdkVersion = proptools.NinjaEscape([]string{ctx.Config().DefaultAppTargetSdk()})[0]
}
linkFlags = append(linkFlags, "--min-sdk-version "+sdkVersion)

View file

@ -16,8 +16,10 @@ package java
import (
"android/soong/android"
"fmt"
"reflect"
"sort"
"strings"
"testing"
)
@ -237,3 +239,94 @@ func TestEnforceRRO(t *testing.T) {
})
}
}
func TestAppSdkVersion(t *testing.T) {
testCases := []struct {
name string
sdkVersion string
platformSdkInt int
platformSdkCodename string
platformSdkFinal bool
expectedMinSdkVersion string
}{
{
name: "current final SDK",
sdkVersion: "current",
platformSdkInt: 27,
platformSdkCodename: "REL",
platformSdkFinal: true,
expectedMinSdkVersion: "27",
},
{
name: "current non-final SDK",
sdkVersion: "current",
platformSdkInt: 27,
platformSdkCodename: "OMR1",
platformSdkFinal: false,
expectedMinSdkVersion: "OMR1",
},
{
name: "default final SDK",
sdkVersion: "",
platformSdkInt: 27,
platformSdkCodename: "REL",
platformSdkFinal: true,
expectedMinSdkVersion: "27",
},
{
name: "default non-final SDK",
sdkVersion: "",
platformSdkInt: 27,
platformSdkCodename: "OMR1",
platformSdkFinal: false,
expectedMinSdkVersion: "OMR1",
},
{
name: "14",
sdkVersion: "14",
expectedMinSdkVersion: "14",
},
}
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
bp := fmt.Sprintf(`android_app {
name: "foo",
srcs: ["a.java"],
sdk_version: "%s",
}`, test.sdkVersion)
config := testConfig(nil)
config.TestProductVariables.Platform_sdk_version = &test.platformSdkInt
config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename
config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal
ctx := testAppContext(config, bp, nil)
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)
}
})
}
}