Merge "Fix aapt2 --min-sdk-version after finalized SDK"
This commit is contained in:
@@ -476,6 +476,10 @@ func (c *config) PlatformSdkVersion() string {
|
|||||||
return strconv.Itoa(c.PlatformSdkVersionInt())
|
return strconv.Itoa(c.PlatformSdkVersionInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *config) PlatformSdkCodename() string {
|
||||||
|
return String(c.productVariables.Platform_sdk_codename)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *config) MinSupportedSdkVersion() int {
|
func (c *config) MinSupportedSdkVersion() int {
|
||||||
return 14
|
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 {
|
func (c *config) AppsDefaultVersionName() string {
|
||||||
return String(c.productVariables.AppsDefaultVersionName)
|
return String(c.productVariables.AppsDefaultVersionName)
|
||||||
}
|
}
|
||||||
|
@@ -110,6 +110,7 @@ type productVariables struct {
|
|||||||
DateFromFile *string `json:",omitempty"`
|
DateFromFile *string `json:",omitempty"`
|
||||||
|
|
||||||
Platform_sdk_version *int `json:",omitempty"`
|
Platform_sdk_version *int `json:",omitempty"`
|
||||||
|
Platform_sdk_codename *string `json:",omitempty"`
|
||||||
Platform_sdk_final *bool `json:",omitempty"`
|
Platform_sdk_final *bool `json:",omitempty"`
|
||||||
Platform_version_active_codenames []string `json:",omitempty"`
|
Platform_version_active_codenames []string `json:",omitempty"`
|
||||||
Platform_version_future_codenames []string `json:",omitempty"`
|
Platform_version_future_codenames []string `json:",omitempty"`
|
||||||
|
@@ -134,7 +134,7 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkVersion string) (flags [
|
|||||||
// SDK version flags
|
// SDK version flags
|
||||||
switch sdkVersion {
|
switch sdkVersion {
|
||||||
case "", "current", "system_current", "test_current":
|
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)
|
linkFlags = append(linkFlags, "--min-sdk-version "+sdkVersion)
|
||||||
|
@@ -16,8 +16,10 @@ package java
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -240,3 +242,96 @@ 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 _, moduleType := range []string{"android_app", "android_library"} {
|
||||||
|
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",
|
||||||
|
}`, moduleType, 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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user