Pass min_sdk_version to cc __ANDROID_SDK_VERSION__

The macro is required only for apex variants regardless of useVndk.
Before the enforcement of LLNDK sdk version, the macro was not passed to
vendor variants.

Bug: 151689896
Test: TARGET_BUILD_APPS=com.android.media.swcodec m
      libbase in swcodec apex is linked with liblog#29
      (compiled with __ANDROID_SDK_VERSIO__=29)

Change-Id: I57fa4afe027eb39b98bd94d534be9ebe11713f19
This commit is contained in:
Jooyung Han 2020-03-21 23:20:55 +09:00
parent 61b66e9b34
commit 24282778ee
2 changed files with 10 additions and 13 deletions

View File

@ -1824,6 +1824,7 @@ func TestMacro(t *testing.T) {
"myapex",
"otherapex",
],
recovery_available: true,
}
cc_library {
name: "mylib2",
@ -1841,7 +1842,7 @@ func TestMacro(t *testing.T) {
// non-APEX variant does not have __ANDROID_APEX__ defined
mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000")
ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000")
// APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined
mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
@ -1873,6 +1874,11 @@ func TestMacro(t *testing.T) {
ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__")
ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
// recovery variant does not set __ANDROID_SDK_VERSION__
mylibCFlags = ctx.ModuleForTests("mylib", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__")
ensureNotContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__")
}
func TestHeaderLibsDependency(t *testing.T) {

View File

@ -315,18 +315,6 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
"-isystem "+getCurrentIncludePath(ctx).Join(ctx, config.NDKTriple(tc)).String())
}
if ctx.canUseSdk() {
sdkVersion := ctx.sdkVersion()
if sdkVersion == "" || sdkVersion == "current" {
if ctx.isForPlatform() {
sdkVersion = strconv.Itoa(android.FutureApiLevel)
} else {
sdkVersion = strconv.Itoa(ctx.apexSdkVersion())
}
}
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_SDK_VERSION__="+sdkVersion)
}
if ctx.useVndk() {
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_VNDK__")
}
@ -340,6 +328,9 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
if Bool(compiler.Properties.Use_apex_name_macro) {
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_APEX_"+makeDefineString(ctx.apexName())+"__")
}
if ctx.Device() {
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_SDK_VERSION__="+strconv.Itoa(ctx.apexSdkVersion()))
}
}
instructionSet := String(compiler.Properties.Instruction_set)