Revert "Revert "Prohibit static executable in APEX""

This reverts commit 2125aab504.

Reason for revert: relanding along with a forward fix

Change-Id: Ib0283ca6beefa2f3073860287d00553ad0af6317
This commit is contained in:
Jiyong Park
2021-08-03 07:52:17 +00:00
parent 2125aab504
commit 192600a7d0
2 changed files with 57 additions and 3 deletions

View File

@@ -1696,6 +1696,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.checkUpdatable(ctx)
a.checkMinSdkVersion(ctx)
a.checkStaticLinkingToStubLibraries(ctx)
a.checkStaticExecutables(ctx)
if len(a.properties.Tests) > 0 && !a.testApex {
ctx.PropertyErrorf("tests", "property allowed only in apex_test module type")
return
@@ -2487,6 +2488,35 @@ func (a *apexBundle) checkApexAvailability(ctx android.ModuleContext) {
})
}
// checkStaticExecutable ensures that executables in an APEX are not static.
func (a *apexBundle) checkStaticExecutables(ctx android.ModuleContext) {
ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
if ctx.OtherModuleDependencyTag(module) != executableTag {
return
}
if cc, ok := module.(*cc.Module); ok && cc.StaticExecutable() {
apex := a.ApexVariationName()
exec := ctx.OtherModuleName(module)
if isStaticExecutableAllowed(apex, exec) {
return
}
ctx.ModuleErrorf("executable %s is static", ctx.OtherModuleName(module))
}
})
}
// A small list of exceptions where static executables are allowed in APEXes.
func isStaticExecutableAllowed(apex string, exec string) bool {
m := map[string][]string{
"com.android.runtime": []string{
"linker",
"linkerconfig",
},
}
execNames, ok := m[apex]
return ok && android.InList(exec, execNames)
}
// Collect information for opening IDE project files in java/jdeps.go.
func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) {
dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...)