Skip to content

Commit ab5ac5f

Browse files
committed
gen.go: some improvements
- 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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Nigel Tao <[email protected]>
1 parent 43e60fb commit ab5ac5f

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

gen.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ func main() {
7979
os.Exit(2)
8080
}
8181
updateCore = true
82+
goroot := os.Getenv("GOROOT")
83+
appendToFile(
84+
filepath.Join(goroot, "api", "except.txt"),
85+
fmt.Sprintf("pkg unicode, const Version = %q\n", unicode.Version),
86+
)
87+
const lines = `pkg unicode, const Version = %q
88+
// TODO: add a new line of the following form for each new script and property.
89+
pkg unicode, var <new script or property> *RangeTable
90+
`
91+
appendToFile(
92+
filepath.Join(goroot, "api", "next.txt"),
93+
fmt.Sprintf(lines, gen.UnicodeVersion()),
94+
)
8295
}
8396

8497
var unicode = &dependency{}
@@ -131,6 +144,20 @@ func main() {
131144
vprintf("SUCCESS\n")
132145
}
133146

147+
func appendToFile(file, text string) {
148+
fmt.Println("Augmenting", file)
149+
w, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY, 0600)
150+
if err != nil {
151+
fmt.Println("Failed to open file:", err)
152+
os.Exit(1)
153+
}
154+
defer w.Close()
155+
if _, err := w.WriteString(text); err != nil {
156+
fmt.Println("Failed to write to file:", err)
157+
os.Exit(1)
158+
}
159+
}
160+
134161
var (
135162
all sync.WaitGroup
136163
hasErrors bool
@@ -243,7 +270,7 @@ func copyPackage(dirSrc, dirDst, search, replace string) {
243270
base := filepath.Base(file)
244271
if err != nil || info.IsDir() ||
245272
!strings.HasSuffix(base, ".go") ||
246-
strings.HasSuffix(base, "_test.go") && !strings.HasPrefix(base, "example") ||
273+
strings.HasSuffix(base, "_test.go") ||
247274
// Don't process subdirectories.
248275
filepath.Dir(file) != dirSrc {
249276
return nil

0 commit comments

Comments
 (0)