Skip to content

Commit

Permalink
gen.go: some improvements
Browse files Browse the repository at this point in the history
- Update api files in core when updating
  Unicode version
- Exclude examples from copied packages.

Change-Id: Id96e735fb8acdd57d3fa0bc6eb01eaa817c1d421
Reviewed-on: https://go-review.googlesource.com/63610
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
  • Loading branch information
mpvl committed Sep 14, 2017
1 parent 43e60fb commit ab5ac5f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ func main() {
os.Exit(2)
}
updateCore = true
goroot := os.Getenv("GOROOT")
appendToFile(
filepath.Join(goroot, "api", "except.txt"),
fmt.Sprintf("pkg unicode, const Version = %q\n", unicode.Version),
)
const lines = `pkg unicode, const Version = %q
// TODO: add a new line of the following form for each new script and property.
pkg unicode, var <new script or property> *RangeTable
`
appendToFile(
filepath.Join(goroot, "api", "next.txt"),
fmt.Sprintf(lines, gen.UnicodeVersion()),
)
}

var unicode = &dependency{}
Expand Down Expand Up @@ -131,6 +144,20 @@ func main() {
vprintf("SUCCESS\n")
}

func appendToFile(file, text string) {
fmt.Println("Augmenting", file)
w, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
fmt.Println("Failed to open file:", err)
os.Exit(1)
}
defer w.Close()
if _, err := w.WriteString(text); err != nil {
fmt.Println("Failed to write to file:", err)
os.Exit(1)
}
}

var (
all sync.WaitGroup
hasErrors bool
Expand Down Expand Up @@ -243,7 +270,7 @@ func copyPackage(dirSrc, dirDst, search, replace string) {
base := filepath.Base(file)
if err != nil || info.IsDir() ||
!strings.HasSuffix(base, ".go") ||
strings.HasSuffix(base, "_test.go") && !strings.HasPrefix(base, "example") ||
strings.HasSuffix(base, "_test.go") ||
// Don't process subdirectories.
filepath.Dir(file) != dirSrc {
return nil
Expand Down

0 comments on commit ab5ac5f

Please # to comment.