Merge "Add __ANDROID_APEX__"
This commit is contained in:
@@ -123,16 +123,17 @@ func testApex(t *testing.T, bp string) *android.TestContext {
|
|||||||
`
|
`
|
||||||
|
|
||||||
ctx.MockFileSystem(map[string][]byte{
|
ctx.MockFileSystem(map[string][]byte{
|
||||||
"Android.bp": []byte(bp),
|
"Android.bp": []byte(bp),
|
||||||
"build/target/product/security": nil,
|
"build/target/product/security": nil,
|
||||||
"apex_manifest.json": nil,
|
"apex_manifest.json": nil,
|
||||||
"system/sepolicy/apex/myapex-file_contexts": nil,
|
"system/sepolicy/apex/myapex-file_contexts": nil,
|
||||||
"mylib.cpp": nil,
|
"system/sepolicy/apex/otherapex-file_contexts": nil,
|
||||||
"myprebuilt": nil,
|
"mylib.cpp": nil,
|
||||||
"vendor/foo/devkeys/test.x509.pem": nil,
|
"myprebuilt": nil,
|
||||||
"vendor/foo/devkeys/test.pk8": nil,
|
"vendor/foo/devkeys/test.x509.pem": nil,
|
||||||
"vendor/foo/devkeys/testkey.avbpubkey": nil,
|
"vendor/foo/devkeys/test.pk8": nil,
|
||||||
"vendor/foo/devkeys/testkey.pem": nil,
|
"vendor/foo/devkeys/testkey.avbpubkey": nil,
|
||||||
|
"vendor/foo/devkeys/testkey.pem": nil,
|
||||||
})
|
})
|
||||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||||
android.FailIfErrored(t, errs)
|
android.FailIfErrored(t, errs)
|
||||||
@@ -729,3 +730,47 @@ func TestKeys(t *testing.T) {
|
|||||||
"vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8")
|
"vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMacro(t *testing.T) {
|
||||||
|
ctx := testApex(t, `
|
||||||
|
apex {
|
||||||
|
name: "myapex",
|
||||||
|
key: "myapex.key",
|
||||||
|
native_shared_libs: ["mylib"],
|
||||||
|
}
|
||||||
|
|
||||||
|
apex {
|
||||||
|
name: "otherapex",
|
||||||
|
key: "myapex.key",
|
||||||
|
native_shared_libs: ["mylib"],
|
||||||
|
}
|
||||||
|
|
||||||
|
apex_key {
|
||||||
|
name: "myapex.key",
|
||||||
|
public_key: "testkey.avbpubkey",
|
||||||
|
private_key: "testkey.pem",
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library {
|
||||||
|
name: "mylib",
|
||||||
|
srcs: ["mylib.cpp"],
|
||||||
|
system_shared_libs: [],
|
||||||
|
stl: "none",
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
// non-APEX variant does not have __ANDROID__APEX__ 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")
|
||||||
|
|
||||||
|
// 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")
|
||||||
|
|
||||||
|
// 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")
|
||||||
|
}
|
||||||
|
7
cc/cc.go
7
cc/cc.go
@@ -258,7 +258,7 @@ type ModuleContextIntf interface {
|
|||||||
getVndkExtendsModuleName() string
|
getVndkExtendsModuleName() string
|
||||||
isPgoCompile() bool
|
isPgoCompile() bool
|
||||||
useClangLld(actx ModuleContext) bool
|
useClangLld(actx ModuleContext) bool
|
||||||
isApex() bool
|
apexName() string
|
||||||
hasStubsVariants() bool
|
hasStubsVariants() bool
|
||||||
isStubs() bool
|
isStubs() bool
|
||||||
}
|
}
|
||||||
@@ -720,9 +720,8 @@ func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
|
|||||||
return ctx.mod.getVndkExtendsModuleName()
|
return ctx.mod.getVndkExtendsModuleName()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests if this module is built for APEX
|
func (ctx *moduleContextImpl) apexName() string {
|
||||||
func (ctx *moduleContextImpl) isApex() bool {
|
return ctx.mod.ApexName()
|
||||||
return ctx.mod.ApexName() != ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx *moduleContextImpl) hasStubsVariants() bool {
|
func (ctx *moduleContextImpl) hasStubsVariants() bool {
|
||||||
|
@@ -341,6 +341,10 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
|
|||||||
flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_RECOVERY__")
|
flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_RECOVERY__")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.apexName() != "" {
|
||||||
|
flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_APEX__="+ctx.apexName())
|
||||||
|
}
|
||||||
|
|
||||||
instructionSet := String(compiler.Properties.Instruction_set)
|
instructionSet := String(compiler.Properties.Instruction_set)
|
||||||
if flags.RequiredInstructionSet != "" {
|
if flags.RequiredInstructionSet != "" {
|
||||||
instructionSet = flags.RequiredInstructionSet
|
instructionSet = flags.RequiredInstructionSet
|
||||||
|
Reference in New Issue
Block a user