Refactor header ABI checker code

- Extract duplicate code into exportedIncludeDirsForAbiCheck.
- Convert libraryDecorator.sAbiOutputFile to a local variable.

Test: make
Bug: 314010764
Change-Id: I99a0352b11347ad363df5645ba8e0faf9bc9a0aa
This commit is contained in:
Hsin-Yi Chen 2024-03-29 20:10:36 +08:00
parent 6954bd2337
commit af369886e5
2 changed files with 35 additions and 45 deletions

View file

@ -854,14 +854,15 @@ func transformObjToDynamicBinary(ctx android.ModuleContext,
// Generate a rule to combine .dump sAbi dump files from multiple source files
// into a single .ldump sAbi dump file
func transformDumpToLinkedDump(ctx android.ModuleContext, sAbiDumps android.Paths, soFile android.Path,
baseName, exportedHeaderFlags string, symbolFile android.OptionalPath,
baseName string, exportedIncludeDirs []string, symbolFile android.OptionalPath,
excludedSymbolVersions, excludedSymbolTags []string,
api string) android.OptionalPath {
api string) android.Path {
outputFile := android.PathForModuleOut(ctx, baseName+".lsdump")
implicits := android.Paths{soFile}
symbolFilterStr := "-so " + soFile.String()
exportedHeaderFlags := android.JoinWithPrefix(exportedIncludeDirs, "-I")
if symbolFile.Valid() {
implicits = append(implicits, symbolFile.Path())
@ -886,13 +887,7 @@ func transformDumpToLinkedDump(ctx android.ModuleContext, sAbiDumps android.Path
}
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_ABI_LINKER") {
rule = sAbiLinkRE
rbeImplicits := implicits.Strings()
for _, p := range strings.Split(exportedHeaderFlags, " ") {
if len(p) > 2 {
// Exclude the -I prefix.
rbeImplicits = append(rbeImplicits, p[2:])
}
}
rbeImplicits := append(implicits.Strings(), exportedIncludeDirs...)
args["implicitInputs"] = strings.Join(rbeImplicits, ",")
}
ctx.Build(pctx, android.BuildParams{
@ -903,7 +898,7 @@ func transformDumpToLinkedDump(ctx android.ModuleContext, sAbiDumps android.Path
Implicits: implicits,
Args: args,
})
return android.OptionalPathForPath(outputFile)
return outputFile
}
func transformAbiDumpToAbiDiff(ctx android.ModuleContext, inputDump, referenceDump android.Path,

View file

@ -390,9 +390,6 @@ type libraryDecorator struct {
// Output archive of gcno coverage information files
coverageOutputFile android.OptionalPath
// linked Source Abi Dump
sAbiOutputFile android.OptionalPath
// Source Abi Diff
sAbiDiff android.Paths
@ -756,15 +753,11 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
return Objects{}
}
if library.sabi.shouldCreateSourceAbiDump() {
exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
var SourceAbiFlags []string
for _, dir := range exportIncludeDirs.Strings() {
SourceAbiFlags = append(SourceAbiFlags, "-I"+dir)
dirs := library.exportedIncludeDirsForAbiCheck(ctx)
flags.SAbiFlags = make([]string, 0, len(dirs))
for _, dir := range dirs {
flags.SAbiFlags = append(flags.SAbiFlags, "-I"+dir)
}
for _, reexportedInclude := range library.sabi.Properties.ReexportedIncludes {
SourceAbiFlags = append(SourceAbiFlags, "-I"+reexportedInclude)
}
flags.SAbiFlags = SourceAbiFlags
totalLength := len(library.baseCompiler.Properties.Srcs) + len(deps.GeneratedSources) +
len(library.SharedProperties.Shared.Srcs) + len(library.StaticProperties.Static.Srcs)
if totalLength > 0 {
@ -1338,6 +1331,12 @@ func (library *libraryDecorator) coverageOutputFilePath() android.OptionalPath {
return library.coverageOutputFile
}
func (library *libraryDecorator) exportedIncludeDirsForAbiCheck(ctx ModuleContext) []string {
exportIncludeDirs := library.flagExporter.exportedIncludes(ctx).Strings()
exportIncludeDirs = append(exportIncludeDirs, library.sabi.Properties.ReexportedIncludes...)
return exportIncludeDirs
}
func getRefAbiDumpFile(ctx android.ModuleInstallPathContext,
versionedDumpDir, fileName string) android.OptionalPath {
@ -1384,12 +1383,11 @@ func currRefAbiDumpSdkVersion(ctx ModuleContext) string {
}
// sourceAbiDiff registers a build statement to compare linked sAbi dump files (.lsdump).
func (library *libraryDecorator) sourceAbiDiff(ctx android.ModuleContext, referenceDump android.Path,
func (library *libraryDecorator) sourceAbiDiff(ctx android.ModuleContext,
sourceDump, referenceDump android.Path,
baseName, nameExt string, isLlndkOrNdk, allowExtensions bool,
sourceVersion, errorMessage string) {
sourceDump := library.sAbiOutputFile.Path()
extraFlags := []string{"-target-version", sourceVersion}
headerAbiChecker := library.getHeaderAbiCheckerProperties(ctx)
if Bool(headerAbiChecker.Check_all_apis) {
@ -1413,26 +1411,29 @@ func (library *libraryDecorator) sourceAbiDiff(ctx android.ModuleContext, refere
baseName, nameExt, extraFlags, errorMessage))
}
func (library *libraryDecorator) crossVersionAbiDiff(ctx android.ModuleContext, referenceDump android.Path,
func (library *libraryDecorator) crossVersionAbiDiff(ctx android.ModuleContext,
sourceDump, referenceDump android.Path,
baseName string, isLlndkOrNdk bool, sourceVersion, prevVersion string) {
errorMessage := "error: Please follow https://android.googlesource.com/platform/development/+/main/vndk/tools/header-checker/README.md#configure-cross_version-abi-check to resolve the ABI difference between your source code and version " + prevVersion + "."
library.sourceAbiDiff(ctx, referenceDump, baseName, prevVersion,
library.sourceAbiDiff(ctx, sourceDump, referenceDump, baseName, prevVersion,
isLlndkOrNdk, true /* allowExtensions */, sourceVersion, errorMessage)
}
func (library *libraryDecorator) sameVersionAbiDiff(ctx android.ModuleContext, referenceDump android.Path,
func (library *libraryDecorator) sameVersionAbiDiff(ctx android.ModuleContext,
sourceDump, referenceDump android.Path,
baseName, nameExt string, isLlndkOrNdk bool) {
libName := strings.TrimSuffix(baseName, filepath.Ext(baseName))
errorMessage := "error: Please update ABI references with: $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py -l " + libName
library.sourceAbiDiff(ctx, referenceDump, baseName, nameExt,
library.sourceAbiDiff(ctx, sourceDump, referenceDump, baseName, nameExt,
isLlndkOrNdk, false /* allowExtensions */, "current", errorMessage)
}
func (library *libraryDecorator) optInAbiDiff(ctx android.ModuleContext, referenceDump android.Path,
func (library *libraryDecorator) optInAbiDiff(ctx android.ModuleContext,
sourceDump, referenceDump android.Path,
baseName, nameExt string, refDumpDir string) {
libName := strings.TrimSuffix(baseName, filepath.Ext(baseName))
@ -1442,33 +1443,26 @@ func (library *libraryDecorator) optInAbiDiff(ctx android.ModuleContext, referen
errorMessage += " -products " + ctx.Config().DeviceProduct()
}
library.sourceAbiDiff(ctx, referenceDump, baseName, nameExt,
library.sourceAbiDiff(ctx, sourceDump, referenceDump, baseName, nameExt,
false /* isLlndkOrNdk */, false /* allowExtensions */, "current", errorMessage)
}
func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string, soFile android.Path) {
if library.sabi.shouldCreateSourceAbiDump() {
exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
var SourceAbiFlags []string
for _, dir := range exportIncludeDirs.Strings() {
SourceAbiFlags = append(SourceAbiFlags, "-I"+dir)
}
for _, reexportedInclude := range library.sabi.Properties.ReexportedIncludes {
SourceAbiFlags = append(SourceAbiFlags, "-I"+reexportedInclude)
}
exportedHeaderFlags := strings.Join(SourceAbiFlags, " ")
exportedIncludeDirs := library.exportedIncludeDirsForAbiCheck(ctx)
headerAbiChecker := library.getHeaderAbiCheckerProperties(ctx)
currSdkVersion := currRefAbiDumpSdkVersion(ctx)
currVendorVersion := ctx.Config().VendorApiLevel()
library.sAbiOutputFile = transformDumpToLinkedDump(ctx, objs.sAbiDumpFiles, soFile, fileName, exportedHeaderFlags,
sourceDump := transformDumpToLinkedDump(ctx,
objs.sAbiDumpFiles, soFile, fileName,
exportedIncludeDirs,
android.OptionalPathForModuleSrc(ctx, library.symbolFileForAbiCheck(ctx)),
headerAbiChecker.Exclude_symbol_versions,
headerAbiChecker.Exclude_symbol_tags,
currSdkVersion)
for _, tag := range classifySourceAbiDump(ctx) {
addLsdumpPath(string(tag) + ":" + library.sAbiOutputFile.String())
addLsdumpPath(string(tag) + ":" + sourceDump.String())
dumpDirName := tag.dirName()
if dumpDirName == "" {
continue
@ -1493,7 +1487,7 @@ func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objec
prevDumpDir := filepath.Join(dumpDir, prevVersion, binderBitness)
prevDumpFile := getRefAbiDumpFile(ctx, prevDumpDir, fileName)
if prevDumpFile.Valid() {
library.crossVersionAbiDiff(ctx, prevDumpFile.Path(),
library.crossVersionAbiDiff(ctx, sourceDump, prevDumpFile.Path(),
fileName, isLlndk || isNdk, currVersion, nameExt+prevVersion)
}
// Check against the current version.
@ -1505,7 +1499,7 @@ func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objec
currDumpDir := filepath.Join(dumpDir, currVersion, binderBitness)
currDumpFile := getRefAbiDumpFile(ctx, currDumpDir, fileName)
if currDumpFile.Valid() {
library.sameVersionAbiDiff(ctx, currDumpFile.Path(),
library.sameVersionAbiDiff(ctx, sourceDump, currDumpFile.Path(),
fileName, nameExt, isLlndk || isNdk)
}
}
@ -1518,7 +1512,8 @@ func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objec
if !optInDumpFile.Valid() {
continue
}
library.optInAbiDiff(ctx, optInDumpFile.Path(),
library.optInAbiDiff(ctx,
sourceDump, optInDumpFile.Path(),
fileName, "opt"+strconv.Itoa(i), optInDumpDirPath.String())
}
}