Sort/unique dists in soong instead of make
The packaging step actually takes a noticable second or two to run
kati, optimize it a little bit by uniquing the lists in soong instead
of make. This also makes it less for soong to write out.
Bug: 388312357
Test: m --soong-only droid dist
Change-Id: I8568094e252d9fa14543b67de588d9efdf1ddf40
diff --git a/android/androidmk.go b/android/androidmk.go
index 9e721e1..8e2bdcd 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -746,22 +746,31 @@
distMkFile := absolutePath(filepath.Join(ctx.Config().katiPackageMkDir(), "dist.mk"))
var goalOutputPairs []string
- var buf strings.Builder
- buf.WriteString("DIST_SRC_DST_PAIRS := $(sort")
+ var srcDstPairs []string
for _, contributions := range allDistContributions {
for _, copiesForGoal := range contributions.copiesForGoals {
goals := strings.Fields(copiesForGoal.goals)
for _, copy := range copiesForGoal.copies {
for _, goal := range goals {
- goalOutputPairs = append(goalOutputPairs, fmt.Sprintf("%s:%s", goal, copy.dest))
+ goalOutputPairs = append(goalOutputPairs, fmt.Sprintf(" %s:%s", goal, copy.dest))
}
- buf.WriteString(fmt.Sprintf(" %s:%s", copy.from.String(), copy.dest))
+ srcDstPairs = append(srcDstPairs, fmt.Sprintf(" %s:%s", copy.from.String(), copy.dest))
}
}
}
- buf.WriteString(")\nDIST_GOAL_OUTPUT_PAIRS := $(sort ")
- buf.WriteString(strings.Join(goalOutputPairs, " "))
- buf.WriteString(")\n")
+ // There are duplicates in the lists that we need to remove
+ goalOutputPairs = SortedUniqueStrings(goalOutputPairs)
+ srcDstPairs = SortedUniqueStrings(srcDstPairs)
+ var buf strings.Builder
+ buf.WriteString("DIST_SRC_DST_PAIRS :=")
+ for _, srcDstPair := range srcDstPairs {
+ buf.WriteString(srcDstPair)
+ }
+ buf.WriteString("\nDIST_GOAL_OUTPUT_PAIRS :=")
+ for _, goalOutputPair := range goalOutputPairs {
+ buf.WriteString(goalOutputPair)
+ }
+ buf.WriteString("\n")
writeValueIfChanged(ctx, distMkFile, buf.String())
}