Output TOC and tree in sorted order to make output stable between invocations. Addresses issue #49
This commit is contained in:
parent
93b909d149
commit
853793af8f
7
asset.go
7
asset.go
|
@ -10,3 +10,10 @@ type Asset struct {
|
||||||
Name string // Key used in TOC -- name by which asset is referenced.
|
Name string // Key used in TOC -- name by which asset is referenced.
|
||||||
Func string // Function name for the procedure returning the asset contents.
|
Func string // Function name for the procedure returning the asset contents.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implement sort.Interface for []Asset based on Path field
|
||||||
|
type ByPath []Asset
|
||||||
|
|
||||||
|
func (v ByPath) Len() int { return len(v) }
|
||||||
|
func (v ByPath) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
|
||||||
|
func (v ByPath) Less(i, j int) bool { return v[i].Path < v[j].Path }
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
@ -34,6 +35,9 @@ func Translate(c *Config) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort to make output stable between invocations
|
||||||
|
sort.Sort(ByPath(toc))
|
||||||
|
|
||||||
// Create output file.
|
// Create output file.
|
||||||
fd, err := os.Create(c.Output)
|
fd, err := os.Create(c.Output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
15
toc.go
15
toc.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -54,10 +55,20 @@ func (root *assetTree) funcOrNil() string {
|
||||||
|
|
||||||
func (root *assetTree) writeGoMap(w io.Writer, nident int) {
|
func (root *assetTree) writeGoMap(w io.Writer, nident int) {
|
||||||
fmt.Fprintf(w, "&_bintree_t{%s, map[string]*_bintree_t{\n", root.funcOrNil())
|
fmt.Fprintf(w, "&_bintree_t{%s, map[string]*_bintree_t{\n", root.funcOrNil())
|
||||||
for p, child := range root.Children {
|
|
||||||
|
// Sort to make output stable between invocations
|
||||||
|
filenames := make([]string, len(root.Children))
|
||||||
|
i := 0
|
||||||
|
for filename, _ := range root.Children {
|
||||||
|
filenames[i] = filename
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
sort.Strings(filenames)
|
||||||
|
|
||||||
|
for _, p := range filenames {
|
||||||
ident(w, nident+1)
|
ident(w, nident+1)
|
||||||
fmt.Fprintf(w, `"%s": `, p)
|
fmt.Fprintf(w, `"%s": `, p)
|
||||||
child.writeGoMap(w, nident+1)
|
root.Children[p].writeGoMap(w, nident+1)
|
||||||
}
|
}
|
||||||
ident(w, nident)
|
ident(w, nident)
|
||||||
io.WriteString(w, "}}")
|
io.WriteString(w, "}}")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user