From c3e9263d7efe8ca7638a21ebbeb4f724033409f7 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Sat, 21 Mar 2020 23:20:55 +0900 Subject: [PATCH] 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) Merged-In: I57fa4afe027eb39b98bd94d534be9ebe11713f19 Change-Id: I57fa4afe027eb39b98bd94d534be9ebe11713f19 (cherry picked from commit 24282778eeb7b0eee3a9b9068b241b0525b4c289) Exempt-From-Owner-Approval: cp from aosp --- apex/apex_test.go | 8 +++++++- cc/compiler.go | 15 +++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index cde80c131..704bad690 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -1740,6 +1740,7 @@ func TestMacro(t *testing.T) { "myapex", "otherapex", ], + recovery_available: true, } cc_library { name: "mylib2", @@ -1757,7 +1758,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"] @@ -1789,6 +1790,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) { diff --git a/cc/compiler.go b/cc/compiler.go index fe81bd0a4..681b1ab90 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -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)