From ab3ceb38552c69b8042b75c95b2826c8ecf413e5 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Wed, 10 Oct 2018 14:05:29 +0900 Subject: [PATCH] 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 --- apex/apex.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 51e240148..0749ab3bb 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -19,6 +19,7 @@ import ( "io" "path/filepath" "runtime" + "sort" "strings" "android/soong/android" @@ -309,6 +310,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { pathsInApex = append(pathsInApex, dirInApex) } } + sort.Strings(pathsInApex) cannedFsConfig := android.PathForModuleOut(ctx, "canned_fs_config") ctx.ModuleBuild(pctx, android.ModuleBuildParams{ Rule: generateFsConfig, @@ -325,17 +327,22 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.outputFile = android.PathForModuleOut(ctx, a.ModuleBase.Name()+apexSuffix) - implicitInputs := []android.Path{} + filesToCopy := []android.Path{} 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{} - for src, dir := range copyManifest { - dest := filepath.Join(dir, src.Base()) + for _, src := range filesToCopy { + dest := filepath.Join(copyManifest[src], src.Base()) dest_path := filepath.Join(android.PathForModuleOut(ctx, "image").String(), dest) copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path)) copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path) } + implicitInputs := append(android.Paths(nil), filesToCopy...) implicitInputs = append(implicitInputs, cannedFsConfig, manifest, fileContexts, key) outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String() prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")