Sort before generating unique function names to get stable output

pull/4/head
Jessica Forrester 2014-11-24 16:00:02 -05:00
parent bbd0c6e271
commit fcbedc59d6
2 changed files with 10 additions and 10 deletions

View File

@ -10,10 +10,3 @@ type Asset struct {
Name string // Key used in TOC -- name by which asset is referenced.
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 }

View File

@ -35,9 +35,6 @@ func Translate(c *Config) error {
}
}
// Sort to make output stable between invocations
sort.Sort(ByPath(toc))
// Create output file.
fd, err := os.Create(c.Output)
if err != nil {
@ -83,6 +80,13 @@ func Translate(c *Config) error {
return writeTOCTree(bfd, toc)
}
// Implement sort.Interface for []os.FileInfo based on Name()
type ByName []os.FileInfo
func (v ByName) Len() int { return len(v) }
func (v ByName) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
func (v ByName) Less(i, j int) bool { return v[i].Name() < v[j].Name() }
// findFiles recursively finds all the file paths in the given directory tree.
// They are added to the given map as keys. Values will be safe function names
// for each file, which will be used when generating the output code.
@ -115,6 +119,9 @@ func findFiles(dir, prefix string, recursive bool, toc *[]Asset, ignore []*regex
if err != nil {
return err
}
// Sort to make output stable between invocations
sort.Sort(ByName(list))
}
knownFuncs := make(map[string]int)