aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiyong Park <jiyong@google.com>2021-05-22 07:09:42 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-05-22 07:09:42 +0000
commit23ac240b8f18bd5a6f336131ffa04a44509bcc2e (patch)
treefa2908a0e232d20a4b521e57bbfa3341ffedb76d
parent3dea4eb2a76da7592a1f4678d9934669b65b01ee (diff)
parent7f28709cb293d03207c770a39da48f2eaf5f1579 (diff)
downloadaidl-23ac240b8f18bd5a6f336131ffa04a44509bcc2e.tar.gz
*-freeze-api does nothing when current == latest stable version am: 7f28709cb2
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/tools/aidl/+/14661881 Change-Id: Ic583e102c811bc7495ab1b35aa52b76786b39270
-rw-r--r--build/aidl_api.go74
1 files changed, 57 insertions, 17 deletions
diff --git a/build/aidl_api.go b/build/aidl_api.go
index 60976687..02290412 100644
--- a/build/aidl_api.go
+++ b/build/aidl_api.go
@@ -148,28 +148,64 @@ func (m *aidlApi) createApiDumpFromSource(ctx android.ModuleContext) apiDump {
return apiDump{apiDir, apiFiles.Paths(), android.OptionalPathForPath(hashFile)}
}
-func (m *aidlApi) makeApiDumpAsVersion(ctx android.ModuleContext, dump apiDump, version string) android.WritablePath {
- timestampFile := android.PathForModuleOut(ctx, "updateapi_"+version+".timestamp")
+func (m *aidlApi) makeApiDumpAsVersion(ctx android.ModuleContext, dump apiDump, version string, latestVersionDump *apiDump) android.WritablePath {
+ creatingNewVersion := version != currentVersion
+ moduleDir := android.PathForModuleSrc(ctx).String()
+ targetDir := filepath.Join(moduleDir, m.apiDir(), version)
+ rb := android.NewRuleBuilder(pctx, ctx)
- modulePath := android.PathForModuleSrc(ctx).String()
+ if creatingNewVersion {
+ // We are asked to create a new version. But before doing that, check if the given
+ // dump is the same as the latest version. If so, don't create a new version,
+ // otherwise we will be unnecessarily creating many versions. `newVersionNeededFile`
+ // is created when the equality check fails.
+ newVersionNeededFile := android.PathForModuleOut(ctx, "updateapi_"+version+".needed")
+ rb.Command().Text("rm -f " + newVersionNeededFile.String())
+
+ if latestVersionDump != nil {
+ equalityCheckCommand := rb.Command()
+ equalityCheckCommand.BuiltTool("aidl").
+ FlagWithArg("--checkapi=", "equal")
+ if m.properties.Stability != nil {
+ equalityCheckCommand.FlagWithArg("--stability ", *m.properties.Stability)
+ }
+ equalityCheckCommand.
+ Text(latestVersionDump.dir.String()).Implicits(latestVersionDump.files).
+ Text(dump.dir.String()).Implicits(dump.files).
+ Text("&> /dev/null")
+ equalityCheckCommand.
+ Text("|| touch").
+ Text(newVersionNeededFile.String())
+ } else {
+ // If there is no latest version (i.e. we are creating the initial version)
+ // create the new version unconditionally
+ rb.Command().Text("touch").Text(newVersionNeededFile.String())
+ }
- targetDir := filepath.Join(modulePath, m.apiDir(), version)
- rb := android.NewRuleBuilder(pctx, ctx)
- // Wipe the target directory and then copy the API dump into the directory
- rb.Command().Text("mkdir -p " + targetDir)
- rb.Command().Text("rm -rf " + targetDir + "/*")
- if version != currentVersion {
- rb.Command().Text("cp -rf " + dump.dir.String() + "/. " + targetDir).Implicits(dump.files)
- // If this is making a new frozen (i.e. non-current) version of the interface,
- // modify Android.bp file to add the new version to the 'versions' property.
- rb.Command().BuiltTool("bpmodify").
+ // Copy the given dump to the target directory only when the equality check failed
+ // (i.e. `newVersionNeededFile` exists).
+ rb.Command().
+ Text("if [ -f " + newVersionNeededFile.String() + " ]; then").
+ Text("cp -rf " + dump.dir.String() + "/. " + targetDir).Implicits(dump.files).
+ Text("; fi")
+
+ // Also modify Android.bp file to add the new version to the 'versions' property.
+ rb.Command().
+ Text("if [ -f " + newVersionNeededFile.String() + " ]; then").
+ BuiltTool("bpmodify").
Text("-w -m " + m.properties.BaseName).
Text("-parameter versions -a " + version).
- Text(android.PathForModuleSrc(ctx, "Android.bp").String())
+ Text(android.PathForModuleSrc(ctx, "Android.bp").String()).
+ Text("; fi")
+
} else {
- // In this case (unfrozen interface), don't copy .hash
+ // We are updating the current version. Don't copy .hash to the current dump
+ rb.Command().Text("mkdir -p " + targetDir)
+ rb.Command().Text("rm -rf " + targetDir + "/*")
rb.Command().Text("cp -rf " + dump.dir.String() + "/* " + targetDir).Implicits(dump.files)
}
+
+ timestampFile := android.PathForModuleOut(ctx, "updateapi_"+version+".timestamp")
rb.Command().Text("touch").Output(timestampFile)
rb.Build("dump_aidl_api"+m.properties.BaseName+"_"+version,
@@ -311,6 +347,10 @@ func (m *aidlApi) GenerateAndroidBuildActions(ctx android.ModuleContext) {
ctx.ModuleErrorf("API version %s path %s does not exist", ver, apiDir)
}
}
+ var latestVersionDump *apiDump
+ if len(dumps) >= 1 {
+ latestVersionDump = &dumps[len(dumps)-1]
+ }
if currentApiDir.Valid() {
dumps = append(dumps, currentApiDump)
}
@@ -328,11 +368,11 @@ func (m *aidlApi) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}
// API dump from source is updated to the 'current' version. Triggered by `m <name>-update-api`
- m.updateApiTimestamp = m.makeApiDumpAsVersion(ctx, totApiDump, currentVersion)
+ m.updateApiTimestamp = m.makeApiDumpAsVersion(ctx, totApiDump, currentVersion, nil)
// API dump from source is frozen as the next stable version. Triggered by `m <name>-freeze-api`
nextVersion := m.nextVersion()
- m.freezeApiTimestamp = m.makeApiDumpAsVersion(ctx, totApiDump, nextVersion)
+ m.freezeApiTimestamp = m.makeApiDumpAsVersion(ctx, totApiDump, nextVersion, latestVersionDump)
}
func (m *aidlApi) AndroidMk() android.AndroidMkData {