aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/tools/imports/mkstdlib.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-04-10 20:30:34 +0200
committerMichael Muré <batolettre@gmail.com>2019-04-10 20:30:34 +0200
commit0e53d2555e9a6ddc707f6c59497f30e182116c80 (patch)
tree7fa6cd92d87c8ac6a0fd486be9647b69975b7d21 /vendor/golang.org/x/tools/imports/mkstdlib.go
parent9722d7c9eca28b1710e50ac9075fd11d0db0606a (diff)
downloadgit-bug-0e53d2555e9a6ddc707f6c59497f30e182116c80.tar.gz
force a version of golang.org/x/tools due to an incompatibility with gqlgen
Diffstat (limited to 'vendor/golang.org/x/tools/imports/mkstdlib.go')
-rw-r--r--vendor/golang.org/x/tools/imports/mkstdlib.go73
1 files changed, 49 insertions, 24 deletions
diff --git a/vendor/golang.org/x/tools/imports/mkstdlib.go b/vendor/golang.org/x/tools/imports/mkstdlib.go
index 02e4727e..c8865e55 100644
--- a/vendor/golang.org/x/tools/imports/mkstdlib.go
+++ b/vendor/golang.org/x/tools/imports/mkstdlib.go
@@ -14,7 +14,7 @@ import (
"io/ioutil"
"log"
"os"
- "path"
+ "os/exec"
"path/filepath"
"regexp"
"runtime"
@@ -36,6 +36,8 @@ func api(base string) string {
var sym = regexp.MustCompile(`^pkg (\S+).*?, (?:var|func|type|const) ([A-Z]\w*)`)
+var unsafeSyms = map[string]bool{"Alignof": true, "ArbitraryType": true, "Offsetof": true, "Pointer": true, "Sizeof": true}
+
func main() {
var buf bytes.Buffer
outf := func(format string, args ...interface{}) {
@@ -43,7 +45,7 @@ func main() {
}
outf("// Code generated by mkstdlib.go. DO NOT EDIT.\n\n")
outf("package imports\n")
- outf("var stdlib = map[string]string{\n")
+ outf("var stdlib = map[string]map[string]bool{\n")
f := io.MultiReader(
mustOpen(api("go1.txt")),
mustOpen(api("go1.1.txt")),
@@ -56,11 +58,20 @@ func main() {
mustOpen(api("go1.8.txt")),
mustOpen(api("go1.9.txt")),
mustOpen(api("go1.10.txt")),
+ mustOpen(api("go1.11.txt")),
+ mustOpen(api("go1.12.txt")),
+
+ // The API of the syscall/js package needs to be computed explicitly,
+ // because it's not included in the GOROOT/api/go1.*.txt files at this time.
+ syscallJSAPI(),
)
sc := bufio.NewScanner(f)
- fullImport := map[string]string{} // "zip.NewReader" => "archive/zip"
- ambiguous := map[string]bool{}
- var keys []string
+
+ pkgs := map[string]map[string]bool{
+ "unsafe": unsafeSyms,
+ }
+ paths := []string{"unsafe"}
+
for sc.Scan() {
l := sc.Text()
has := func(v string) bool { return strings.Contains(l, v) }
@@ -68,32 +79,31 @@ func main() {
continue
}
if m := sym.FindStringSubmatch(l); m != nil {
- full := m[1]
- key := path.Base(full) + "." + m[2]
- if exist, ok := fullImport[key]; ok {
- if exist != full {
- ambiguous[key] = true
- }
- } else {
- fullImport[key] = full
- keys = append(keys, key)
+ path, sym := m[1], m[2]
+
+ if _, ok := pkgs[path]; !ok {
+ pkgs[path] = map[string]bool{}
+ paths = append(paths, path)
}
+ pkgs[path][sym] = true
}
}
if err := sc.Err(); err != nil {
log.Fatal(err)
}
- sort.Strings(keys)
- for _, key := range keys {
- if ambiguous[key] {
- outf("\t// %q is ambiguous\n", key)
- } else {
- outf("\t%q: %q,\n", key, fullImport[key])
+ sort.Strings(paths)
+ for _, path := range paths {
+ outf("\t%q: map[string]bool{\n", path)
+ pkg := pkgs[path]
+ var syms []string
+ for sym := range pkg {
+ syms = append(syms, sym)
}
- }
- outf("\n")
- for _, sym := range [...]string{"Alignof", "ArbitraryType", "Offsetof", "Pointer", "Sizeof"} {
- outf("\t%q: %q,\n", "unsafe."+sym, "unsafe")
+ sort.Strings(syms)
+ for _, sym := range syms {
+ outf("\t\t%q: true,\n", sym)
+ }
+ outf("},\n")
}
outf("}\n")
fmtbuf, err := format.Source(buf.Bytes())
@@ -105,3 +115,18 @@ func main() {
log.Fatal(err)
}
}
+
+// syscallJSAPI returns the API of the syscall/js package.
+// It's computed from the contents of $(go env GOROOT)/src/syscall/js.
+func syscallJSAPI() io.Reader {
+ var exeSuffix string
+ if runtime.GOOS == "windows" {
+ exeSuffix = ".exe"
+ }
+ cmd := exec.Command("go"+exeSuffix, "run", "cmd/api", "-contexts", "js-wasm", "syscall/js")
+ out, err := cmd.Output()
+ if err != nil {
+ log.Fatalln(err)
+ }
+ return bytes.NewReader(out)
+}