Make APEX build rules consistent

Don't directly iterate over the copyManifest map to generate the copy
commands. Iterating over a map in golang isn't guaranteed to give
consistent order. This causes the apex build rules to be executed even
when there is no source file change.

Fix the issue by creating a sorted list of the key and then iterate over
the list.

Bug: 117453592
Test: m apex.test; m.apex.test   nothing is built during the second
build

Change-Id: I329a91ec0b6a34cbe745bf9a9ceb0843b63c200c
This commit is contained in:
Jiyong Park
2018-10-10 14:05:29 +09:00
parent 48ca7dc535
commit ab3ceb3855

View File

@@ -19,6 +19,7 @@ import (
"io" "io"
"path/filepath" "path/filepath"
"runtime" "runtime"
"sort"
"strings" "strings"
"android/soong/android" "android/soong/android"
@@ -309,6 +310,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
pathsInApex = append(pathsInApex, dirInApex) pathsInApex = append(pathsInApex, dirInApex)
} }
} }
sort.Strings(pathsInApex)
cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config") cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config")
ctx.ModuleBuild(pctx, android.ModuleBuildParams{ ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Rule: generateFsConfig, Rule: generateFsConfig,
@@ -325,17 +327,22 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.outputFile = android.PathForModuleOut(ctx, a.ModuleBase.Name()+apexSuffix) a.outputFile = android.PathForModuleOut(ctx, a.ModuleBase.Name()+apexSuffix)
implicitInputs := []android.Path{} filesToCopy := []android.Path{}
for file := range copyManifest { for file := range copyManifest {
implicitInputs = append(implicitInputs, file) filesToCopy = append(filesToCopy, file)
} }
sort.Slice(filesToCopy, func(i, j int) bool {
return filesToCopy[i].String() < filesToCopy[j].String()
})
copyCommands := []string{} copyCommands := []string{}
for src, dir := range copyManifest { for _, src := range filesToCopy {
dest := filepath.Join(dir, src.Base()) dest := filepath.Join(copyManifest[src], src.Base())
dest_path := filepath.Join(android.PathForModuleOut(ctx, "image").String(), dest) dest_path := filepath.Join(android.PathForModuleOut(ctx, "image").String(), dest)
copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path)) copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path) copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
} }
implicitInputs := append(android.Paths(nil), filesToCopy...)
implicitInputs = append(implicitInputs, cannedFsConfig, manifest, fileContexts, key) implicitInputs = append(implicitInputs, cannedFsConfig, manifest, fileContexts, key)
outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String() outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin") prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")