Specify the API level via the triple instead of __ANDROID_API__.
Clang derives the value of __ANDROID_API__ from the triple these days. In a
future version of clang I plan to start making the behaviour of the HWASAN pass
dependent on the API level in the triple, so it's going to need to be accurate.
Test: walleye-userdebug boots
Change-Id: Ie5e36b5c8f6dcda084cc12b1160abbdf94765174
diff --git a/cc/compiler.go b/cc/compiler.go
index 0f9599e..ffb6ad2 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -17,6 +17,7 @@
import (
"fmt"
"path/filepath"
+ "strconv"
"strings"
"github.com/google/blueprint/proptools"
@@ -308,27 +309,10 @@
flags.SystemIncludeFlags = append(flags.SystemIncludeFlags,
"-isystem "+getCurrentIncludePath(ctx).String(),
"-isystem "+getCurrentIncludePath(ctx).Join(ctx, config.NDKTriple(tc)).String())
-
- // TODO: Migrate to API suffixed triple?
- // Traditionally this has come from android/api-level.h, but with the
- // libc headers unified it must be set by the build system since we
- // don't have per-API level copies of that header now.
- version := ctx.sdkVersion()
- if version == "current" {
- version = "__ANDROID_API_FUTURE__"
- }
- flags.GlobalFlags = append(flags.GlobalFlags,
- "-D__ANDROID_API__="+version)
}
if ctx.useVndk() {
- // sdkVersion() returns VNDK version for vendor modules.
- version := ctx.sdkVersion()
- if version == "current" {
- version = "__ANDROID_API_FUTURE__"
- }
- flags.GlobalFlags = append(flags.GlobalFlags,
- "-D__ANDROID_API__="+version, "-D__ANDROID_VNDK__")
+ flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_VNDK__")
}
if ctx.inRecovery() {
@@ -364,6 +348,15 @@
flags.LdFlags = config.ClangFilterUnknownCflags(flags.LdFlags)
target := "-target " + tc.ClangTriple()
+ if ctx.Os().Class == android.Device {
+ version := ctx.sdkVersion()
+ if version == "" || version == "current" {
+ target += strconv.Itoa(android.FutureApiLevel)
+ } else {
+ target += version
+ }
+ }
+
gccPrefix := "-B" + config.ToolPath(tc)
flags.CFlags = append(flags.CFlags, target, gccPrefix)
diff --git a/cc/makevars.go b/cc/makevars.go
index 2b49772..acac455 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -249,9 +249,9 @@
}
clangPrefix := secondPrefix + "CLANG_" + typePrefix
- clangExtras := "-target " + toolchain.ClangTriple()
- clangExtras += " -B" + config.ToolPath(toolchain)
+ clangExtras := "-B" + config.ToolPath(toolchain)
+ ctx.Strict(clangPrefix+"TRIPLE", toolchain.ClangTriple())
ctx.Strict(clangPrefix+"GLOBAL_CFLAGS", strings.Join([]string{
toolchain.ClangCflags(),
"${config.CommonClangGlobalCflags}",