Refactor cc/cc.go cc/library.go shouldCreateSourceAbiDump()
* Consolidate the two shouldCreateSourceAbiDump() in cc/cc.go and cc/library.go into cc/sabi.go. * Rename SAbiProperties.CreateSAbiDumps to ShouldCreateSourceAbiDump. * sabiDepsMutator determines whether a library needs to generate ABI dump, and mark their ShouldCreateSourceAbiDump property. * After this change, sabi.Properties.ShouldCreateSourceAbiDump is the single source of truth of whether ABI dump should be created or not. GenerateAndroidBuildActions() should check the property, or call the property accessor (*sabi).shouldCreateSourceAbiDump(). * classifySourceAbiDump() is no longer a *libraryDecorator receiver. Instead it uses the libraryInterface object in the ctx.Module().(*cc.Module).library field. This way classifySourceAbiDump() doesn't need to depend on the internal fields of libraryDecorator. Bug: 145608479 Bug: 173492236 Test: Presubmit Test: Dump the list of module names marked by sabi_deps mutator Change-Id: Ibfc29fe0153551ab6e2d56ff38ab9bae2c179e0b
This commit is contained in:
37
cc/cc.go
37
cc/cc.go
@@ -419,7 +419,6 @@ type ModuleContextIntf interface {
|
|||||||
inRamdisk() bool
|
inRamdisk() bool
|
||||||
inVendorRamdisk() bool
|
inVendorRamdisk() bool
|
||||||
inRecovery() bool
|
inRecovery() bool
|
||||||
shouldCreateSourceAbiDump() bool
|
|
||||||
selectedStl() string
|
selectedStl() string
|
||||||
baseModuleName() string
|
baseModuleName() string
|
||||||
getVndkExtendsModuleName() string
|
getVndkExtendsModuleName() string
|
||||||
@@ -1283,42 +1282,6 @@ func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
|
|||||||
return ctx.mod.MustUseVendorVariant()
|
return ctx.mod.MustUseVendorVariant()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether ABI dumps should be created for this module.
|
|
||||||
func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
|
|
||||||
if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Coverage builds have extra symbols.
|
|
||||||
if ctx.mod.isCoverageVariant() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if ctx.ctx.Fuchsia() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if sanitize := ctx.mod.sanitize; sanitize != nil {
|
|
||||||
if !sanitize.isVariantOnProductionDevice() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !ctx.ctx.Device() {
|
|
||||||
// Host modules do not need ABI dumps.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if ctx.isNDKStubLibrary() {
|
|
||||||
// Stubs do not need ABI dumps.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if lib := ctx.mod.library; lib != nil && lib.buildStubs() {
|
|
||||||
// Stubs do not need ABI dumps.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ctx *moduleContextImpl) selectedStl() string {
|
func (ctx *moduleContextImpl) selectedStl() string {
|
||||||
if stl := ctx.mod.stl; stl != nil {
|
if stl := ctx.mod.stl; stl != nil {
|
||||||
return stl.Properties.SelectedStl
|
return stl.Properties.SelectedStl
|
||||||
|
@@ -594,59 +594,12 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags, d
|
|||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a string that represents the class of the ABI dump.
|
func (library *libraryDecorator) headerAbiCheckerEnabled() bool {
|
||||||
// Returns an empty string if ABI check is disabled for this library.
|
return Bool(library.Properties.Header_abi_checker.Enabled)
|
||||||
func (library *libraryDecorator) classifySourceAbiDump(ctx BaseModuleContext) string {
|
|
||||||
enabled := library.Properties.Header_abi_checker.Enabled
|
|
||||||
if enabled != nil && !Bool(enabled) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
// Return NDK if the library is both NDK and LLNDK.
|
|
||||||
if ctx.isNdk(ctx.Config()) {
|
|
||||||
return "NDK"
|
|
||||||
}
|
|
||||||
if ctx.isLlndkPublic(ctx.Config()) {
|
|
||||||
return "LLNDK"
|
|
||||||
}
|
|
||||||
if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate(ctx.Config()) {
|
|
||||||
if ctx.isVndkSp() {
|
|
||||||
if ctx.IsVndkExt() {
|
|
||||||
return "VNDK-SP-ext"
|
|
||||||
} else {
|
|
||||||
return "VNDK-SP"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ctx.IsVndkExt() {
|
|
||||||
return "VNDK-ext"
|
|
||||||
} else {
|
|
||||||
return "VNDK-core"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if Bool(enabled) || library.hasStubsVariants() {
|
|
||||||
return "PLATFORM"
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) shouldCreateSourceAbiDump(ctx BaseModuleContext) bool {
|
func (library *libraryDecorator) headerAbiCheckerExplicitlyDisabled() bool {
|
||||||
if !ctx.shouldCreateSourceAbiDump() {
|
return !BoolDefault(library.Properties.Header_abi_checker.Enabled, true)
|
||||||
return false
|
|
||||||
}
|
|
||||||
if !ctx.isForPlatform() {
|
|
||||||
if !library.hasStubsVariants() {
|
|
||||||
// Skip ABI checks if this library is for APEX but isn't exported.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if !Bool(library.Properties.Header_abi_checker.Enabled) {
|
|
||||||
// Skip ABI checks if this library is for APEX and did not explicitly enable
|
|
||||||
// ABI checks.
|
|
||||||
// TODO(b/145608479): ABI checks should be enabled by default. Remove this
|
|
||||||
// after evaluating the extra build time.
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return library.classifySourceAbiDump(ctx) != ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
|
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
|
||||||
@@ -668,7 +621,7 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
|
|||||||
}
|
}
|
||||||
return Objects{}
|
return Objects{}
|
||||||
}
|
}
|
||||||
if library.shouldCreateSourceAbiDump(ctx) || library.sabi.Properties.CreateSAbiDumps {
|
if library.sabi.shouldCreateSourceAbiDump() {
|
||||||
exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
|
exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
|
||||||
var SourceAbiFlags []string
|
var SourceAbiFlags []string
|
||||||
for _, dir := range exportIncludeDirs.Strings() {
|
for _, dir := range exportIncludeDirs.Strings() {
|
||||||
@@ -718,6 +671,10 @@ type libraryInterface interface {
|
|||||||
setStatic()
|
setStatic()
|
||||||
setShared()
|
setShared()
|
||||||
|
|
||||||
|
// Check whether header_abi_checker is enabled or explicitly disabled.
|
||||||
|
headerAbiCheckerEnabled() bool
|
||||||
|
headerAbiCheckerExplicitlyDisabled() bool
|
||||||
|
|
||||||
// Write LOCAL_ADDITIONAL_DEPENDENCIES for ABI diff
|
// Write LOCAL_ADDITIONAL_DEPENDENCIES for ABI diff
|
||||||
androidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer)
|
androidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer)
|
||||||
|
|
||||||
@@ -1158,7 +1115,7 @@ func getRefAbiDumpFile(ctx ModuleContext, vndkVersion, fileName string) android.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string, soFile android.Path) {
|
func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string, soFile android.Path) {
|
||||||
if library.shouldCreateSourceAbiDump(ctx) {
|
if library.sabi.shouldCreateSourceAbiDump() {
|
||||||
var vndkVersion string
|
var vndkVersion string
|
||||||
|
|
||||||
if ctx.useVndk() {
|
if ctx.useVndk() {
|
||||||
@@ -1183,7 +1140,7 @@ func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objec
|
|||||||
library.Properties.Header_abi_checker.Exclude_symbol_versions,
|
library.Properties.Header_abi_checker.Exclude_symbol_versions,
|
||||||
library.Properties.Header_abi_checker.Exclude_symbol_tags)
|
library.Properties.Header_abi_checker.Exclude_symbol_tags)
|
||||||
|
|
||||||
addLsdumpPath(library.classifySourceAbiDump(ctx) + ":" + library.sAbiOutputFile.String())
|
addLsdumpPath(classifySourceAbiDump(ctx) + ":" + library.sAbiOutputFile.String())
|
||||||
|
|
||||||
refAbiDumpFile := getRefAbiDumpFile(ctx, vndkVersion, fileName)
|
refAbiDumpFile := getRefAbiDumpFile(ctx, vndkVersion, fileName)
|
||||||
if refAbiDumpFile != nil {
|
if refAbiDumpFile != nil {
|
||||||
|
157
cc/sabi.go
157
cc/sabi.go
@@ -27,8 +27,10 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SAbiProperties struct {
|
type SAbiProperties struct {
|
||||||
// True if need to generate ABI dump.
|
// Whether ABI dump should be created for this module.
|
||||||
CreateSAbiDumps bool `blueprint:"mutated"`
|
// Set by `sabiDepsMutator` if this module is a shared library that needs ABI check, or a static
|
||||||
|
// library that is depended on by an ABI checked library.
|
||||||
|
ShouldCreateSourceAbiDump bool `blueprint:"mutated"`
|
||||||
|
|
||||||
// Include directories that may contain ABI information exported by a library.
|
// Include directories that may contain ABI information exported by a library.
|
||||||
// These directories are passed to the header-abi-dumper.
|
// These directories are passed to the header-abi-dumper.
|
||||||
@@ -39,17 +41,17 @@ type sabi struct {
|
|||||||
Properties SAbiProperties
|
Properties SAbiProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sabimod *sabi) props() []interface{} {
|
func (sabi *sabi) props() []interface{} {
|
||||||
return []interface{}{&sabimod.Properties}
|
return []interface{}{&sabi.Properties}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sabimod *sabi) begin(ctx BaseModuleContext) {}
|
func (sabi *sabi) begin(ctx BaseModuleContext) {}
|
||||||
|
|
||||||
func (sabimod *sabi) deps(ctx BaseModuleContext, deps Deps) Deps {
|
func (sabi *sabi) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags {
|
func (sabi *sabi) flags(ctx ModuleContext, flags Flags) Flags {
|
||||||
// Filter out flags which libTooling don't understand.
|
// Filter out flags which libTooling don't understand.
|
||||||
// This is here for legacy reasons and future-proof, in case the version of libTooling and clang
|
// This is here for legacy reasons and future-proof, in case the version of libTooling and clang
|
||||||
// diverge.
|
// diverge.
|
||||||
@@ -60,37 +62,134 @@ func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldSkipSabiDepsMutator(mctx android.TopDownMutatorContext, m *Module) bool {
|
// Returns true if ABI dump should be created for this library, either because library is ABI
|
||||||
if m.sabi != nil && m.sabi.Properties.CreateSAbiDumps {
|
// checked or is depended on by an ABI checked library.
|
||||||
|
// Could be called as a nil receiver.
|
||||||
|
func (sabi *sabi) shouldCreateSourceAbiDump() bool {
|
||||||
|
return sabi != nil && sabi.Properties.ShouldCreateSourceAbiDump
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns a string that represents the class of the ABI dump.
|
||||||
|
// Returns an empty string if ABI check is disabled for this library.
|
||||||
|
func classifySourceAbiDump(ctx android.BaseModuleContext) string {
|
||||||
|
m := ctx.Module().(*Module)
|
||||||
|
if m.library.headerAbiCheckerExplicitlyDisabled() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
// Return NDK if the library is both NDK and LLNDK.
|
||||||
|
if m.IsNdk(ctx.Config()) {
|
||||||
|
return "NDK"
|
||||||
|
}
|
||||||
|
if m.isLlndkPublic(ctx.Config()) {
|
||||||
|
return "LLNDK"
|
||||||
|
}
|
||||||
|
if m.UseVndk() && m.IsVndk() && !m.IsVndkPrivate(ctx.Config()) {
|
||||||
|
if m.isVndkSp() {
|
||||||
|
if m.IsVndkExt() {
|
||||||
|
return "VNDK-SP-ext"
|
||||||
|
} else {
|
||||||
|
return "VNDK-SP"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if m.IsVndkExt() {
|
||||||
|
return "VNDK-ext"
|
||||||
|
} else {
|
||||||
|
return "VNDK-core"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if m.library.headerAbiCheckerEnabled() || m.library.hasStubsVariants() {
|
||||||
|
return "PLATFORM"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called from sabiDepsMutator to check whether ABI dumps should be created for this module.
|
||||||
|
// ctx should be wrapping a native library type module.
|
||||||
|
func shouldCreateSourceAbiDumpForLibrary(ctx android.BaseModuleContext) bool {
|
||||||
|
if ctx.Fuchsia() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if library, ok := m.linker.(*libraryDecorator); ok {
|
|
||||||
ctx := &baseModuleContext{
|
// Only generate ABI dump for device modules.
|
||||||
BaseModuleContext: mctx,
|
if !ctx.Device() {
|
||||||
moduleContextImpl: moduleContextImpl{
|
return false
|
||||||
mod: m,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
ctx.ctx = ctx
|
|
||||||
return !library.shouldCreateSourceAbiDump(ctx)
|
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
|
m := ctx.Module().(*Module)
|
||||||
|
|
||||||
|
// Only create ABI dump for native library module types.
|
||||||
|
if m.library == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create ABI dump for static libraries only if they are dependencies of ABI checked libraries.
|
||||||
|
if m.library.static() {
|
||||||
|
return m.sabi.shouldCreateSourceAbiDump()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Module is shared library type.
|
||||||
|
|
||||||
|
// Don't create ABI dump for prebuilts.
|
||||||
|
if m.Prebuilt() != nil || m.isSnapshotPrebuilt() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Coverage builds have extra symbols.
|
||||||
|
if m.isCoverageVariant() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some sanitizer variants may have different ABI.
|
||||||
|
if m.sanitize != nil && !m.sanitize.isVariantOnProductionDevice() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't create ABI dump for stubs.
|
||||||
|
if m.isNDKStubLibrary() || m.IsStubs() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Special case for APEX variants.
|
||||||
|
if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() {
|
||||||
|
// Don't create ABI dump if this library is for APEX but isn't exported.
|
||||||
|
if !m.HasStubsVariants() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !m.library.headerAbiCheckerEnabled() {
|
||||||
|
// Skip ABI checks if this library is for APEX and did not explicitly enable
|
||||||
|
// ABI checks.
|
||||||
|
// TODO(b/145608479): ABI checks should be enabled by default. Remove this
|
||||||
|
// after evaluating the extra build time.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return classifySourceAbiDump(ctx) != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the direct and transitive dependencies of libraries that need ABI check, so that ABI dumps
|
// Mark the direct and transitive dependencies of libraries that need ABI check, so that ABI dumps
|
||||||
// of their dependencies would be generated.
|
// of their dependencies would be generated.
|
||||||
func sabiDepsMutator(mctx android.TopDownMutatorContext) {
|
func sabiDepsMutator(mctx android.TopDownMutatorContext) {
|
||||||
if c, ok := mctx.Module().(*Module); ok {
|
// Escape hatch to not check any ABI dump.
|
||||||
if shouldSkipSabiDepsMutator(mctx, c) {
|
if mctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mctx.VisitDirectDeps(func(m android.Module) {
|
// Only create ABI dump for native shared libraries and their static library dependencies.
|
||||||
if tag, ok := mctx.OtherModuleDependencyTag(m).(libraryDependencyTag); ok && tag.static() {
|
if m, ok := mctx.Module().(*Module); ok && m.sabi != nil {
|
||||||
if cc, ok := m.(*Module); ok {
|
if shouldCreateSourceAbiDumpForLibrary(mctx) {
|
||||||
cc.sabi.Properties.CreateSAbiDumps = true
|
// Mark this module so that .sdump / .lsdump for this library can be generated.
|
||||||
|
m.sabi.Properties.ShouldCreateSourceAbiDump = true
|
||||||
|
// Mark all of its static library dependencies.
|
||||||
|
mctx.VisitDirectDeps(func(child android.Module) {
|
||||||
|
depTag := mctx.OtherModuleDependencyTag(child)
|
||||||
|
if libDepTag, ok := depTag.(libraryDependencyTag); ok && libDepTag.static() {
|
||||||
|
if c, ok := child.(*Module); ok && c.sabi != nil {
|
||||||
|
// Mark this module so that .sdump for this static library can be generated.
|
||||||
|
c.sabi.Properties.ShouldCreateSourceAbiDump = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user