Sort modules and singletons for output.

This change causes the module and singleton content in generated Ninja files to
be sorted by name.

Change-Id: I6e1fe6d4211111c7dfa25ebe0fc721701a6d0256
diff --git a/blueprint/context.go b/blueprint/context.go
index d8e6620..9ecaef1 100644
--- a/blueprint/context.go
+++ b/blueprint/context.go
@@ -1183,6 +1183,22 @@
 	return nil
 }
 
+type moduleInfoSorter []*moduleInfo
+
+func (s moduleInfoSorter) Len() int {
+	return len(s)
+}
+
+func (s moduleInfoSorter) Less(i, j int) bool {
+	iName := s[i].properties.Name
+	jName := s[j].properties.Name
+	return iName < jName
+}
+
+func (s moduleInfoSorter) Swap(i, j int) {
+	s[i], s[j] = s[j], s[i]
+}
+
 func (c *Context) writeAllModuleActions(nw *ninjaWriter) error {
 	headerTemplate := template.New("moduleHeader")
 	_, err := headerTemplate.Parse(moduleHeaderTemplate)
@@ -1191,9 +1207,15 @@
 		panic(err)
 	}
 
+	infos := make([]*moduleInfo, 0, len(c.moduleInfo))
+	for _, info := range c.moduleInfo {
+		infos = append(infos, info)
+	}
+	sort.Sort(moduleInfoSorter(infos))
+
 	buf := bytes.NewBuffer(nil)
 
-	for _, info := range c.moduleInfo {
+	for _, info := range infos {
 		buf.Reset()
 
 		// In order to make the bootstrap build manifest independent of the
@@ -1247,7 +1269,15 @@
 
 	buf := bytes.NewBuffer(nil)
 
-	for name, info := range c.singletonInfo {
+	singletonNames := make([]string, 0, len(c.singletonInfo))
+	for name := range c.singletonInfo {
+		singletonNames = append(singletonNames, name)
+	}
+	sort.Strings(singletonNames)
+
+	for _, name := range singletonNames {
+		info := c.singletonInfo[name]
+
 		buf.Reset()
 		infoMap := map[string]interface{}{
 			"name":       name,
diff --git a/build.ninja.in b/build.ninja.in
index 40dc1db..ee3eae6 100644
--- a/build.ninja.in
+++ b/build.ninja.in
@@ -81,6 +81,28 @@
     prefix = .bootstrap/blueprint/pkg
 
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# Module:  blueprint-bootstrap
+# Type:    bootstrap_go_package
+# GoType:  blueprint/bootstrap.goPackageModule
+# Defined: Blueprints:30:1
+
+build .bootstrap/blueprint-bootstrap/obj/_go_.${g.bootstrap.GoChar}: $
+        g.bootstrap.gc ${g.bootstrap.SrcDir}/blueprint/bootstrap/bootstrap.go $
+        ${g.bootstrap.SrcDir}/blueprint/bootstrap/command.go $
+        ${g.bootstrap.SrcDir}/blueprint/bootstrap/config.go $
+        ${g.bootstrap.SrcDir}/blueprint/bootstrap/doc.go | $
+        .bootstrap/blueprint-parser/pkg/blueprint/parser.a $
+        .bootstrap/blueprint/pkg/blueprint.a $
+        .bootstrap/blueprint-pathtools/pkg/blueprint/pathtools.a
+    pkgPath = blueprint/bootstrap
+    incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-pathtools/pkg
+
+build .bootstrap/blueprint-bootstrap/pkg/blueprint/bootstrap.a: $
+        g.bootstrap.pack $
+        .bootstrap/blueprint-bootstrap/obj/_go_.${g.bootstrap.GoChar}
+    prefix = .bootstrap/blueprint-bootstrap/pkg
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 # Module:  blueprint-parser
 # Type:    bootstrap_go_package
 # GoType:  blueprint/bootstrap.goPackageModule
@@ -110,28 +132,6 @@
     prefix = .bootstrap/blueprint-pathtools/pkg
 
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-# Module:  blueprint-bootstrap
-# Type:    bootstrap_go_package
-# GoType:  blueprint/bootstrap.goPackageModule
-# Defined: Blueprints:30:1
-
-build .bootstrap/blueprint-bootstrap/obj/_go_.${g.bootstrap.GoChar}: $
-        g.bootstrap.gc ${g.bootstrap.SrcDir}/blueprint/bootstrap/bootstrap.go $
-        ${g.bootstrap.SrcDir}/blueprint/bootstrap/command.go $
-        ${g.bootstrap.SrcDir}/blueprint/bootstrap/config.go $
-        ${g.bootstrap.SrcDir}/blueprint/bootstrap/doc.go | $
-        .bootstrap/blueprint-parser/pkg/blueprint/parser.a $
-        .bootstrap/blueprint/pkg/blueprint.a $
-        .bootstrap/blueprint-pathtools/pkg/blueprint/pathtools.a
-    pkgPath = blueprint/bootstrap
-    incFlags = -I .bootstrap/blueprint-parser/pkg -I .bootstrap/blueprint/pkg -I .bootstrap/blueprint-pathtools/pkg
-
-build .bootstrap/blueprint-bootstrap/pkg/blueprint/bootstrap.a: $
-        g.bootstrap.pack $
-        .bootstrap/blueprint-bootstrap/obj/_go_.${g.bootstrap.GoChar}
-    prefix = .bootstrap/blueprint-bootstrap/pkg
-
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 # Module:  minibp
 # Type:    bootstrap_go_binary
 # GoType:  blueprint/bootstrap.goBinaryModule