From 6b8459be4fb226e6a2b8fccd96f1a6959b08df72 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Wed, 30 Oct 2019 08:29:25 +0900 Subject: [PATCH] apex: __ANDROID_APEX__ defined with no value __ANDROID_APEX__ was defined with the name of apex module. -D__ANDROID_APEX__=com.android.foo But in this way, conditional compilation is not easy since comparing macro's string value is not supported in C/C++. (There's no usages of this value in source tree.) In most cases, modules can check if __ANDROID_APEX__ is defined to see if they are compiled for apex. For modules which should behave differently according to which apex they are included, they can check __ANDROID_APEX___. Bug: 142582178 Test: m (soong tests run) && boot device && TH Change-Id: I0f5e3e9463ccd96cbba333a8bdd648470c5c912d --- apex/apex_test.go | 15 ++++++--------- cc/compiler.go | 3 +-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index ffbee8694..227164564 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -1212,24 +1212,21 @@ func TestMacro(t *testing.T) { } `) - // non-APEX variant does not have __ANDROID__APEX__ defined + // non-APEX variant does not have __ANDROID_APEX(_NAME)__ defined mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"] - ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") - ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") + ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") - // APEX variant has __ANDROID_APEX__= defined + // APEX variant has __ANDROID_APEX(_NAME)__ defined mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] - ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") - ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") + ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") - // APEX variant has __ANDROID_APEX__= defined + // APEX variant has __ANDROID_APEX(_NAME)__ defined mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"] - ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") - ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") + ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") } diff --git a/cc/compiler.go b/cc/compiler.go index 438dee701..ff681017e 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -320,8 +320,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps } if ctx.apexName() != "" { - // TODO(b/142582178): remove the value for __ANDROID_APEX__ - flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_APEX__="+ctx.apexName()) + flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_APEX__") flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_APEX_"+makeDefineString(ctx.apexName())+"__") }