Sort modules before writing to Android.mk
Sort the modules before writing them to the Android.mk file to prevent
it changing every time soong rebuilts itself. Avoids unnecessary
makefile reparses by kati when it sees Android.mk change.
Change-Id: Ie2cebb25a82d131ee5b556f8e4b3b317d080692c
diff --git a/common/module.go b/common/module.go
index a3de5f6..a2b2efa 100644
--- a/common/module.go
+++ b/common/module.go
@@ -632,3 +632,24 @@
})
}
}
+
+type AndroidModulesByName struct {
+ slice []AndroidModule
+ ctx interface {
+ ModuleName(blueprint.Module) string
+ ModuleSubDir(blueprint.Module) string
+ }
+}
+
+func (s AndroidModulesByName) Len() int { return len(s.slice) }
+func (s AndroidModulesByName) Less(i, j int) bool {
+ mi, mj := s.slice[i], s.slice[j]
+ ni, nj := s.ctx.ModuleName(mi), s.ctx.ModuleName(mj)
+
+ if ni != nj {
+ return ni < nj
+ } else {
+ return s.ctx.ModuleSubDir(mi) < s.ctx.ModuleSubDir(mj)
+ }
+}
+func (s AndroidModulesByName) Swap(i, j int) { s.slice[i], s.slice[j] = s.slice[j], s.slice[i] }