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
2627var 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
3641func api (base string )string {
3742return 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+
4053var sym = regexp .MustCompile (`^pkg (\S+).*?, (?:var|func|type|const) ([A-Z]\w*)` )
4154
4255var skips = map [string ]struct {}{
@@ -56,26 +69,13 @@ func main() {
5669outf ("package imports\n " )
5770outf ("var stdlib = map[string]string{\n " )
5871f := 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" )... )... )
7979sc := bufio .NewScanner (f )
8080fullImport := map [string ]string {}// "zip.NewReader" => "archive/zip"
8181ambiguous := map [string ]bool {}