diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-05-22 23:09:26 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-05-22 23:09:26 +0000 |
commit | 5253cb0f381e223d635a25eec1437938af2c3ccc (patch) | |
tree | fa2908a0e232d20a4b521e57bbfa3341ffedb76d | |
parent | e31f6cfe808ff8eb5140165f789d1e2591019348 (diff) | |
parent | 23ac240b8f18bd5a6f336131ffa04a44509bcc2e (diff) | |
download | aidl-5253cb0f381e223d635a25eec1437938af2c3ccc.tar.gz |
Snap for 7390572 from 23ac240b8f18bd5a6f336131ffa04a44509bcc2e to sc-d2-release
Change-Id: Iec334c6e7ff59f88acb3b31c9a7182c56a03cb1f
-rw-r--r-- | build/Android.mk | 18 | ||||
-rw-r--r-- | build/aidl_api.go | 97 | ||||
-rw-r--r-- | build/aidl_mapping.go | 12 |
3 files changed, 80 insertions, 47 deletions
diff --git a/build/Android.mk b/build/Android.mk deleted file mode 100644 index e50f7028..00000000 --- a/build/Android.mk +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright (C) 2019 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -.PHONY: aidl-freeze-api -aidl-freeze-api: $(addsuffix -freeze-api, $(SOONG_ALL_AIDL_INTERFACES)) diff --git a/build/aidl_api.go b/build/aidl_api.go index 3ce72ae1..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 { @@ -377,3 +417,26 @@ func addApiModule(mctx android.LoadHookContext, i *aidlInterface) string { }) return apiModule } + +func init() { + android.RegisterSingletonType("aidl-freeze-api", freezeApiSingletonFactory) +} + +func freezeApiSingletonFactory() android.Singleton { + return &freezeApiSingleton{} +} + +type freezeApiSingleton struct{} + +func (f *freezeApiSingleton) GenerateBuildActions(ctx android.SingletonContext) { + var files android.Paths + ctx.VisitAllModules(func(module android.Module) { + if !module.Enabled() { + return + } + if m, ok := module.(*aidlApi); ok { + files = append(files, m.freezeApiTimestamp) + } + }) + ctx.Phony("aidl-freeze-api", files...) +} diff --git a/build/aidl_mapping.go b/build/aidl_mapping.go index b48e61e6..b9194955 100644 --- a/build/aidl_mapping.go +++ b/build/aidl_mapping.go @@ -19,7 +19,6 @@ import ( "fmt" "io" - "strings" "github.com/google/blueprint" ) @@ -35,7 +34,6 @@ var ( func init() { android.RegisterModuleType("aidl_mapping", aidlMappingFactory) - android.RegisterMakeVarsProvider(pctx, allAidlInterfacesMakeVars) } type aidlMappingProperties struct { @@ -90,13 +88,3 @@ func (m *aidlMapping) AndroidMk() android.AndroidMkData { }, } } - -func allAidlInterfacesMakeVars(ctx android.MakeVarsContext) { - names := []string{} - ctx.VisitAllModules(func(module android.Module) { - if ai, ok := module.(*aidlInterface); ok { - names = append(names, ai.BaseModuleName()) - } - }) - ctx.Strict("ALL_AIDL_INTERFACES", strings.Join(names, " ")) -} |