update golang.org/x/tools

This commit is contained in:
Denis Isaev 2018-10-28 18:03:14 +03:00
parent 0421bac259
commit 17508ab904
No known key found for this signature in database
GPG Key ID: A36A0EC8E27A1A01
7 changed files with 43 additions and 43 deletions

4
Gopkg.lock generated
View File

@ -552,7 +552,7 @@
[[projects]]
branch = "master"
digest = "1:e5f00913432ec90163061b29e00176fd12b71fe400adeb0cb4071273ada6542d"
digest = "1:6aa9381fe53ab53763996ddd72a57dc1b69ed1cd90fa8aeb4f6b4e567204f8cf"
name = "golang.org/x/tools"
packages = [
"go/ast/astutil",
@ -569,7 +569,7 @@
"internal/semver",
]
pruneopts = "UT"
revision = "3e7aa9e59977626dc60433e9aeadf1bb63d28295"
revision = "f60e5f99f0816fc2d9ecb338008ea420248d2943"
[[projects]]
digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202"

2
go.mod
View File

@ -56,7 +56,7 @@ require (
github.com/spf13/viper v1.0.2
github.com/stretchr/testify v1.2.1
golang.org/x/crypto v0.0.0-20180505025534-4ec37c66abab // indirect
golang.org/x/tools v0.0.0-20180831211245-3e7aa9e59977
golang.org/x/tools v0.0.0-20180831211245-f60e5f99f081
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
sourcegraph.com/sourcegraph/go-diff v0.0.0-20171119081133-3f415a150aec

1
go.sum
View File

@ -137,6 +137,7 @@ golang.org/x/tools v0.0.0-20180831211245-5d4988d199e2 h1:DpCOQ3KV1qfJ60hZlyxHUgK
golang.org/x/tools v0.0.0-20180831211245-5d4988d199e2/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180831211245-7ca132754999 h1:mf2VYfMpSMTlp0I/UXrX13w5LejDx34QeUUHH4TrUA8=
golang.org/x/tools v0.0.0-20180831211245-7ca132754999/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180831211245-f60e5f99f081/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/airbrake/gobrake.v2 v2.0.9 h1:7z2uVWwn7oVeeugY1DtlPAy5H+KYgB1KeKTnqjNatLo=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

View File

@ -8,8 +8,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"golang.org/x/tools/internal/gopathwalk"
"golang.org/x/tools/internal/semver"
"io/ioutil"
"log"
"os"
@ -18,6 +16,9 @@ import (
"regexp"
"strings"
"sync"
"golang.org/x/tools/internal/gopathwalk"
"golang.org/x/tools/internal/semver"
)
// A goTooOldError reports that the go command
@ -292,20 +293,14 @@ func runNamedQueries(cfg *Config, driver driver, addPkg func(*Package), queries
// roots selects the appropriate paths to walk based on the passed-in configuration,
// particularly the environment and the presence of a go.mod in cfg.Dir's parents.
func roots(cfg *Config) ([]gopathwalk.Root, bool, error) {
stdout := new(bytes.Buffer)
stderr := new(bytes.Buffer)
cmd := exec.CommandContext(cfg.Context, "go", "env", "GOROOT", "GOPATH", "GOMOD")
cmd.Stdout = stdout
cmd.Stderr = stderr
cmd.Dir = cfg.Dir
cmd.Env = cfg.Env
if err := cmd.Run(); err != nil {
return nil, false, fmt.Errorf("running go env: %v (stderr: %q)", err, stderr.Bytes())
stdout, err := invokeGo(cfg, "env", "GOROOT", "GOPATH", "GOMOD")
if err != nil {
return nil, false, err
}
fields := strings.Split(string(stdout.Bytes()), "\n")
fields := strings.Split(stdout.String(), "\n")
if len(fields) != 4 || len(fields[3]) != 0 {
return nil, false, fmt.Errorf("go env returned unexpected output: %q (stderr: %q)", stdout.Bytes(), stderr.Bytes())
return nil, false, fmt.Errorf("go env returned unexpected output: %q", stdout.String())
}
goroot, gopath, gomod := fields[0], filepath.SplitList(fields[1]), fields[2]
modsEnabled := gomod != ""
@ -449,7 +444,7 @@ func golistDriverCurrent(cfg *Config, words ...string) (*driverResponse, error)
// Run "go list" for complete
// information on the specified packages.
buf, err := golist(cfg, golistargs(cfg, words))
buf, err := invokeGo(cfg, golistargs(cfg, words)...)
if err != nil {
return nil, err
}
@ -573,12 +568,18 @@ func golistargs(cfg *Config, words []string) []string {
return fullargs
}
// golist returns the JSON-encoded result of a "go list args..." query.
func golist(cfg *Config, args []string) (*bytes.Buffer, error) {
// invokeGo returns the stdout of a go command invocation.
func invokeGo(cfg *Config, args ...string) (*bytes.Buffer, error) {
stdout := new(bytes.Buffer)
stderr := new(bytes.Buffer)
cmd := exec.CommandContext(cfg.Context, "go", args...)
cmd.Env = cfg.Env
// On darwin the cwd gets resolved to the real path, which breaks anything that
// expects the working directory to keep the original path, including the
// go command when dealing with modules.
// The Go stdlib has a special feature where if the cwd and the PWD are the
// same node then it trusts the PWD, so by setting it in the env for the child
// process we fix up all the paths returned by the go command.
cmd.Env = append(append([]string{}, cfg.Env...), "PWD="+cfg.Dir)
cmd.Dir = cfg.Dir
cmd.Stdout = stdout
cmd.Stderr = stderr
@ -591,9 +592,9 @@ func golist(cfg *Config, args []string) (*bytes.Buffer, error) {
return nil, fmt.Errorf("couldn't exec 'go %v': %s %T", args, err, err)
}
// Old go list?
if strings.Contains(fmt.Sprint(cmd.Stderr), "flag provided but not defined") {
return nil, goTooOldError{fmt.Errorf("unsupported version of go list: %s: %s", exitErr, cmd.Stderr)}
// Old go version?
if strings.Contains(stderr.String(), "flag provided but not defined") {
return nil, goTooOldError{fmt.Errorf("unsupported version of go: %s: %s", exitErr, stderr)}
}
// Export mode entails a build.
@ -601,7 +602,7 @@ func golist(cfg *Config, args []string) (*bytes.Buffer, error) {
// (despite the -e flag) and the Export field is blank.
// Do not fail in that case.
if !usesExportData(cfg) {
return nil, fmt.Errorf("go %v: %s: %s", args, exitErr, cmd.Stderr)
return nil, fmt.Errorf("go %v: %s: %s", args, exitErr, stderr)
}
}
@ -612,12 +613,12 @@ func golist(cfg *Config, args []string) (*bytes.Buffer, error) {
// be useful for debugging. Print them if $GOPACKAGESPRINTGOLISTERRORS
// is set.
if len(stderr.Bytes()) != 0 && os.Getenv("GOPACKAGESPRINTGOLISTERRORS") != "" {
fmt.Fprintf(os.Stderr, "go %v stderr: <<\n%s\n>>\n", args, stderr)
fmt.Fprintf(os.Stderr, "go %v stderr: <<%s>>\n", args, stderr)
}
// debugging
if false {
fmt.Fprintln(os.Stderr, stdout)
fmt.Fprintf(os.Stderr, "go %v stdout: <<%s>>\n", args, stdout)
}
return stdout, nil

View File

@ -227,7 +227,7 @@ func golistDriverFallback(cfg *Config, words ...string) (*driverResponse, error)
return &response, nil
}
buf, err := golist(cfg, golistArgsFallback(cfg, deps))
buf, err := invokeGo(cfg, golistArgsFallback(cfg, deps)...)
if err != nil {
return nil, err
}
@ -362,7 +362,7 @@ func vendorlessPath(ipath string) string {
// getDeps runs an initial go list to determine all the dependency packages.
func getDeps(cfg *Config, words ...string) (originalSet map[string]*jsonPackage, deps []string, err error) {
buf, err := golist(cfg, golistArgsFallback(cfg, words))
buf, err := invokeGo(cfg, golistArgsFallback(cfg, words)...)
if err != nil {
return nil, nil, err
}
@ -396,7 +396,7 @@ func getDeps(cfg *Config, words ...string) (originalSet map[string]*jsonPackage,
}
// Get the deps of the packages imported by tests.
if len(testImports) > 0 {
buf, err = golist(cfg, golistArgsFallback(cfg, testImports))
buf, err = invokeGo(cfg, golistArgsFallback(cfg, testImports)...)
if err != nil {
return nil, nil, err
}

View File

@ -932,15 +932,3 @@ func findImportStdlib(shortPkg string, symbols map[string]bool) (importPath stri
}
return importPath, importPath != ""
}
// fileInDir reports whether the provided file path looks like
// it's in dir. (without hitting the filesystem)
func fileInDir(file, dir string) bool {
rest := strings.TrimPrefix(file, dir)
if len(rest) == len(file) {
// dir is not a prefix of file.
return false
}
// Check for boundary: either nothing (file == dir), or a slash.
return len(rest) == 0 || rest[0] == '/' || rest[0] == '\\'
}

View File

@ -34,8 +34,18 @@ func sortImports(fset *token.FileSet, f *ast.File) {
continue
}
// Sort and regroup all imports.
sortSpecs(fset, f, d.Specs)
// Identify and sort runs of specs on successive lines.
i := 0
specs := d.Specs[:0]
for j, s := range d.Specs {
if j > i && fset.Position(s.Pos()).Line > 1+fset.Position(d.Specs[j-1].End()).Line {
// j begins a new run. End this one.
specs = append(specs, sortSpecs(fset, f, d.Specs[i:j])...)
i = j
}
}
specs = append(specs, sortSpecs(fset, f, d.Specs[i:])...)
d.Specs = specs
// Deduping can leave a blank line before the rparen; clean that up.
if len(d.Specs) > 0 {