Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitce7cd49

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 parent1e39098 commitce7cd49

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
varoutputFlag=flag.String("output","","output file name without extension; if empty, then print to stdout")
2728

28-
funcmustOpen(namestring) io.Reader {
29-
f,err:=os.Open(name)
30-
iferr!=nil {
31-
log.Fatal(err)
29+
funcmustOpenAll(names...string) []io.Reader {
30+
ff:= []io.Reader{}
31+
for_,name:=rangenames {
32+
f,err:=os.Open(name)
33+
iferr!=nil {
34+
log.Fatal(err)
35+
}
36+
ff=append(ff,f)
3237
}
33-
returnf
38+
returnff
3439
}
3540

3641
funcapi(basestring)string {
3742
returnfilepath.Join(runtime.GOROOT(),"api",base)
3843
}
3944

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

4255
varskips=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)

[8]ページ先頭

©2009-2025 Movatter.jp