Refactor cc/sabi.go

* Rename `vndk_deps` mutator to `sabi_deps` to better reflect its
  purpose.
* Eliminate duplication of ABI dump generation logic. sabiDepsMutator
  should call libraryDecorator.shouldCreateSourceAbiDump() to determine
  if a module needs to be marked with CreateSAbiDumps.
* Non-VNDK libraries that are opt-in to ABI check would have their
  dependencies correctly marked with CreateSAbiDumps.
* Refactor some lines to idiomatic syntax.
* Add comment strings.

Bug: 145608479
Bug: 173492236
Test: TH presubmit
Change-Id: I99e97787bdf2a4f0c970809161b64aa668ff3d1a
This commit is contained in:
Yo Chiang
2020-11-19 16:30:49 +08:00
parent 9ae3c52b20
commit 8aa4e3f99e
4 changed files with 54 additions and 44 deletions

View File

@@ -79,7 +79,6 @@ func RegisterCCBuildComponents(ctx android.RegistrationContext) {
ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel() ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
ctx.BottomUp("coverage", coverageMutator).Parallel() ctx.BottomUp("coverage", coverageMutator).Parallel()
ctx.TopDown("vndk_deps", sabiDepsMutator)
ctx.TopDown("lto_deps", ltoDepsMutator) ctx.TopDown("lto_deps", ltoDepsMutator)
ctx.BottomUp("lto", ltoMutator).Parallel() ctx.BottomUp("lto", ltoMutator).Parallel()
@@ -88,6 +87,11 @@ func RegisterCCBuildComponents(ctx android.RegistrationContext) {
ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel() ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
}) })
ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
// sabi mutator needs to be run after apex mutator finishes.
ctx.TopDown("sabi_deps", sabiDepsMutator)
})
ctx.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory) ctx.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
} }

View File

@@ -249,6 +249,10 @@ func ClangFilterUnknownLldflags(lldflags []string) []string {
return result return result
} }
func ClangLibToolingFilterUnknownCflags(libToolingFlags []string) []string {
return android.RemoveListFromList(libToolingFlags, ClangLibToolingUnknownCflags)
}
func inListSorted(s string, list []string) bool { func inListSorted(s string, list []string) bool {
for _, l := range list { for _, l := range list {
if s == l { if s == l {

View File

@@ -596,7 +596,7 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags, d
// Returns a string that represents the class of the ABI dump. // Returns a string that represents the class of the ABI dump.
// Returns an empty string if ABI check is disabled for this library. // Returns an empty string if ABI check is disabled for this library.
func (library *libraryDecorator) classifySourceAbiDump(ctx ModuleContext) string { func (library *libraryDecorator) classifySourceAbiDump(ctx BaseModuleContext) string {
enabled := library.Properties.Header_abi_checker.Enabled enabled := library.Properties.Header_abi_checker.Enabled
if enabled != nil && !Bool(enabled) { if enabled != nil && !Bool(enabled) {
return "" return ""
@@ -629,7 +629,7 @@ func (library *libraryDecorator) classifySourceAbiDump(ctx ModuleContext) string
return "" return ""
} }
func (library *libraryDecorator) shouldCreateSourceAbiDump(ctx ModuleContext) bool { func (library *libraryDecorator) shouldCreateSourceAbiDump(ctx BaseModuleContext) bool {
if !ctx.shouldCreateSourceAbiDump() { if !ctx.shouldCreateSourceAbiDump() {
return false return false
} }

View File

@@ -15,7 +15,6 @@
package cc package cc
import ( import (
"strings"
"sync" "sync"
"android/soong/android" "android/soong/android"
@@ -23,12 +22,16 @@ import (
) )
var ( var (
lsdumpPaths []string lsdumpPaths []string
sabiLock sync.Mutex lsdumpPathsLock sync.Mutex
) )
type SAbiProperties struct { type SAbiProperties struct {
CreateSAbiDumps bool `blueprint:"mutated"` // True if need to generate ABI dump.
CreateSAbiDumps bool `blueprint:"mutated"`
// Include directories that may contain ABI information exported by a library.
// These directories are passed to the header-abi-dumper.
ReexportedIncludes []string `blueprint:"mutated"` ReexportedIncludes []string `blueprint:"mutated"`
} }
@@ -46,56 +49,55 @@ func (sabimod *sabi) deps(ctx BaseModuleContext, deps Deps) Deps {
return deps return deps
} }
func inListWithPrefixSearch(flag string, filter []string) bool {
// Assuming the filter is small enough.
// If the suffix of a filter element is *, try matching prefixes as well.
for _, f := range filter {
if (f == flag) || (strings.HasSuffix(f, "*") && strings.HasPrefix(flag, strings.TrimSuffix(f, "*"))) {
return true
}
}
return false
}
func filterOutWithPrefix(list []string, filter []string) (remainder []string) {
// Go through the filter, matching and optionally doing a prefix search for list elements.
for _, l := range list {
if !inListWithPrefixSearch(l, filter) {
remainder = append(remainder, l)
}
}
return
}
func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags { func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags {
// Assuming that the cflags which clang LibTooling tools cannot // Filter out flags which libTooling don't understand.
// understand have not been converted to ninja variables yet. // This is here for legacy reasons and future-proof, in case the version of libTooling and clang
flags.Local.ToolingCFlags = filterOutWithPrefix(flags.Local.CFlags, config.ClangLibToolingUnknownCflags) // diverge.
flags.Global.ToolingCFlags = filterOutWithPrefix(flags.Global.CFlags, config.ClangLibToolingUnknownCflags) flags.Local.ToolingCFlags = config.ClangLibToolingFilterUnknownCflags(flags.Local.CFlags)
flags.Local.ToolingCppFlags = filterOutWithPrefix(flags.Local.CppFlags, config.ClangLibToolingUnknownCflags) flags.Global.ToolingCFlags = config.ClangLibToolingFilterUnknownCflags(flags.Global.CFlags)
flags.Global.ToolingCppFlags = filterOutWithPrefix(flags.Global.CppFlags, config.ClangLibToolingUnknownCflags) flags.Local.ToolingCppFlags = config.ClangLibToolingFilterUnknownCflags(flags.Local.CppFlags)
flags.Global.ToolingCppFlags = config.ClangLibToolingFilterUnknownCflags(flags.Global.CppFlags)
return flags return flags
} }
func shouldSkipSabiDepsMutator(mctx android.TopDownMutatorContext, m *Module) bool {
if m.sabi != nil && m.sabi.Properties.CreateSAbiDumps {
return false
}
if library, ok := m.linker.(*libraryDecorator); ok {
ctx := &baseModuleContext{
BaseModuleContext: mctx,
moduleContextImpl: moduleContextImpl{
mod: m,
},
}
ctx.ctx = ctx
return !library.shouldCreateSourceAbiDump(ctx)
}
return true
}
// Mark the direct and transitive dependencies of libraries that need ABI check, so that ABI dumps
// of their dependencies would be generated.
func sabiDepsMutator(mctx android.TopDownMutatorContext) { func sabiDepsMutator(mctx android.TopDownMutatorContext) {
if c, ok := mctx.Module().(*Module); ok && if c, ok := mctx.Module().(*Module); ok {
((c.IsVndk() && c.UseVndk()) || c.isLlndk(mctx.Config()) || if shouldSkipSabiDepsMutator(mctx, c) {
(c.sabi != nil && c.sabi.Properties.CreateSAbiDumps)) { return
}
mctx.VisitDirectDeps(func(m android.Module) { mctx.VisitDirectDeps(func(m android.Module) {
if tag, ok := mctx.OtherModuleDependencyTag(m).(libraryDependencyTag); ok && tag.static() { if tag, ok := mctx.OtherModuleDependencyTag(m).(libraryDependencyTag); ok && tag.static() {
cc, _ := m.(*Module) if cc, ok := m.(*Module); ok {
if cc == nil { cc.sabi.Properties.CreateSAbiDumps = true
return
} }
cc.sabi.Properties.CreateSAbiDumps = true
} }
}) })
} }
} }
// Add an entry to the global list of lsdump. The list is exported to a Make variable by
// `cc.makeVarsProvider`.
func addLsdumpPath(lsdumpPath string) { func addLsdumpPath(lsdumpPath string) {
sabiLock.Lock() lsdumpPathsLock.Lock()
defer lsdumpPathsLock.Unlock()
lsdumpPaths = append(lsdumpPaths, lsdumpPath) lsdumpPaths = append(lsdumpPaths, lsdumpPath)
sabiLock.Unlock()
} }