Skip to content

Commit ce7cd49

Browse files
committed
Consider all Go versions up to current when generating symbol import map.
Each new Go release adds a new file with a list of APIs it introduced, updated code will automatically include all of them.
1 parent 1e39098 commit ce7cd49

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

playground/internal/imports/mkstdlib.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build generate
12
// +build generate
23

34
// mkstdlib generates the zstdlib.go file, containing the Go standard
@@ -25,18 +26,30 @@ import (
2526

2627
var outputFlag = flag.String("output", "", "output file name without extension; if empty, then print to stdout")
2728

28-
func mustOpen(name string) io.Reader {
29-
f, err := os.Open(name)
30-
if err != nil {
31-
log.Fatal(err)
29+
func mustOpenAll(names ...string) []io.Reader {
30+
ff := []io.Reader{}
31+
for _, name := range names {
32+
f, err := os.Open(name)
33+
if err != nil {
34+
log.Fatal(err)
35+
}
36+
ff = append(ff, f)
3237
}
33-
return f
38+
return ff
3439
}
3540

3641
func api(base string) string {
3742
return filepath.Join(runtime.GOROOT(), "api", base)
3843
}
3944

45+
func goAPIs() []string {
46+
paths, err := filepath.Glob(filepath.Join(runtime.GOROOT(), "api", "go1.*.txt"))
47+
if err != nil {
48+
log.Fatalf("Failed to match Go API files: %s", err)
49+
}
50+
return paths
51+
}
52+
4053
var sym = regexp.MustCompile(`^pkg (\S+).*?, (?:var|func|type|const) ([A-Z]\w*)`)
4154

4255
var skips = map[string]struct{}{
@@ -56,26 +69,13 @@ func main() {
5669
outf("package imports\n")
5770
outf("var stdlib = map[string]string{\n")
5871
f := io.MultiReader(
59-
mustOpen(api("go1.txt")),
60-
mustOpen(api("go1.1.txt")),
61-
mustOpen(api("go1.2.txt")),
62-
mustOpen(api("go1.3.txt")),
63-
mustOpen(api("go1.4.txt")),
64-
mustOpen(api("go1.5.txt")),
65-
mustOpen(api("go1.6.txt")),
66-
mustOpen(api("go1.7.txt")),
67-
mustOpen(api("go1.8.txt")),
68-
mustOpen(api("go1.9.txt")),
69-
mustOpen(api("go1.10.txt")),
70-
mustOpen(api("go1.11.txt")),
71-
mustOpen(api("go1.12.txt")),
72-
73-
// The API of the syscall/js package needs to be computed explicitly,
74-
// because it's not included in the GOROOT/api/go1.*.txt files at this time.
75-
mustOpen("syscalljs.txt"),
76-
77-
mustOpen("gopherjs.txt"),
78-
)
72+
mustOpenAll(append(
73+
// Standard library packages.
74+
goAPIs(),
75+
// The API of the syscall/js package needs to be computed explicitly,
76+
// because it's not included in the GOROOT/api/go1.*.txt files at this time.
77+
"syscalljs.txt",
78+
"gopherjs.txt")...)...)
7979
sc := bufio.NewScanner(f)
8080
fullImport := map[string]string{} // "zip.NewReader" => "archive/zip"
8181
ambiguous := map[string]bool{}

0 commit comments

Comments
 (0)