1
+ //go:build generate
1
2
// +build generate
2
3
3
4
// mkstdlib generates the zstdlib.go file, containing the Go standard
@@ -25,18 +26,30 @@ import (
25
26
26
27
var outputFlag = flag .String ("output" , "" , "output file name without extension; if empty, then print to stdout" )
27
28
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 )
32
37
}
33
- return f
38
+ return ff
34
39
}
35
40
36
41
func api (base string ) string {
37
42
return filepath .Join (runtime .GOROOT (), "api" , base )
38
43
}
39
44
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
+
40
53
var sym = regexp .MustCompile (`^pkg (\S+).*?, (?:var|func|type|const) ([A-Z]\w*)` )
41
54
42
55
var skips = map [string ]struct {}{
@@ -56,26 +69,13 @@ func main() {
56
69
outf ("package imports\n " )
57
70
outf ("var stdlib = map[string]string{\n " )
58
71
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" )... )... )
79
79
sc := bufio .NewScanner (f )
80
80
fullImport := map [string ]string {} // "zip.NewReader" => "archive/zip"
81
81
ambiguous := map [string ]bool {}
0 commit comments