TUN-6937: Bump golang.org/x/* packages to new release tags

This commit is contained in:
Devin Carr
2022-11-11 15:48:45 -08:00
parent 85b44695f0
commit 1fe4878264
244 changed files with 24750 additions and 3579 deletions

View File

@@ -796,7 +796,7 @@ func GetPackageExports(ctx context.Context, wrapped func(PackageExport), searchP
return getCandidatePkgs(ctx, callback, filename, filePkg, env)
}
var RequiredGoEnvVars = []string{"GO111MODULE", "GOFLAGS", "GOINSECURE", "GOMOD", "GOMODCACHE", "GONOPROXY", "GONOSUMDB", "GOPATH", "GOPROXY", "GOROOT", "GOSUMDB"}
var RequiredGoEnvVars = []string{"GO111MODULE", "GOFLAGS", "GOINSECURE", "GOMOD", "GOMODCACHE", "GONOPROXY", "GONOSUMDB", "GOPATH", "GOPROXY", "GOROOT", "GOSUMDB", "GOWORK"}
// ProcessEnv contains environment variables and settings that affect the use of
// the go command, the go/build package, etc.
@@ -906,7 +906,7 @@ func (e *ProcessEnv) GetResolver() (Resolver, error) {
if err := e.init(); err != nil {
return nil, err
}
if len(e.Env["GOMOD"]) == 0 {
if len(e.Env["GOMOD"]) == 0 && len(e.Env["GOWORK"]) == 0 {
e.resolver = newGopathResolver(e)
return e.resolver, nil
}

View File

@@ -103,12 +103,17 @@ func ApplyFixes(fixes []*ImportFix, filename string, src []byte, opt *Options, e
return formatFile(fileSet, file, src, nil, opt)
}
func formatFile(fileSet *token.FileSet, file *ast.File, src []byte, adjust func(orig []byte, src []byte) []byte, opt *Options) ([]byte, error) {
mergeImports(fileSet, file)
sortImports(opt.LocalPrefix, fileSet, file)
imps := astutil.Imports(fileSet, file)
// formatFile formats the file syntax tree.
// It may mutate the token.FileSet.
//
// If an adjust function is provided, it is called after formatting
// with the original source (formatFile's src parameter) and the
// formatted file, and returns the postpocessed result.
func formatFile(fset *token.FileSet, file *ast.File, src []byte, adjust func(orig []byte, src []byte) []byte, opt *Options) ([]byte, error) {
mergeImports(file)
sortImports(opt.LocalPrefix, fset.File(file.Pos()), file)
var spacesBefore []string // import paths we need spaces before
for _, impSection := range imps {
for _, impSection := range astutil.Imports(fset, file) {
// Within each block of contiguous imports, see if any
// import lines are in different group numbers. If so,
// we'll need to put a space between them so it's
@@ -132,7 +137,7 @@ func formatFile(fileSet *token.FileSet, file *ast.File, src []byte, adjust func(
printConfig := &printer.Config{Mode: printerMode, Tabwidth: opt.TabWidth}
var buf bytes.Buffer
err := printConfig.Fprint(&buf, fileSet, file)
err := printConfig.Fprint(&buf, fset, file)
if err != nil {
return nil, err
}
@@ -276,11 +281,11 @@ func cutSpace(b []byte) (before, middle, after []byte) {
}
// matchSpace reformats src to use the same space context as orig.
// 1) If orig begins with blank lines, matchSpace inserts them at the beginning of src.
// 2) matchSpace copies the indentation of the first non-blank line in orig
// to every non-blank line in src.
// 3) matchSpace copies the trailing space from orig and uses it in place
// of src's trailing space.
// 1. If orig begins with blank lines, matchSpace inserts them at the beginning of src.
// 2. matchSpace copies the indentation of the first non-blank line in orig
// to every non-blank line in src.
// 3. matchSpace copies the trailing space from orig and uses it in place
// of src's trailing space.
func matchSpace(orig []byte, src []byte) []byte {
before, _, after := cutSpace(orig)
i := bytes.LastIndex(before, []byte{'\n'})
@@ -306,7 +311,7 @@ func matchSpace(orig []byte, src []byte) []byte {
return b.Bytes()
}
var impLine = regexp.MustCompile(`^\s+(?:[\w\.]+\s+)?"(.+)"`)
var impLine = regexp.MustCompile(`^\s+(?:[\w\.]+\s+)?"(.+?)"`)
func addImportSpaces(r io.Reader, breaks []string) ([]byte, error) {
var out bytes.Buffer

View File

@@ -34,7 +34,8 @@ type ModuleResolver struct {
scannedRoots map[gopathwalk.Root]bool
initialized bool
main *gocommand.ModuleJSON
mains []*gocommand.ModuleJSON
mainByDir map[string]*gocommand.ModuleJSON
modsByModPath []*gocommand.ModuleJSON // All modules, ordered by # of path components in module Path...
modsByDir []*gocommand.ModuleJSON // ...or Dir.
@@ -69,21 +70,29 @@ func (r *ModuleResolver) init() error {
Logf: r.env.Logf,
WorkingDir: r.env.WorkingDir,
}
mainMod, vendorEnabled, err := gocommand.VendorEnabled(context.TODO(), inv, r.env.GocmdRunner)
if err != nil {
return err
vendorEnabled := false
var mainModVendor *gocommand.ModuleJSON
// Module vendor directories are ignored in workspace mode:
// https://go.googlesource.com/proposal/+/master/design/45713-workspace.md
if len(r.env.Env["GOWORK"]) == 0 {
vendorEnabled, mainModVendor, err = gocommand.VendorEnabled(context.TODO(), inv, r.env.GocmdRunner)
if err != nil {
return err
}
}
if mainMod != nil && vendorEnabled {
if mainModVendor != nil && vendorEnabled {
// Vendor mode is on, so all the non-Main modules are irrelevant,
// and we need to search /vendor for everything.
r.main = mainMod
r.mains = []*gocommand.ModuleJSON{mainModVendor}
r.dummyVendorMod = &gocommand.ModuleJSON{
Path: "",
Dir: filepath.Join(mainMod.Dir, "vendor"),
Dir: filepath.Join(mainModVendor.Dir, "vendor"),
}
r.modsByModPath = []*gocommand.ModuleJSON{mainMod, r.dummyVendorMod}
r.modsByDir = []*gocommand.ModuleJSON{mainMod, r.dummyVendorMod}
r.modsByModPath = []*gocommand.ModuleJSON{mainModVendor, r.dummyVendorMod}
r.modsByDir = []*gocommand.ModuleJSON{mainModVendor, r.dummyVendorMod}
} else {
// Vendor mode is off, so run go list -m ... to find everything.
err := r.initAllMods()
@@ -122,8 +131,10 @@ func (r *ModuleResolver) init() error {
r.roots = []gopathwalk.Root{
{filepath.Join(goenv["GOROOT"], "/src"), gopathwalk.RootGOROOT},
}
if r.main != nil {
r.roots = append(r.roots, gopathwalk.Root{r.main.Dir, gopathwalk.RootCurrentModule})
r.mainByDir = make(map[string]*gocommand.ModuleJSON)
for _, main := range r.mains {
r.roots = append(r.roots, gopathwalk.Root{main.Dir, gopathwalk.RootCurrentModule})
r.mainByDir[main.Dir] = main
}
if vendorEnabled {
r.roots = append(r.roots, gopathwalk.Root{r.dummyVendorMod.Dir, gopathwalk.RootOther})
@@ -189,7 +200,7 @@ func (r *ModuleResolver) initAllMods() error {
r.modsByModPath = append(r.modsByModPath, mod)
r.modsByDir = append(r.modsByDir, mod)
if mod.Main {
r.main = mod
r.mains = append(r.mains, mod)
}
}
return nil
@@ -609,7 +620,7 @@ func (r *ModuleResolver) scanDirForPackage(root gopathwalk.Root, dir string) dir
}
switch root.Type {
case gopathwalk.RootCurrentModule:
importPath = path.Join(r.main.Path, filepath.ToSlash(subdir))
importPath = path.Join(r.mainByDir[root.Path].Path, filepath.ToSlash(subdir))
case gopathwalk.RootModuleCache:
matches := modCacheRegexp.FindStringSubmatch(subdir)
if len(matches) == 0 {

View File

@@ -3,19 +3,23 @@
// license that can be found in the LICENSE file.
// Hacked up copy of go/ast/import.go
// Modified to use a single token.File in preference to a FileSet.
package imports
import (
"go/ast"
"go/token"
"log"
"sort"
"strconv"
)
// sortImports sorts runs of consecutive import lines in import blocks in f.
// It also removes duplicate imports when it is possible to do so without data loss.
func sortImports(localPrefix string, fset *token.FileSet, f *ast.File) {
//
// It may mutate the token.File.
func sortImports(localPrefix string, tokFile *token.File, f *ast.File) {
for i, d := range f.Decls {
d, ok := d.(*ast.GenDecl)
if !ok || d.Tok != token.IMPORT {
@@ -38,21 +42,21 @@ func sortImports(localPrefix string, fset *token.FileSet, f *ast.File) {
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 {
if j > i && tokFile.Line(s.Pos()) > 1+tokFile.Line(d.Specs[j-1].End()) {
// j begins a new run. End this one.
specs = append(specs, sortSpecs(localPrefix, fset, f, d.Specs[i:j])...)
specs = append(specs, sortSpecs(localPrefix, tokFile, f, d.Specs[i:j])...)
i = j
}
}
specs = append(specs, sortSpecs(localPrefix, fset, f, d.Specs[i:])...)
specs = append(specs, sortSpecs(localPrefix, tokFile, f, d.Specs[i:])...)
d.Specs = specs
// Deduping can leave a blank line before the rparen; clean that up.
if len(d.Specs) > 0 {
lastSpec := d.Specs[len(d.Specs)-1]
lastLine := fset.Position(lastSpec.Pos()).Line
if rParenLine := fset.Position(d.Rparen).Line; rParenLine > lastLine+1 {
fset.File(d.Rparen).MergeLine(rParenLine - 1)
lastLine := tokFile.PositionFor(lastSpec.Pos(), false).Line
if rParenLine := tokFile.PositionFor(d.Rparen, false).Line; rParenLine > lastLine+1 {
tokFile.MergeLine(rParenLine - 1) // has side effects!
}
}
}
@@ -60,7 +64,8 @@ func sortImports(localPrefix string, fset *token.FileSet, f *ast.File) {
// mergeImports merges all the import declarations into the first one.
// Taken from golang.org/x/tools/ast/astutil.
func mergeImports(fset *token.FileSet, f *ast.File) {
// This does not adjust line numbers properly
func mergeImports(f *ast.File) {
if len(f.Decls) <= 1 {
return
}
@@ -142,7 +147,9 @@ type posSpan struct {
End token.Pos
}
func sortSpecs(localPrefix string, fset *token.FileSet, f *ast.File, specs []ast.Spec) []ast.Spec {
// sortSpecs sorts the import specs within each import decl.
// It may mutate the token.File.
func sortSpecs(localPrefix string, tokFile *token.File, f *ast.File, specs []ast.Spec) []ast.Spec {
// Can't short-circuit here even if specs are already sorted,
// since they might yet need deduplication.
// A lone import, however, may be safely ignored.
@@ -158,7 +165,7 @@ func sortSpecs(localPrefix string, fset *token.FileSet, f *ast.File, specs []ast
// Identify comments in this range.
// Any comment from pos[0].Start to the final line counts.
lastLine := fset.Position(pos[len(pos)-1].End).Line
lastLine := tokFile.Line(pos[len(pos)-1].End)
cstart := len(f.Comments)
cend := len(f.Comments)
for i, g := range f.Comments {
@@ -168,7 +175,7 @@ func sortSpecs(localPrefix string, fset *token.FileSet, f *ast.File, specs []ast
if i < cstart {
cstart = i
}
if fset.Position(g.End()).Line > lastLine {
if tokFile.Line(g.End()) > lastLine {
cend = i
break
}
@@ -201,7 +208,7 @@ func sortSpecs(localPrefix string, fset *token.FileSet, f *ast.File, specs []ast
deduped = append(deduped, s)
} else {
p := s.Pos()
fset.File(p).MergeLine(fset.Position(p).Line)
tokFile.MergeLine(tokFile.Line(p)) // has side effects!
}
}
specs = deduped
@@ -232,13 +239,22 @@ func sortSpecs(localPrefix string, fset *token.FileSet, f *ast.File, specs []ast
// Fixup comments can insert blank lines, because import specs are on different lines.
// We remove those blank lines here by merging import spec to the first import spec line.
firstSpecLine := fset.Position(specs[0].Pos()).Line
firstSpecLine := tokFile.Line(specs[0].Pos())
for _, s := range specs[1:] {
p := s.Pos()
line := fset.File(p).Line(p)
line := tokFile.Line(p)
for previousLine := line - 1; previousLine >= firstSpecLine; {
fset.File(p).MergeLine(previousLine)
previousLine--
// MergeLine can panic. Avoid the panic at the cost of not removing the blank line
// golang/go#50329
if previousLine > 0 && previousLine < tokFile.LineCount() {
tokFile.MergeLine(previousLine) // has side effects!
previousLine--
} else {
// try to gather some data to diagnose how this could happen
req := "Please report what the imports section of your go file looked like."
log.Printf("panic avoided: first:%d line:%d previous:%d max:%d. %s",
firstSpecLine, line, previousLine, tokFile.LineCount(), req)
}
}
}
return specs

View File

@@ -88,6 +88,7 @@ var stdlib = map[string][]string{
"ContainsAny",
"ContainsRune",
"Count",
"Cut",
"Equal",
"EqualFold",
"ErrTooLarge",
@@ -180,6 +181,8 @@ var stdlib = map[string][]string{
"NewReader",
"NewWriter",
"Order",
"Reader",
"Writer",
},
"compress/zlib": []string{
"BestCompression",
@@ -641,7 +644,9 @@ var stdlib = map[string][]string{
"Named",
"NamedArg",
"NullBool",
"NullByte",
"NullFloat64",
"NullInt16",
"NullInt32",
"NullInt64",
"NullString",
@@ -707,6 +712,11 @@ var stdlib = map[string][]string{
"ValueConverter",
"Valuer",
},
"debug/buildinfo": []string{
"BuildInfo",
"Read",
"ReadFile",
},
"debug/dwarf": []string{
"AddrType",
"ArrayType",
@@ -1940,6 +1950,7 @@ var stdlib = map[string][]string{
"R_PPC64_REL24_NOTOC",
"R_PPC64_REL32",
"R_PPC64_REL64",
"R_PPC64_RELATIVE",
"R_PPC64_SECTOFF_DS",
"R_PPC64_SECTOFF_LO_DS",
"R_PPC64_TLS",
@@ -2248,6 +2259,7 @@ var stdlib = map[string][]string{
"SHT_LOOS",
"SHT_LOPROC",
"SHT_LOUSER",
"SHT_MIPS_ABIFLAGS",
"SHT_NOBITS",
"SHT_NOTE",
"SHT_NULL",
@@ -2542,6 +2554,7 @@ var stdlib = map[string][]string{
"Symbol",
},
"debug/plan9obj": []string{
"ErrNoSymbols",
"File",
"FileHeader",
"Magic386",
@@ -2901,6 +2914,7 @@ var stdlib = map[string][]string{
"Importer",
"IncDecStmt",
"IndexExpr",
"IndexListExpr",
"Inspect",
"InterfaceType",
"IsExported",
@@ -3061,6 +3075,7 @@ var stdlib = map[string][]string{
"ParseExpr",
"ParseExprFrom",
"ParseFile",
"SkipObjectResolution",
"SpuriousErrors",
"Trace",
},
@@ -3173,6 +3188,7 @@ var stdlib = map[string][]string{
"SUB",
"SUB_ASSIGN",
"SWITCH",
"TILDE",
"TYPE",
"Token",
"UnaryPrec",
@@ -3181,6 +3197,7 @@ var stdlib = map[string][]string{
"XOR_ASSIGN",
},
"go/types": []string{
"ArgumentError",
"Array",
"AssertableTo",
"AssignableTo",
@@ -3199,6 +3216,7 @@ var stdlib = map[string][]string{
"Complex64",
"Config",
"Const",
"Context",
"ConvertibleTo",
"DefPredeclaredTestFuncs",
"Default",
@@ -3218,6 +3236,8 @@ var stdlib = map[string][]string{
"ImporterFrom",
"Info",
"Initializer",
"Instance",
"Instantiate",
"Int",
"Int16",
"Int32",
@@ -3248,6 +3268,7 @@ var stdlib = map[string][]string{
"NewChan",
"NewChecker",
"NewConst",
"NewContext",
"NewField",
"NewFunc",
"NewInterface",
@@ -3262,10 +3283,14 @@ var stdlib = map[string][]string{
"NewPointer",
"NewScope",
"NewSignature",
"NewSignatureType",
"NewSlice",
"NewStruct",
"NewTerm",
"NewTuple",
"NewTypeName",
"NewTypeParam",
"NewUnion",
"NewVar",
"Nil",
"Object",
@@ -3290,11 +3315,15 @@ var stdlib = map[string][]string{
"StdSizes",
"String",
"Struct",
"Term",
"Tuple",
"Typ",
"Type",
"TypeAndValue",
"TypeList",
"TypeName",
"TypeParam",
"TypeParamList",
"TypeString",
"Uint",
"Uint16",
@@ -3302,6 +3331,7 @@ var stdlib = map[string][]string{
"Uint64",
"Uint8",
"Uintptr",
"Union",
"Universe",
"Unsafe",
"UnsafePointer",
@@ -3441,6 +3471,7 @@ var stdlib = map[string][]string{
"Pt",
"RGBA",
"RGBA64",
"RGBA64Image",
"Rect",
"Rectangle",
"RegisterFormat",
@@ -3507,6 +3538,7 @@ var stdlib = map[string][]string{
"Op",
"Over",
"Quantizer",
"RGBA64Image",
"Src",
},
"image/gif": []string{
@@ -3612,6 +3644,7 @@ var stdlib = map[string][]string{
"FS",
"File",
"FileInfo",
"FileInfoToDirEntry",
"FileMode",
"Glob",
"GlobFS",
@@ -3772,15 +3805,18 @@ var stdlib = map[string][]string{
"Max",
"MaxFloat32",
"MaxFloat64",
"MaxInt",
"MaxInt16",
"MaxInt32",
"MaxInt64",
"MaxInt8",
"MaxUint",
"MaxUint16",
"MaxUint32",
"MaxUint64",
"MaxUint8",
"Min",
"MinInt",
"MinInt16",
"MinInt32",
"MinInt64",
@@ -4068,9 +4104,11 @@ var stdlib = map[string][]string{
"SRV",
"SplitHostPort",
"TCPAddr",
"TCPAddrFromAddrPort",
"TCPConn",
"TCPListener",
"UDPAddr",
"UDPAddrFromAddrPort",
"UDPConn",
"UnixAddr",
"UnixConn",
@@ -4078,6 +4116,7 @@ var stdlib = map[string][]string{
"UnknownNetworkError",
},
"net/http": []string{
"AllowQuerySemicolons",
"CanonicalHeaderKey",
"Client",
"CloseNotifier",
@@ -4129,6 +4168,7 @@ var stdlib = map[string][]string{
"ListenAndServe",
"ListenAndServeTLS",
"LocalAddrContextKey",
"MaxBytesHandler",
"MaxBytesReader",
"MethodConnect",
"MethodDelete",
@@ -4325,6 +4365,25 @@ var stdlib = map[string][]string{
"ParseDate",
"ReadMessage",
},
"net/netip": []string{
"Addr",
"AddrFrom16",
"AddrFrom4",
"AddrFromSlice",
"AddrPort",
"AddrPortFrom",
"IPv4Unspecified",
"IPv6LinkLocalAllNodes",
"IPv6Unspecified",
"MustParseAddr",
"MustParseAddrPort",
"MustParsePrefix",
"ParseAddr",
"ParseAddrPort",
"ParsePrefix",
"Prefix",
"PrefixFrom",
},
"net/rpc": []string{
"Accept",
"Call",
@@ -4628,6 +4687,8 @@ var stdlib = map[string][]string{
"Method",
"New",
"NewAt",
"Pointer",
"PointerTo",
"Ptr",
"PtrTo",
"RecvDir",
@@ -4660,6 +4721,7 @@ var stdlib = map[string][]string{
"Value",
"ValueError",
"ValueOf",
"VisibleFields",
"Zero",
},
"regexp": []string{
@@ -4799,11 +4861,17 @@ var stdlib = map[string][]string{
"UnlockOSThread",
"Version",
},
"runtime/cgo": []string{
"Handle",
"NewHandle",
},
"runtime/debug": []string{
"BuildInfo",
"BuildSetting",
"FreeOSMemory",
"GCStats",
"Module",
"ParseBuildInfo",
"PrintStack",
"ReadBuildInfo",
"ReadGCStats",
@@ -4915,16 +4983,19 @@ var stdlib = map[string][]string{
"QuoteRuneToGraphic",
"QuoteToASCII",
"QuoteToGraphic",
"QuotedPrefix",
"Unquote",
"UnquoteChar",
},
"strings": []string{
"Builder",
"Clone",
"Compare",
"Contains",
"ContainsAny",
"ContainsRune",
"Count",
"Cut",
"EqualFold",
"Fields",
"FieldsFunc",
@@ -9774,6 +9845,7 @@ var stdlib = map[string][]string{
"Syscall18",
"Syscall6",
"Syscall9",
"SyscallN",
"Sysctl",
"SysctlUint32",
"Sysctlnode",
@@ -10183,7 +10255,6 @@ var stdlib = map[string][]string{
"Value",
"ValueError",
"ValueOf",
"Wrapper",
},
"testing": []string{
"AllocsPerRun",
@@ -10194,9 +10265,11 @@ var stdlib = map[string][]string{
"CoverBlock",
"CoverMode",
"Coverage",
"F",
"Init",
"InternalBenchmark",
"InternalExample",
"InternalFuzzTarget",
"InternalTest",
"M",
"Main",
@@ -10294,9 +10367,11 @@ var stdlib = map[string][]string{
"ActionNode",
"BoolNode",
"BranchNode",
"BreakNode",
"ChainNode",
"CommandNode",
"CommentNode",
"ContinueNode",
"DotNode",
"FieldNode",
"IdentifierNode",
@@ -10310,9 +10385,11 @@ var stdlib = map[string][]string{
"Node",
"NodeAction",
"NodeBool",
"NodeBreak",
"NodeChain",
"NodeCommand",
"NodeComment",
"NodeContinue",
"NodeDot",
"NodeField",
"NodeIdentifier",
@@ -10334,6 +10411,7 @@ var stdlib = map[string][]string{
"PipeNode",
"Pos",
"RangeNode",
"SkipFuncCheck",
"StringNode",
"TemplateNode",
"TextNode",
@@ -10358,6 +10436,7 @@ var stdlib = map[string][]string{
"July",
"June",
"Kitchen",
"Layout",
"LoadLocation",
"LoadLocationFromTZData",
"Local",
@@ -10406,6 +10485,8 @@ var stdlib = map[string][]string{
"UTC",
"Unix",
"UnixDate",
"UnixMicro",
"UnixMilli",
"Until",
"Wednesday",
"Weekday",
@@ -10704,6 +10785,7 @@ var stdlib = map[string][]string{
"IsSurrogate",
},
"unicode/utf8": []string{
"AppendRune",
"DecodeLastRune",
"DecodeLastRuneInString",
"DecodeRune",