this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

pkg: sort input packages in a consistent order when generating

This resolves a minor quirk where adding pkg/encoding/toml
would initially put it at the very end of the register.go import list.
It could be fixed by a second run of `go generate`, but it's also easy
to fix the generator so that it doesn't have this quirk.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I2798ed976918587c6c276f438f9dec6a87c1a9e3
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201473
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+9
+9
pkg/gen.go
··· 30 30 31 31 import ( 32 32 "bytes" 33 + "cmp" 33 34 _ "embed" 34 35 "flag" 35 36 "fmt" ··· 41 42 "math/big" 42 43 "os" 43 44 "path/filepath" 45 + "slices" 44 46 "sort" 45 47 "strings" 46 48 "text/template" ··· 100 102 if packages.PrintErrors(pkgs) > 0 { 101 103 os.Exit(1) 102 104 } 105 + // Sort the Go packages by import path; otherwise adding a new builtin package 106 + // puts it at the very end of the list the first time it is getting added to register.go, 107 + // as it's not imported by the root package yet. Sorting ensures consistent output. 108 + slices.SortFunc(pkgs, func(a, b *packages.Package) int { 109 + return cmp.Compare(a.PkgPath, b.PkgPath) 110 + }) 111 + 103 112 regBuf := new(bytes.Buffer) 104 113 fmt.Fprintf(regBuf, "// Code generated by cuelang.org/go/pkg/gen. DO NOT EDIT.\n\n") 105 114 fmt.Fprintf(regBuf, "package pkg\n\n")