Add __ANDROID_APEX_<NAME>__ for apex variants
With __ANDROID_APEX_<NAME>__ definition, native modules may have different behavior when it is built for a specific apex module. Previously, the name is passed as value of definition __ANDROID_APEX__ like -D__ANDROID_APEX__=com.android.foo. But it is difficult to do conditional compilation with it. Now, since the name is incorporated into definition itself, it gets easier to set #ifdef condition. Bug: 142582178 Test: m (soong test added) Change-Id: I3c90c789fa692a19addf2e5a7c8d4cc571cde112
This commit is contained in:
parent
394951da73
commit
d29e551efd
|
@ -1209,16 +1209,22 @@ func TestMacro(t *testing.T) {
|
|||
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_MYAPEX__")
|
||||
ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
|
||||
|
||||
// APEX variant has __ANDROID_APEX__=<apexname> 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_MYAPEX__")
|
||||
ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
|
||||
|
||||
// APEX variant has __ANDROID_APEX__=<apexname> 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")
|
||||
ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__")
|
||||
ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__")
|
||||
}
|
||||
|
||||
func TestHeaderLibsDependency(t *testing.T) {
|
||||
|
|
|
@ -321,7 +321,9 @@ 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_"+makeDefineString(ctx.apexName())+"__")
|
||||
}
|
||||
|
||||
instructionSet := String(compiler.Properties.Instruction_set)
|
||||
|
@ -529,6 +531,12 @@ func (compiler *baseCompiler) hasSrcExt(ext string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// makeDefineString transforms a name of an APEX module into a value to be used as value for C define
|
||||
// For example, com.android.foo => COM_ANDROID_FOO
|
||||
func makeDefineString(name string) string {
|
||||
return strings.ReplaceAll(strings.ToUpper(name), ".", "_")
|
||||
}
|
||||
|
||||
var gnuToCReplacer = strings.NewReplacer("gnu", "c")
|
||||
|
||||
func ndkPathDeps(ctx ModuleContext) android.Paths {
|
||||
|
|
Loading…
Reference in New Issue