vendor: update golang.org/x/tools including goimports formatting changes

A recent change was introduced in goimports improving how it sort and
format imports in https://go-review.googlesource.com/c/tools/+/116795

This commit updates the vendored version of the golang.org/x/tools
repository to include these changes.
This commit is contained in:
Cezar Sa Espinola 2018-10-16 09:53:46 -03:00 committed by Isaev Denis
parent 889e38c2fa
commit 0e2be20016
12 changed files with 7989 additions and 7658 deletions

5
Gopkg.lock generated
View File

@ -549,7 +549,7 @@
[[projects]]
branch = "master"
digest = "1:1c24352e1722a8954fe7c95bcb12d878ef9883b01fe3e0e801f62e8cbf9621a0"
digest = "1:1f0808c71cfd0b33831391bc26c7ba2862138bfaa10b7f8ed695b2a0c67f896c"
name = "golang.org/x/tools"
packages = [
"go/ast/astutil",
@ -561,9 +561,10 @@
"go/types/typeutil",
"imports",
"internal/fastwalk",
"internal/gopathwalk",
]
pruneopts = "UT"
revision = "7ca132754999accbaa5c1735eda29e7ce0f3bf03"
revision = "5d4988d199e2aeefda3528f599e06410c43caa29"
[[projects]]
digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202"

35
vendor/golang.org/x/tools/go/types/typeutil/callee.go generated vendored Normal file
View File

@ -0,0 +1,35 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package typeutil
import (
"go/ast"
"go/types"
)
// StaticCallee returns the target (function or method) of a static
// function call, if any. It returns nil for calls to builtin.
func StaticCallee(info *types.Info, call *ast.CallExpr) *types.Func {
var obj types.Object
switch fun := call.Fun.(type) {
case *ast.Ident:
obj = info.Uses[fun] // type, var, builtin, or declared func
case *ast.SelectorExpr:
if sel, ok := info.Selections[fun]; ok {
obj = sel.Obj() // method or field
} else {
obj = info.Uses[fun.Sel] // qualified identifier?
}
}
if f, ok := obj.(*types.Func); ok && !interfaceMethod(f) {
return f
}
return nil
}
func interfaceMethod(f *types.Func) bool {
recv := f.Type().(*types.Signature).Recv()
return recv != nil && types.IsInterface(recv.Type())
}

View File

@ -5,8 +5,6 @@
package imports
import (
"bufio"
"bytes"
"context"
"fmt"
"go/ast"
@ -24,7 +22,7 @@ import (
"sync"
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/internal/fastwalk"
"golang.org/x/tools/internal/gopathwalk"
)
// Debug controls verbose logging.
@ -471,16 +469,8 @@ func init() {
// Directory-scanning state.
var (
// scanGoRootOnce guards calling scanGoRoot (for $GOROOT)
scanGoRootOnce sync.Once
// scanGoPathOnce guards calling scanGoPath (for $GOPATH)
scanGoPathOnce sync.Once
// populateIgnoreOnce guards calling populateIgnore
populateIgnoreOnce sync.Once
ignoredDirs []os.FileInfo
dirScanMu sync.Mutex
// scanOnce guards calling scanGoDirs and assigning dirScan
scanOnce sync.Once
dirScan map[string]*pkg // abs dir path => *pkg
)
@ -531,195 +521,27 @@ func distance(basepath, targetpath string) int {
return strings.Count(p, string(filepath.Separator)) + 1
}
// guarded by populateIgnoreOnce; populates ignoredDirs.
func populateIgnore() {
for _, srcDir := range build.Default.SrcDirs() {
if srcDir == filepath.Join(build.Default.GOROOT, "src") {
continue
}
populateIgnoredDirs(srcDir)
}
}
// scanGoDirs populates the dirScan map for GOPATH and GOROOT.
func scanGoDirs() map[string]*pkg {
result := make(map[string]*pkg)
var mu sync.Mutex
// populateIgnoredDirs reads an optional config file at <path>/.goimportsignore
// of relative directories to ignore when scanning for go files.
// The provided path is one of the $GOPATH entries with "src" appended.
func populateIgnoredDirs(path string) {
file := filepath.Join(path, ".goimportsignore")
slurp, err := ioutil.ReadFile(file)
if Debug {
if err != nil {
log.Print(err)
} else {
log.Printf("Read %s", file)
}
}
if err != nil {
add := func(srcDir, dir string) {
mu.Lock()
defer mu.Unlock()
if _, dup := result[dir]; dup {
return
}
bs := bufio.NewScanner(bytes.NewReader(slurp))
for bs.Scan() {
line := strings.TrimSpace(bs.Text())
if line == "" || strings.HasPrefix(line, "#") {
continue
}
full := filepath.Join(path, line)
if fi, err := os.Stat(full); err == nil {
ignoredDirs = append(ignoredDirs, fi)
if Debug {
log.Printf("Directory added to ignore list: %s", full)
}
} else if Debug {
log.Printf("Error statting entry in .goimportsignore: %v", err)
}
}
}
func skipDir(fi os.FileInfo) bool {
for _, ignoredDir := range ignoredDirs {
if os.SameFile(fi, ignoredDir) {
return true
}
}
return false
}
// shouldTraverse reports whether the symlink fi, found in dir,
// should be followed. It makes sure symlinks were never visited
// before to avoid symlink loops.
func shouldTraverse(dir string, fi os.FileInfo) bool {
path := filepath.Join(dir, fi.Name())
target, err := filepath.EvalSymlinks(path)
if err != nil {
return false
}
ts, err := os.Stat(target)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return false
}
if !ts.IsDir() {
return false
}
if skipDir(ts) {
return false
}
// Check for symlink loops by statting each directory component
// and seeing if any are the same file as ts.
for {
parent := filepath.Dir(path)
if parent == path {
// Made it to the root without seeing a cycle.
// Use this symlink.
return true
}
parentInfo, err := os.Stat(parent)
if err != nil {
return false
}
if os.SameFile(ts, parentInfo) {
// Cycle. Don't traverse.
return false
}
path = parent
}
}
var testHookScanDir = func(dir string) {}
type goDirType string
const (
goRoot goDirType = "$GOROOT"
goPath goDirType = "$GOPATH"
)
var scanGoRootDone = make(chan struct{}) // closed when scanGoRoot is done
// scanGoDirs populates the dirScan map for the given directory type. It may be
// called concurrently (and usually is, if both directory types are needed).
func scanGoDirs(which goDirType) {
if Debug {
log.Printf("scanning %s", which)
defer log.Printf("scanned %s", which)
}
for _, srcDir := range build.Default.SrcDirs() {
isGoroot := srcDir == filepath.Join(build.Default.GOROOT, "src")
if isGoroot != (which == goRoot) {
continue
}
testHookScanDir(srcDir)
srcV := filepath.Join(srcDir, "v")
srcMod := filepath.Join(srcDir, "mod")
walkFn := func(path string, typ os.FileMode) error {
if path == srcV || path == srcMod {
return filepath.SkipDir
}
dir := filepath.Dir(path)
if typ.IsRegular() {
if dir == srcDir {
// Doesn't make sense to have regular files
// directly in your $GOPATH/src or $GOROOT/src.
return nil
}
if !strings.HasSuffix(path, ".go") {
return nil
}
dirScanMu.Lock()
defer dirScanMu.Unlock()
if _, dup := dirScan[dir]; dup {
return nil
}
if dirScan == nil {
dirScan = make(map[string]*pkg)
}
importpath := filepath.ToSlash(dir[len(srcDir)+len("/"):])
dirScan[dir] = &pkg{
result[dir] = &pkg{
importPath: importpath,
importPathShort: VendorlessPath(importpath),
dir: dir,
}
return nil
}
if typ == os.ModeDir {
base := filepath.Base(path)
if base == "" || base[0] == '.' || base[0] == '_' ||
base == "testdata" || base == "node_modules" {
return filepath.SkipDir
}
fi, err := os.Lstat(path)
if err == nil && skipDir(fi) {
if Debug {
log.Printf("skipping directory %q under %s", fi.Name(), dir)
}
return filepath.SkipDir
}
return nil
}
if typ == os.ModeSymlink {
base := filepath.Base(path)
if strings.HasPrefix(base, ".#") {
// Emacs noise.
return nil
}
fi, err := os.Lstat(path)
if err != nil {
// Just ignore it.
return nil
}
if shouldTraverse(dir, fi) {
return fastwalk.TraverseLink
}
}
return nil
}
if err := fastwalk.Walk(srcDir, walkFn); err != nil {
log.Printf("goimports: scanning directory %v: %v", srcDir, err)
}
}
gopathwalk.Walk(add, gopathwalk.Options{Debug: Debug, ModulesEnabled: false})
return result
}
// VendorlessPath returns the devendorized version of the import path ipath.
@ -868,25 +690,8 @@ func findImportGoPath(ctx context.Context, pkgName string, symbols map[string]bo
// in the current Go file. Return rename=true when the other Go files
// use a renamed package that's also used in the current file.
// Read all the $GOPATH/src/.goimportsignore files before scanning directories.
populateIgnoreOnce.Do(populateIgnore)
// Start scanning the $GOROOT asynchronously, then run the
// GOPATH scan synchronously if needed, and then wait for the
// $GOROOT to finish.
//
// TODO(bradfitz): run each $GOPATH entry async. But nobody
// really has more than one anyway, so low priority.
scanGoRootOnce.Do(func() {
go func() {
scanGoDirs(goRoot)
close(scanGoRootDone)
}()
})
if !fileInDir(filename, build.Default.GOROOT) {
scanGoPathOnce.Do(func() { scanGoDirs(goPath) })
}
<-scanGoRootDone
// Scan $GOROOT and each $GOPATH.
scanOnce.Do(func() { dirScan = scanGoDirs() })
// Find candidate packages, looking only at their directory names first.
var candidates []pkgDistance

View File

@ -56,6 +56,7 @@ func main() {
mustOpen(api("go1.8.txt")),
mustOpen(api("go1.9.txt")),
mustOpen(api("go1.10.txt")),
mustOpen(api("go1.11.txt")),
)
sc := bufio.NewScanner(f)
fullImport := map[string]string{} // "zip.NewReader" => "archive/zip"

View File

@ -34,18 +34,8 @@ func sortImports(fset *token.FileSet, f *ast.File) {
continue
}
// 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
// Sort and regroup all imports.
sortSpecs(fset, f, d.Specs)
// Deduping can leave a blank line before the rparen; clean that up.
if len(d.Specs) > 0 {

View File

@ -378,6 +378,7 @@ var stdlib = map[string]string{
"cipher.NewCTR": "crypto/cipher",
"cipher.NewGCM": "crypto/cipher",
"cipher.NewGCMWithNonceSize": "crypto/cipher",
"cipher.NewGCMWithTagSize": "crypto/cipher",
"cipher.NewOFB": "crypto/cipher",
"cipher.Stream": "crypto/cipher",
"cipher.StreamReader": "crypto/cipher",
@ -917,6 +918,9 @@ var stdlib = map[string]string{
"elf.ELFOSABI_86OPEN": "debug/elf",
"elf.ELFOSABI_AIX": "debug/elf",
"elf.ELFOSABI_ARM": "debug/elf",
"elf.ELFOSABI_AROS": "debug/elf",
"elf.ELFOSABI_CLOUDABI": "debug/elf",
"elf.ELFOSABI_FENIXOS": "debug/elf",
"elf.ELFOSABI_FREEBSD": "debug/elf",
"elf.ELFOSABI_HPUX": "debug/elf",
"elf.ELFOSABI_HURD": "debug/elf",
@ -933,52 +937,190 @@ var stdlib = map[string]string{
"elf.ELFOSABI_TRU64": "debug/elf",
"elf.EM_386": "debug/elf",
"elf.EM_486": "debug/elf",
"elf.EM_56800EX": "debug/elf",
"elf.EM_68HC05": "debug/elf",
"elf.EM_68HC08": "debug/elf",
"elf.EM_68HC11": "debug/elf",
"elf.EM_68HC12": "debug/elf",
"elf.EM_68HC16": "debug/elf",
"elf.EM_68K": "debug/elf",
"elf.EM_78KOR": "debug/elf",
"elf.EM_8051": "debug/elf",
"elf.EM_860": "debug/elf",
"elf.EM_88K": "debug/elf",
"elf.EM_960": "debug/elf",
"elf.EM_AARCH64": "debug/elf",
"elf.EM_ALPHA": "debug/elf",
"elf.EM_ALPHA_STD": "debug/elf",
"elf.EM_ALTERA_NIOS2": "debug/elf",
"elf.EM_AMDGPU": "debug/elf",
"elf.EM_ARC": "debug/elf",
"elf.EM_ARCA": "debug/elf",
"elf.EM_ARC_COMPACT": "debug/elf",
"elf.EM_ARC_COMPACT2": "debug/elf",
"elf.EM_ARM": "debug/elf",
"elf.EM_AVR": "debug/elf",
"elf.EM_AVR32": "debug/elf",
"elf.EM_BA1": "debug/elf",
"elf.EM_BA2": "debug/elf",
"elf.EM_BLACKFIN": "debug/elf",
"elf.EM_BPF": "debug/elf",
"elf.EM_C166": "debug/elf",
"elf.EM_CDP": "debug/elf",
"elf.EM_CE": "debug/elf",
"elf.EM_CLOUDSHIELD": "debug/elf",
"elf.EM_COGE": "debug/elf",
"elf.EM_COLDFIRE": "debug/elf",
"elf.EM_COOL": "debug/elf",
"elf.EM_COREA_1ST": "debug/elf",
"elf.EM_COREA_2ND": "debug/elf",
"elf.EM_CR": "debug/elf",
"elf.EM_CR16": "debug/elf",
"elf.EM_CRAYNV2": "debug/elf",
"elf.EM_CRIS": "debug/elf",
"elf.EM_CRX": "debug/elf",
"elf.EM_CSR_KALIMBA": "debug/elf",
"elf.EM_CUDA": "debug/elf",
"elf.EM_CYPRESS_M8C": "debug/elf",
"elf.EM_D10V": "debug/elf",
"elf.EM_D30V": "debug/elf",
"elf.EM_DSP24": "debug/elf",
"elf.EM_DSPIC30F": "debug/elf",
"elf.EM_DXP": "debug/elf",
"elf.EM_ECOG1": "debug/elf",
"elf.EM_ECOG16": "debug/elf",
"elf.EM_ECOG1X": "debug/elf",
"elf.EM_ECOG2": "debug/elf",
"elf.EM_ETPU": "debug/elf",
"elf.EM_EXCESS": "debug/elf",
"elf.EM_F2MC16": "debug/elf",
"elf.EM_FIREPATH": "debug/elf",
"elf.EM_FR20": "debug/elf",
"elf.EM_FR30": "debug/elf",
"elf.EM_FT32": "debug/elf",
"elf.EM_FX66": "debug/elf",
"elf.EM_H8S": "debug/elf",
"elf.EM_H8_300": "debug/elf",
"elf.EM_H8_300H": "debug/elf",
"elf.EM_H8_500": "debug/elf",
"elf.EM_HUANY": "debug/elf",
"elf.EM_IA_64": "debug/elf",
"elf.EM_INTEL205": "debug/elf",
"elf.EM_INTEL206": "debug/elf",
"elf.EM_INTEL207": "debug/elf",
"elf.EM_INTEL208": "debug/elf",
"elf.EM_INTEL209": "debug/elf",
"elf.EM_IP2K": "debug/elf",
"elf.EM_JAVELIN": "debug/elf",
"elf.EM_K10M": "debug/elf",
"elf.EM_KM32": "debug/elf",
"elf.EM_KMX16": "debug/elf",
"elf.EM_KMX32": "debug/elf",
"elf.EM_KMX8": "debug/elf",
"elf.EM_KVARC": "debug/elf",
"elf.EM_L10M": "debug/elf",
"elf.EM_LANAI": "debug/elf",
"elf.EM_LATTICEMICO32": "debug/elf",
"elf.EM_M16C": "debug/elf",
"elf.EM_M32": "debug/elf",
"elf.EM_M32C": "debug/elf",
"elf.EM_M32R": "debug/elf",
"elf.EM_MANIK": "debug/elf",
"elf.EM_MAX": "debug/elf",
"elf.EM_MAXQ30": "debug/elf",
"elf.EM_MCHP_PIC": "debug/elf",
"elf.EM_MCST_ELBRUS": "debug/elf",
"elf.EM_ME16": "debug/elf",
"elf.EM_METAG": "debug/elf",
"elf.EM_MICROBLAZE": "debug/elf",
"elf.EM_MIPS": "debug/elf",
"elf.EM_MIPS_RS3_LE": "debug/elf",
"elf.EM_MIPS_RS4_BE": "debug/elf",
"elf.EM_MIPS_X": "debug/elf",
"elf.EM_MMA": "debug/elf",
"elf.EM_MMDSP_PLUS": "debug/elf",
"elf.EM_MMIX": "debug/elf",
"elf.EM_MN10200": "debug/elf",
"elf.EM_MN10300": "debug/elf",
"elf.EM_MOXIE": "debug/elf",
"elf.EM_MSP430": "debug/elf",
"elf.EM_NCPU": "debug/elf",
"elf.EM_NDR1": "debug/elf",
"elf.EM_NDS32": "debug/elf",
"elf.EM_NONE": "debug/elf",
"elf.EM_NORC": "debug/elf",
"elf.EM_NS32K": "debug/elf",
"elf.EM_OPEN8": "debug/elf",
"elf.EM_OPENRISC": "debug/elf",
"elf.EM_PARISC": "debug/elf",
"elf.EM_PCP": "debug/elf",
"elf.EM_PDP10": "debug/elf",
"elf.EM_PDP11": "debug/elf",
"elf.EM_PDSP": "debug/elf",
"elf.EM_PJ": "debug/elf",
"elf.EM_PPC": "debug/elf",
"elf.EM_PPC64": "debug/elf",
"elf.EM_PRISM": "debug/elf",
"elf.EM_QDSP6": "debug/elf",
"elf.EM_R32C": "debug/elf",
"elf.EM_RCE": "debug/elf",
"elf.EM_RH32": "debug/elf",
"elf.EM_RISCV": "debug/elf",
"elf.EM_RL78": "debug/elf",
"elf.EM_RS08": "debug/elf",
"elf.EM_RX": "debug/elf",
"elf.EM_S370": "debug/elf",
"elf.EM_S390": "debug/elf",
"elf.EM_SCORE7": "debug/elf",
"elf.EM_SEP": "debug/elf",
"elf.EM_SE_C17": "debug/elf",
"elf.EM_SE_C33": "debug/elf",
"elf.EM_SH": "debug/elf",
"elf.EM_SHARC": "debug/elf",
"elf.EM_SLE9X": "debug/elf",
"elf.EM_SNP1K": "debug/elf",
"elf.EM_SPARC": "debug/elf",
"elf.EM_SPARC32PLUS": "debug/elf",
"elf.EM_SPARCV9": "debug/elf",
"elf.EM_ST100": "debug/elf",
"elf.EM_ST19": "debug/elf",
"elf.EM_ST200": "debug/elf",
"elf.EM_ST7": "debug/elf",
"elf.EM_ST9PLUS": "debug/elf",
"elf.EM_STARCORE": "debug/elf",
"elf.EM_STM8": "debug/elf",
"elf.EM_STXP7X": "debug/elf",
"elf.EM_SVX": "debug/elf",
"elf.EM_TILE64": "debug/elf",
"elf.EM_TILEGX": "debug/elf",
"elf.EM_TILEPRO": "debug/elf",
"elf.EM_TINYJ": "debug/elf",
"elf.EM_TI_ARP32": "debug/elf",
"elf.EM_TI_C2000": "debug/elf",
"elf.EM_TI_C5500": "debug/elf",
"elf.EM_TI_C6000": "debug/elf",
"elf.EM_TI_PRU": "debug/elf",
"elf.EM_TMM_GPP": "debug/elf",
"elf.EM_TPC": "debug/elf",
"elf.EM_TRICORE": "debug/elf",
"elf.EM_TRIMEDIA": "debug/elf",
"elf.EM_TSK3000": "debug/elf",
"elf.EM_UNICORE": "debug/elf",
"elf.EM_V800": "debug/elf",
"elf.EM_V850": "debug/elf",
"elf.EM_VAX": "debug/elf",
"elf.EM_VIDEOCORE": "debug/elf",
"elf.EM_VIDEOCORE3": "debug/elf",
"elf.EM_VIDEOCORE5": "debug/elf",
"elf.EM_VISIUM": "debug/elf",
"elf.EM_VPP500": "debug/elf",
"elf.EM_X86_64": "debug/elf",
"elf.EM_XCORE": "debug/elf",
"elf.EM_XGATE": "debug/elf",
"elf.EM_XIMO16": "debug/elf",
"elf.EM_XTENSA": "debug/elf",
"elf.EM_Z80": "debug/elf",
"elf.EM_ZSP": "debug/elf",
"elf.ET_CORE": "debug/elf",
"elf.ET_DYN": "debug/elf",
"elf.ET_EXEC": "debug/elf",
@ -1673,6 +1815,60 @@ var stdlib = map[string]string{
"elf.R_PPC_TPREL32": "debug/elf",
"elf.R_PPC_UADDR16": "debug/elf",
"elf.R_PPC_UADDR32": "debug/elf",
"elf.R_RISCV": "debug/elf",
"elf.R_RISCV_32": "debug/elf",
"elf.R_RISCV_64": "debug/elf",
"elf.R_RISCV_ADD16": "debug/elf",
"elf.R_RISCV_ADD32": "debug/elf",
"elf.R_RISCV_ADD64": "debug/elf",
"elf.R_RISCV_ADD8": "debug/elf",
"elf.R_RISCV_ALIGN": "debug/elf",
"elf.R_RISCV_BRANCH": "debug/elf",
"elf.R_RISCV_CALL": "debug/elf",
"elf.R_RISCV_CALL_PLT": "debug/elf",
"elf.R_RISCV_COPY": "debug/elf",
"elf.R_RISCV_GNU_VTENTRY": "debug/elf",
"elf.R_RISCV_GNU_VTINHERIT": "debug/elf",
"elf.R_RISCV_GOT_HI20": "debug/elf",
"elf.R_RISCV_GPREL_I": "debug/elf",
"elf.R_RISCV_GPREL_S": "debug/elf",
"elf.R_RISCV_HI20": "debug/elf",
"elf.R_RISCV_JAL": "debug/elf",
"elf.R_RISCV_JUMP_SLOT": "debug/elf",
"elf.R_RISCV_LO12_I": "debug/elf",
"elf.R_RISCV_LO12_S": "debug/elf",
"elf.R_RISCV_NONE": "debug/elf",
"elf.R_RISCV_PCREL_HI20": "debug/elf",
"elf.R_RISCV_PCREL_LO12_I": "debug/elf",
"elf.R_RISCV_PCREL_LO12_S": "debug/elf",
"elf.R_RISCV_RELATIVE": "debug/elf",
"elf.R_RISCV_RELAX": "debug/elf",
"elf.R_RISCV_RVC_BRANCH": "debug/elf",
"elf.R_RISCV_RVC_JUMP": "debug/elf",
"elf.R_RISCV_RVC_LUI": "debug/elf",
"elf.R_RISCV_SET16": "debug/elf",
"elf.R_RISCV_SET32": "debug/elf",
"elf.R_RISCV_SET6": "debug/elf",
"elf.R_RISCV_SET8": "debug/elf",
"elf.R_RISCV_SUB16": "debug/elf",
"elf.R_RISCV_SUB32": "debug/elf",
"elf.R_RISCV_SUB6": "debug/elf",
"elf.R_RISCV_SUB64": "debug/elf",
"elf.R_RISCV_SUB8": "debug/elf",
"elf.R_RISCV_TLS_DTPMOD32": "debug/elf",
"elf.R_RISCV_TLS_DTPMOD64": "debug/elf",
"elf.R_RISCV_TLS_DTPREL32": "debug/elf",
"elf.R_RISCV_TLS_DTPREL64": "debug/elf",
"elf.R_RISCV_TLS_GD_HI20": "debug/elf",
"elf.R_RISCV_TLS_GOT_HI20": "debug/elf",
"elf.R_RISCV_TLS_TPREL32": "debug/elf",
"elf.R_RISCV_TLS_TPREL64": "debug/elf",
"elf.R_RISCV_TPREL_ADD": "debug/elf",
"elf.R_RISCV_TPREL_HI20": "debug/elf",
"elf.R_RISCV_TPREL_I": "debug/elf",
"elf.R_RISCV_TPREL_LO12_I": "debug/elf",
"elf.R_RISCV_TPREL_LO12_S": "debug/elf",
"elf.R_RISCV_TPREL_S": "debug/elf",
"elf.R_SPARC": "debug/elf",
"elf.R_SPARC_10": "debug/elf",
"elf.R_SPARC_11": "debug/elf",
@ -2180,6 +2376,10 @@ var stdlib = map[string]string{
"http.Response": "net/http",
"http.ResponseWriter": "net/http",
"http.RoundTripper": "net/http",
"http.SameSite": "net/http",
"http.SameSiteDefaultMode": "net/http",
"http.SameSiteLaxMode": "net/http",
"http.SameSiteStrictMode": "net/http",
"http.Serve": "net/http",
"http.ServeContent": "net/http",
"http.ServeFile": "net/http",
@ -2214,6 +2414,7 @@ var stdlib = map[string]string{
"http.StatusLocked": "net/http",
"http.StatusLoopDetected": "net/http",
"http.StatusMethodNotAllowed": "net/http",
"http.StatusMisdirectedRequest": "net/http",
"http.StatusMovedPermanently": "net/http",
"http.StatusMultiStatus": "net/http",
"http.StatusMultipleChoices": "net/http",
@ -2499,6 +2700,7 @@ var stdlib = map[string]string{
"macho.Cpu386": "debug/macho",
"macho.CpuAmd64": "debug/macho",
"macho.CpuArm": "debug/macho",
"macho.CpuArm64": "debug/macho",
"macho.CpuPpc": "debug/macho",
"macho.CpuPpc64": "debug/macho",
"macho.Dylib": "debug/macho",
@ -2780,6 +2982,7 @@ var stdlib = map[string]string{
"net.InvalidAddrError": "net",
"net.JoinHostPort": "net",
"net.Listen": "net",
"net.ListenConfig": "net",
"net.ListenIP": "net",
"net.ListenMulticastUDP": "net",
"net.ListenPacket": "net",
@ -2875,6 +3078,7 @@ var stdlib = map[string]string{
"os.ModeDevice": "os",
"os.ModeDir": "os",
"os.ModeExclusive": "os",
"os.ModeIrregular": "os",
"os.ModeNamedPipe": "os",
"os.ModePerm": "os",
"os.ModeSetgid": "os",
@ -2923,6 +3127,7 @@ var stdlib = map[string]string{
"os.TempDir": "os",
"os.Truncate": "os",
"os.Unsetenv": "os",
"os.UserCacheDir": "os",
"palette.Plan9": "image/color/palette",
"palette.WebSafe": "image/color/palette",
"parse.ActionNode": "text/template/parse",
@ -2997,9 +3202,25 @@ var stdlib = map[string]string{
"pe.File": "debug/pe",
"pe.FileHeader": "debug/pe",
"pe.FormatError": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_ARCHITECTURE": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_BASERELOC": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_DEBUG": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_EXCEPTION": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_EXPORT": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_GLOBALPTR": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_IAT": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_IMPORT": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_RESOURCE": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_SECURITY": "debug/pe",
"pe.IMAGE_DIRECTORY_ENTRY_TLS": "debug/pe",
"pe.IMAGE_FILE_MACHINE_AM33": "debug/pe",
"pe.IMAGE_FILE_MACHINE_AMD64": "debug/pe",
"pe.IMAGE_FILE_MACHINE_ARM": "debug/pe",
"pe.IMAGE_FILE_MACHINE_ARM64": "debug/pe",
"pe.IMAGE_FILE_MACHINE_EBC": "debug/pe",
"pe.IMAGE_FILE_MACHINE_I386": "debug/pe",
"pe.IMAGE_FILE_MACHINE_IA64": "debug/pe",
@ -3360,6 +3581,7 @@ var stdlib = map[string]string{
"sha512.Sum512_224": "crypto/sha512",
"sha512.Sum512_256": "crypto/sha512",
"signal.Ignore": "os/signal",
"signal.Ignored": "os/signal",
"signal.Notify": "os/signal",
"signal.Reset": "os/signal",
"signal.Stop": "os/signal",
@ -4077,10 +4299,13 @@ var stdlib = map[string]string{
"syscall.CertFreeCertificateChain": "syscall",
"syscall.CertFreeCertificateContext": "syscall",
"syscall.CertGetCertificateChain": "syscall",
"syscall.CertInfo": "syscall",
"syscall.CertOpenStore": "syscall",
"syscall.CertOpenSystemStore": "syscall",
"syscall.CertRevocationCrlInfo": "syscall",
"syscall.CertRevocationInfo": "syscall",
"syscall.CertSimpleChain": "syscall",
"syscall.CertTrustListInfo": "syscall",
"syscall.CertTrustStatus": "syscall",
"syscall.CertUsageMatch": "syscall",
"syscall.CertVerifyCertificateChainPolicy": "syscall",
@ -6588,6 +6813,7 @@ var stdlib = map[string]string{
"syscall.Pipe": "syscall",
"syscall.Pipe2": "syscall",
"syscall.PivotRoot": "syscall",
"syscall.Pointer": "syscall",
"syscall.PostQueuedCompletionStatus": "syscall",
"syscall.Pread": "syscall",
"syscall.Proc": "syscall",
@ -8536,6 +8762,7 @@ var stdlib = map[string]string{
"syscall.TOKEN_ADJUST_DEFAULT": "syscall",
"syscall.TOKEN_ADJUST_GROUPS": "syscall",
"syscall.TOKEN_ADJUST_PRIVILEGES": "syscall",
"syscall.TOKEN_ADJUST_SESSIONID": "syscall",
"syscall.TOKEN_ALL_ACCESS": "syscall",
"syscall.TOKEN_ASSIGN_PRIMARY": "syscall",
"syscall.TOKEN_DUPLICATE": "syscall",
@ -9109,8 +9336,16 @@ var stdlib = map[string]string{
"token.VAR": "go/token",
"token.XOR": "go/token",
"token.XOR_ASSIGN": "go/token",
"trace.IsEnabled": "runtime/trace",
"trace.Log": "runtime/trace",
"trace.Logf": "runtime/trace",
"trace.NewTask": "runtime/trace",
"trace.Region": "runtime/trace",
"trace.Start": "runtime/trace",
"trace.StartRegion": "runtime/trace",
"trace.Stop": "runtime/trace",
"trace.Task": "runtime/trace",
"trace.WithRegion": "runtime/trace",
"types.Array": "go/types",
"types.AssertableTo": "go/types",
"types.AssignableTo": "go/types",
@ -9180,6 +9415,7 @@ var stdlib = map[string]string{
"types.NewField": "go/types",
"types.NewFunc": "go/types",
"types.NewInterface": "go/types",
"types.NewInterfaceType": "go/types",
"types.NewLabel": "go/types",
"types.NewMap": "go/types",
"types.NewMethodSet": "go/types",

View File

@ -18,6 +18,11 @@ import (
// symlink named in the call may be traversed.
var TraverseLink = errors.New("fastwalk: traverse symlink, assuming target is a directory")
// SkipFiles is a used as a return value from WalkFuncs to indicate that the
// callback should not be called for any other files in the current directory.
// Child directories will still be traversed.
var SkipFiles = errors.New("fastwalk: skip remaining files in directory")
// Walk is a faster implementation of filepath.Walk.
//
// filepath.Walk's design necessarily calls os.Lstat on each file,

View File

@ -0,0 +1,13 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build darwin freebsd openbsd netbsd
package fastwalk
import "syscall"
func direntNamlen(dirent *syscall.Dirent) uint64 {
return uint64(dirent.Namlen)
}

View File

@ -0,0 +1,24 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build linux
// +build !appengine
package fastwalk
import (
"bytes"
"syscall"
"unsafe"
)
func direntNamlen(dirent *syscall.Dirent) uint64 {
const fixedHdr = uint16(unsafe.Offsetof(syscall.Dirent{}.Name))
nameBuf := (*[unsafe.Sizeof(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0]))
nameLen := bytes.IndexByte(nameBuf[:dirent.Reclen-fixedHdr], 0)
if nameLen < 0 {
panic("failed to find terminating 0 byte in dirent")
}
return uint64(nameLen)
}

View File

@ -20,8 +20,16 @@ func readDir(dirName string, fn func(dirName, entName string, typ os.FileMode) e
if err != nil {
return err
}
skipFiles := false
for _, fi := range fis {
if fi.Mode().IsRegular() && skipFiles {
continue
}
if err := fn(dirName, fi.Name(), fi.Mode()&os.ModeType); err != nil {
if err == SkipFiles {
skipFiles = true
continue
}
return err
}
}

View File

@ -8,7 +8,6 @@
package fastwalk
import (
"bytes"
"fmt"
"os"
"syscall"
@ -32,6 +31,7 @@ func readDir(dirName string, fn func(dirName, entName string, typ os.FileMode) e
buf := make([]byte, blockSize) // stack-allocated; doesn't escape
bufp := 0 // starting read position in buf
nbuf := 0 // end valid data in buf
skipFiles := false
for {
if bufp >= nbuf {
bufp = 0
@ -62,7 +62,14 @@ func readDir(dirName string, fn func(dirName, entName string, typ os.FileMode) e
}
typ = fi.Mode() & os.ModeType
}
if skipFiles && typ.IsRegular() {
continue
}
if err := fn(dirName, name, typ); err != nil {
if err == SkipFiles {
skipFiles = true
continue
}
return err
}
}
@ -106,10 +113,7 @@ func parseDirEnt(buf []byte) (consumed int, name string, typ os.FileMode) {
}
nameBuf := (*[unsafe.Sizeof(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0]))
nameLen := bytes.IndexByte(nameBuf[:], 0)
if nameLen < 0 {
panic("failed to find terminating 0 byte in dirent")
}
nameLen := direntNamlen(dirent)
// Special cases for common things:
if nameLen == 1 && nameBuf[0] == '.' {

209
vendor/golang.org/x/tools/internal/gopathwalk/walk.go generated vendored Normal file
View File

@ -0,0 +1,209 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package gopathwalk is like filepath.Walk but specialized for finding Go
// packages, particularly in $GOPATH and $GOROOT.
package gopathwalk
import (
"bufio"
"bytes"
"fmt"
"go/build"
"golang.org/x/tools/internal/fastwalk"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
)
// Options controls the behavior of a Walk call.
type Options struct {
Debug bool // Enable debug logging
ModulesEnabled bool // Search module caches. Also disables legacy goimports ignore rules.
}
// Walk walks Go source directories ($GOROOT, $GOPATH, etc) to find packages.
// For each package found, add will be called (concurrently) with the absolute
// paths of the containing source directory and the package directory.
func Walk(add func(srcDir string, dir string), opts Options) {
for _, srcDir := range build.Default.SrcDirs() {
walkDir(srcDir, add, opts)
}
}
func walkDir(srcDir string, add func(string, string), opts Options) {
if opts.Debug {
log.Printf("scanning %s", srcDir)
}
w := &walker{
srcDir: srcDir,
srcV: filepath.Join(srcDir, "v"),
srcMod: filepath.Join(srcDir, "mod"),
add: add,
opts: opts,
}
w.init()
if err := fastwalk.Walk(srcDir, w.walk); err != nil {
log.Printf("goimports: scanning directory %v: %v", srcDir, err)
}
if opts.Debug {
defer log.Printf("scanned %s", srcDir)
}
}
// walker is the callback for fastwalk.Walk.
type walker struct {
srcDir string // The source directory to scan.
srcV, srcMod string // vgo-style module cache dirs. Optional.
add func(string, string) // The callback that will be invoked for every possible Go package dir.
opts Options // Options passed to Walk by the user.
ignoredDirs []os.FileInfo // The ignored directories, loaded from .goimportsignore files.
}
// init initializes the walker based on its Options.
func (w *walker) init() {
if !w.opts.ModulesEnabled {
w.ignoredDirs = w.getIgnoredDirs(w.srcDir)
}
}
// getIgnoredDirs reads an optional config file at <path>/.goimportsignore
// of relative directories to ignore when scanning for go files.
// The provided path is one of the $GOPATH entries with "src" appended.
func (w *walker) getIgnoredDirs(path string) []os.FileInfo {
file := filepath.Join(path, ".goimportsignore")
slurp, err := ioutil.ReadFile(file)
if w.opts.Debug {
if err != nil {
log.Print(err)
} else {
log.Printf("Read %s", file)
}
}
if err != nil {
return nil
}
var ignoredDirs []os.FileInfo
bs := bufio.NewScanner(bytes.NewReader(slurp))
for bs.Scan() {
line := strings.TrimSpace(bs.Text())
if line == "" || strings.HasPrefix(line, "#") {
continue
}
full := filepath.Join(path, line)
if fi, err := os.Stat(full); err == nil {
ignoredDirs = append(ignoredDirs, fi)
if w.opts.Debug {
log.Printf("Directory added to ignore list: %s", full)
}
} else if w.opts.Debug {
log.Printf("Error statting entry in .goimportsignore: %v", err)
}
}
return ignoredDirs
}
func (w *walker) shouldSkipDir(fi os.FileInfo) bool {
for _, ignoredDir := range w.ignoredDirs {
if os.SameFile(fi, ignoredDir) {
return true
}
}
return false
}
func (w *walker) walk(path string, typ os.FileMode) error {
if !w.opts.ModulesEnabled && (path == w.srcV || path == w.srcMod) {
return filepath.SkipDir
}
dir := filepath.Dir(path)
if typ.IsRegular() {
if dir == w.srcDir {
// Doesn't make sense to have regular files
// directly in your $GOPATH/src or $GOROOT/src.
return fastwalk.SkipFiles
}
if !strings.HasSuffix(path, ".go") {
return nil
}
w.add(w.srcDir, dir)
return fastwalk.SkipFiles
}
if typ == os.ModeDir {
base := filepath.Base(path)
if base == "" || base[0] == '.' || base[0] == '_' ||
base == "testdata" || (!w.opts.ModulesEnabled && base == "node_modules") {
return filepath.SkipDir
}
fi, err := os.Lstat(path)
if err == nil && w.shouldSkipDir(fi) {
return filepath.SkipDir
}
return nil
}
if typ == os.ModeSymlink {
base := filepath.Base(path)
if strings.HasPrefix(base, ".#") {
// Emacs noise.
return nil
}
fi, err := os.Lstat(path)
if err != nil {
// Just ignore it.
return nil
}
if w.shouldTraverse(dir, fi) {
return fastwalk.TraverseLink
}
}
return nil
}
// shouldTraverse reports whether the symlink fi, found in dir,
// should be followed. It makes sure symlinks were never visited
// before to avoid symlink loops.
func (w *walker) shouldTraverse(dir string, fi os.FileInfo) bool {
path := filepath.Join(dir, fi.Name())
target, err := filepath.EvalSymlinks(path)
if err != nil {
return false
}
ts, err := os.Stat(target)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return false
}
if !ts.IsDir() {
return false
}
if w.shouldSkipDir(ts) {
return false
}
// Check for symlink loops by statting each directory component
// and seeing if any are the same file as ts.
for {
parent := filepath.Dir(path)
if parent == path {
// Made it to the root without seeing a cycle.
// Use this symlink.
return true
}
parentInfo, err := os.Stat(parent)
if err != nil {
return false
}
if os.SameFile(ts, parentInfo) {
// Cycle. Don't traverse.
return false
}
path = parent
}
}