Merge changes from topic "min_sdk_version"
* changes: Versioned CRT objects are built with correct __ANDROID_API__ Always respect min_sdk_version
This commit is contained in:
commit
10906f5cc6
20
cc/cc.go
20
cc/cc.go
|
@ -1363,6 +1363,19 @@ func (ctx *moduleContextImpl) minSdkVersion() string {
|
||||||
if ver == "apex_inherit" || ver == "" {
|
if ver == "apex_inherit" || ver == "" {
|
||||||
ver = ctx.sdkVersion()
|
ver = ctx.sdkVersion()
|
||||||
}
|
}
|
||||||
|
// For crt objects, the meaning of min_sdk_version is very different from other types of
|
||||||
|
// module. For them, min_sdk_version defines the oldest version that the build system will
|
||||||
|
// create versioned variants for. For example, if min_sdk_version is 16, then sdk variant of
|
||||||
|
// the crt object has local variants of 16, 17, ..., up to the latest version. sdk_version
|
||||||
|
// and min_sdk_version properties of the variants are set to the corresponding version
|
||||||
|
// numbers. However, the platform (non-sdk) variant of the crt object is left untouched.
|
||||||
|
// min_sdk_version: 16 doesn't actually mean that the platform variant has to support such
|
||||||
|
// an old version. Since the variant is for the platform, it's preferred to target the
|
||||||
|
// latest version.
|
||||||
|
if ctx.mod.SplitPerApiLevel() && !ctx.isSdkVariant() {
|
||||||
|
ver = strconv.Itoa(android.FutureApiLevelInt)
|
||||||
|
}
|
||||||
|
|
||||||
// Also make sure that minSdkVersion is not greater than sdkVersion, if they are both numbers
|
// Also make sure that minSdkVersion is not greater than sdkVersion, if they are both numbers
|
||||||
sdkVersionInt, err := strconv.Atoi(ctx.sdkVersion())
|
sdkVersionInt, err := strconv.Atoi(ctx.sdkVersion())
|
||||||
minSdkVersionInt, err2 := strconv.Atoi(ver)
|
minSdkVersionInt, err2 := strconv.Atoi(ver)
|
||||||
|
@ -1927,9 +1940,14 @@ func GetCrtVariations(ctx android.BottomUpMutatorContext,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if m.UseSdk() {
|
if m.UseSdk() {
|
||||||
|
// Choose the CRT that best satisfies the min_sdk_version requirement of this module
|
||||||
|
minSdkVersion := m.MinSdkVersion()
|
||||||
|
if minSdkVersion == "" || minSdkVersion == "apex_inherit" {
|
||||||
|
minSdkVersion = m.SdkVersion()
|
||||||
|
}
|
||||||
return []blueprint.Variation{
|
return []blueprint.Variation{
|
||||||
{Mutator: "sdk", Variation: "sdk"},
|
{Mutator: "sdk", Variation: "sdk"},
|
||||||
{Mutator: "version", Variation: m.SdkVersion()},
|
{Mutator: "version", Variation: minSdkVersion},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return []blueprint.Variation{
|
return []blueprint.Variation{
|
||||||
|
|
|
@ -3637,6 +3637,71 @@ func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMinSdkVersionInClangTriple(t *testing.T) {
|
||||||
|
ctx := testCc(t, `
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libfoo",
|
||||||
|
srcs: ["foo.c"],
|
||||||
|
min_sdk_version: "29",
|
||||||
|
}`)
|
||||||
|
|
||||||
|
cFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
|
||||||
|
android.AssertStringDoesContain(t, "min sdk version", cFlags, "-target aarch64-linux-android29")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMinSdkVersionsOfCrtObjects(t *testing.T) {
|
||||||
|
ctx := testCc(t, `
|
||||||
|
cc_object {
|
||||||
|
name: "crt_foo",
|
||||||
|
srcs: ["foo.c"],
|
||||||
|
crt: true,
|
||||||
|
stl: "none",
|
||||||
|
min_sdk_version: "28",
|
||||||
|
|
||||||
|
}`)
|
||||||
|
|
||||||
|
arch := "android_arm64_armv8-a"
|
||||||
|
for _, v := range []string{"", "28", "29", "30", "current"} {
|
||||||
|
var variant string
|
||||||
|
if v == "" {
|
||||||
|
variant = arch
|
||||||
|
} else {
|
||||||
|
variant = arch + "_sdk_" + v
|
||||||
|
}
|
||||||
|
cflags := ctx.ModuleForTests("crt_foo", variant).Rule("cc").Args["cFlags"]
|
||||||
|
vNum := v
|
||||||
|
if v == "current" || v == "" {
|
||||||
|
vNum = "10000"
|
||||||
|
}
|
||||||
|
expected := "-target aarch64-linux-android" + vNum + " "
|
||||||
|
android.AssertStringDoesContain(t, "cflag", cflags, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUseCrtObjectOfCorrectVersion(t *testing.T) {
|
||||||
|
ctx := testCc(t, `
|
||||||
|
cc_binary {
|
||||||
|
name: "bin",
|
||||||
|
srcs: ["foo.c"],
|
||||||
|
stl: "none",
|
||||||
|
min_sdk_version: "29",
|
||||||
|
sdk_version: "current",
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
// Sdk variant uses the crt object of the matching min_sdk_version
|
||||||
|
variant := "android_arm64_armv8-a_sdk"
|
||||||
|
crt := ctx.ModuleForTests("bin", variant).Rule("ld").Args["crtBegin"]
|
||||||
|
android.AssertStringDoesContain(t, "crt dep of sdk variant", crt,
|
||||||
|
variant+"_29/crtbegin_dynamic.o")
|
||||||
|
|
||||||
|
// platform variant uses the crt object built for platform
|
||||||
|
variant = "android_arm64_armv8-a"
|
||||||
|
crt = ctx.ModuleForTests("bin", variant).Rule("ld").Args["crtBegin"]
|
||||||
|
android.AssertStringDoesContain(t, "crt dep of platform variant", crt,
|
||||||
|
variant+"/crtbegin_dynamic.o")
|
||||||
|
}
|
||||||
|
|
||||||
type MemtagNoteType int
|
type MemtagNoteType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -414,12 +414,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
|
||||||
|
|
||||||
target := "-target " + tc.ClangTriple()
|
target := "-target " + tc.ClangTriple()
|
||||||
if ctx.Os().Class == android.Device {
|
if ctx.Os().Class == android.Device {
|
||||||
// When built for the non-updateble part of platform, minSdkVersion doesn't matter.
|
version := ctx.minSdkVersion()
|
||||||
// It matters only when building we are building for modules that can be unbundled.
|
|
||||||
version := "current"
|
|
||||||
if !ctx.isForPlatform() || ctx.isSdkVariant() {
|
|
||||||
version = ctx.minSdkVersion()
|
|
||||||
}
|
|
||||||
if version == "" || version == "current" {
|
if version == "" || version == "current" {
|
||||||
target += strconv.Itoa(android.FutureApiLevelInt)
|
target += strconv.Itoa(android.FutureApiLevelInt)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1917,6 +1917,7 @@ func createPerApiVersionVariations(mctx android.BottomUpMutatorContext, minSdkVe
|
||||||
|
|
||||||
for i, module := range modules {
|
for i, module := range modules {
|
||||||
module.(*Module).Properties.Sdk_version = StringPtr(versionStrs[i])
|
module.(*Module).Properties.Sdk_version = StringPtr(versionStrs[i])
|
||||||
|
module.(*Module).Properties.Min_sdk_version = StringPtr(versionStrs[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,7 @@ type LinkableInterface interface {
|
||||||
InProduct() bool
|
InProduct() bool
|
||||||
|
|
||||||
SdkVersion() string
|
SdkVersion() string
|
||||||
|
MinSdkVersion() string
|
||||||
AlwaysSdk() bool
|
AlwaysSdk() bool
|
||||||
IsSdkVariant() bool
|
IsSdkVariant() bool
|
||||||
|
|
||||||
|
|
|
@ -256,6 +256,10 @@ func (mod *Module) SdkVersion() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mod *Module) MinSdkVersion() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (mod *Module) AlwaysSdk() bool {
|
func (mod *Module) AlwaysSdk() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue