Change the type of parameter prevVersion to int in sourceAbiDump
Since the caller is doing Itoa and pass it into sourceAbiDump(), and
sourceAbiDump() is calling Atoi to convert it back, it makes sense to
not do the Itoa in the first place.
Test: make libz
Bug: 244009549
Change-Id: I61731a5eb442b5a1a8f50c820a673d9b2204c3a0
diff --git a/cc/builder.go b/cc/builder.go
index 35ae69b..a552553 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -920,14 +920,14 @@
// sourceAbiDiff registers a build statement to compare linked sAbi dump files (.lsdump).
func sourceAbiDiff(ctx android.ModuleContext, inputDump android.Path, referenceDump android.Path,
- baseName, prevVersion, exportedHeaderFlags string, diffFlags []string,
+ baseName, exportedHeaderFlags string, diffFlags []string, prevVersion int,
checkAllApis, isLlndk, isNdk, isVndkExt, previousVersionDiff bool) android.OptionalPath {
var outputFile android.ModuleOutPath
- if prevVersion == "" {
- outputFile = android.PathForModuleOut(ctx, baseName+".abidiff")
+ if previousVersionDiff {
+ outputFile = android.PathForModuleOut(ctx, baseName+"."+strconv.Itoa(prevVersion)+".abidiff")
} else {
- outputFile = android.PathForModuleOut(ctx, baseName+"."+prevVersion+".abidiff")
+ outputFile = android.PathForModuleOut(ctx, baseName+".abidiff")
}
libName := strings.TrimSuffix(baseName, filepath.Ext(baseName))
@@ -946,12 +946,9 @@
if previousVersionDiff {
// TODO(b/241496591): Remove -advice-only after b/239792343 and b/239790286 are reolved.
extraFlags = append(extraFlags, "-advice-only")
- errorMessage = "error: Please follow development/vndk/tools/header-checker/README.md to ensure the ABI compatibility between your source code and version " + prevVersion + "."
- // The prevVersion is expected as a string of int, skip it if not.
- if prevVersionInt, err := strconv.Atoi(prevVersion); err == nil {
- sourceVersion := strconv.Itoa(prevVersionInt + 1)
- extraFlags = append(extraFlags, "-target-version", sourceVersion)
- }
+ errorMessage = "error: Please follow development/vndk/tools/header-checker/README.md to ensure the ABI compatibility between your source code and version " + strconv.Itoa(prevVersion) + "."
+ sourceVersion := prevVersion + 1
+ extraFlags = append(extraFlags, "-target-version", strconv.Itoa(sourceVersion))
} else {
errorMessage = "error: Please update ABI references with: $ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py -l " + libName
extraFlags = append(extraFlags, "-target-version", "current")
diff --git a/cc/library.go b/cc/library.go
index 41dca01..c8ce6a5 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1623,12 +1623,12 @@
return nil
}
-func prevDumpRefVersion(ctx ModuleContext) string {
+func prevDumpRefVersion(ctx ModuleContext) int {
sdkVersionInt := ctx.Config().PlatformSdkVersion().FinalInt()
sdkVersionStr := ctx.Config().PlatformSdkVersion().String()
if ctx.Config().PlatformSdkFinal() {
- return strconv.Itoa(sdkVersionInt - 1)
+ return sdkVersionInt - 1
} else {
var dirName string
@@ -1644,9 +1644,9 @@
// This situation could be identified by checking the existence of the PLATFORM_SDK_VERION dump directory.
refDumpDir := android.ExistentPathForSource(ctx, "prebuilts", "abi-dumps", dirName, sdkVersionStr)
if refDumpDir.Valid() {
- return sdkVersionStr
+ return sdkVersionInt
} else {
- return strconv.Itoa(sdkVersionInt - 1)
+ return sdkVersionInt - 1
}
}
}
@@ -1654,7 +1654,7 @@
func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string, soFile android.Path) {
if library.sabi.shouldCreateSourceAbiDump() {
var version string
- var prevVersion string
+ var prevVersion int
if ctx.useVndk() {
// For modules linking against vndk, follow its vndk version
@@ -1686,12 +1686,13 @@
addLsdumpPath(classifySourceAbiDump(ctx) + ":" + library.sAbiOutputFile.String())
- if prevVersion != "" {
- prevRefAbiDumpFile := getRefAbiDumpFile(ctx, prevVersion, fileName)
+ // If NDK or PLATFORM library, check against previous version ABI.
+ if !ctx.useVndk() {
+ prevRefAbiDumpFile := getRefAbiDumpFile(ctx, strconv.Itoa(prevVersion), fileName)
if prevRefAbiDumpFile != nil {
library.prevSAbiDiff = sourceAbiDiff(ctx, library.sAbiOutputFile.Path(),
- prevRefAbiDumpFile, fileName, prevVersion, exportedHeaderFlags,
- library.Properties.Header_abi_checker.Diff_flags,
+ prevRefAbiDumpFile, fileName, exportedHeaderFlags,
+ library.Properties.Header_abi_checker.Diff_flags, prevVersion,
Bool(library.Properties.Header_abi_checker.Check_all_apis),
ctx.IsLlndk(), ctx.isNdk(ctx.Config()), ctx.IsVndkExt(), true)
}
@@ -1700,8 +1701,9 @@
refAbiDumpFile := getRefAbiDumpFile(ctx, version, fileName)
if refAbiDumpFile != nil {
library.sAbiDiff = sourceAbiDiff(ctx, library.sAbiOutputFile.Path(),
- refAbiDumpFile, fileName, "", exportedHeaderFlags,
+ refAbiDumpFile, fileName, exportedHeaderFlags,
library.Properties.Header_abi_checker.Diff_flags,
+ /* unused if not previousVersionDiff */ 0,
Bool(library.Properties.Header_abi_checker.Check_all_apis),
ctx.IsLlndk(), ctx.isNdk(ctx.Config()), ctx.IsVndkExt(), false)
}