mirror of
https://github.com/containers/skopeo.git
synced 2025-09-17 15:30:38 +00:00
Merge pull request #2169 from containers/renovate/golang.org-x-exp-digest
fix(deps): update golang.org/x/exp digest to 6522937
This commit is contained in:
10
go.mod
10
go.mod
@@ -16,7 +16,7 @@ require (
|
|||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
github.com/stretchr/testify v1.8.4
|
github.com/stretchr/testify v1.8.4
|
||||||
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
|
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
|
||||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
|
golang.org/x/exp v0.0.0-20231127185646-65229373498e
|
||||||
golang.org/x/term v0.15.0
|
golang.org/x/term v0.15.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
@@ -116,14 +116,14 @@ require (
|
|||||||
go.opentelemetry.io/otel v1.19.0 // indirect
|
go.opentelemetry.io/otel v1.19.0 // indirect
|
||||||
go.opentelemetry.io/otel/metric v1.19.0 // indirect
|
go.opentelemetry.io/otel/metric v1.19.0 // indirect
|
||||||
go.opentelemetry.io/otel/trace v1.19.0 // indirect
|
go.opentelemetry.io/otel/trace v1.19.0 // indirect
|
||||||
golang.org/x/crypto v0.15.0 // indirect
|
golang.org/x/crypto v0.16.0 // indirect
|
||||||
golang.org/x/mod v0.13.0 // indirect
|
golang.org/x/mod v0.14.0 // indirect
|
||||||
golang.org/x/net v0.18.0 // indirect
|
golang.org/x/net v0.19.0 // indirect
|
||||||
golang.org/x/oauth2 v0.14.0 // indirect
|
golang.org/x/oauth2 v0.14.0 // indirect
|
||||||
golang.org/x/sync v0.5.0 // indirect
|
golang.org/x/sync v0.5.0 // indirect
|
||||||
golang.org/x/sys v0.15.0 // indirect
|
golang.org/x/sys v0.15.0 // indirect
|
||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
golang.org/x/tools v0.14.0 // indirect
|
golang.org/x/tools v0.16.0 // indirect
|
||||||
google.golang.org/appengine v1.6.8 // indirect
|
google.golang.org/appengine v1.6.8 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
|
||||||
google.golang.org/grpc v1.58.3 // indirect
|
google.golang.org/grpc v1.58.3 // indirect
|
||||||
|
20
go.sum
20
go.sum
@@ -420,19 +420,19 @@ golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPh
|
|||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
|
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
|
||||||
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
|
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No=
|
||||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
|
||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
|
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
|
||||||
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
@@ -446,8 +446,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
|
|||||||
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
|
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
|
||||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
|
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
|
||||||
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
|
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0=
|
golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0=
|
||||||
golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM=
|
golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM=
|
||||||
@@ -506,8 +506,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
|
|||||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
|
golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM=
|
||||||
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
|
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
102
vendor/golang.org/x/sys/execabs/execabs.go
generated
vendored
102
vendor/golang.org/x/sys/execabs/execabs.go
generated
vendored
@@ -1,102 +0,0 @@
|
|||||||
// Copyright 2020 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 execabs is a drop-in replacement for os/exec
|
|
||||||
// that requires PATH lookups to find absolute paths.
|
|
||||||
// That is, execabs.Command("cmd") runs the same PATH lookup
|
|
||||||
// as exec.Command("cmd"), but if the result is a path
|
|
||||||
// which is relative, the Run and Start methods will report
|
|
||||||
// an error instead of running the executable.
|
|
||||||
//
|
|
||||||
// See https://blog.golang.org/path-security for more information
|
|
||||||
// about when it may be necessary or appropriate to use this package.
|
|
||||||
package execabs
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
|
||||||
"reflect"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ErrNotFound is the error resulting if a path search failed to find an executable file.
|
|
||||||
// It is an alias for exec.ErrNotFound.
|
|
||||||
var ErrNotFound = exec.ErrNotFound
|
|
||||||
|
|
||||||
// Cmd represents an external command being prepared or run.
|
|
||||||
// It is an alias for exec.Cmd.
|
|
||||||
type Cmd = exec.Cmd
|
|
||||||
|
|
||||||
// Error is returned by LookPath when it fails to classify a file as an executable.
|
|
||||||
// It is an alias for exec.Error.
|
|
||||||
type Error = exec.Error
|
|
||||||
|
|
||||||
// An ExitError reports an unsuccessful exit by a command.
|
|
||||||
// It is an alias for exec.ExitError.
|
|
||||||
type ExitError = exec.ExitError
|
|
||||||
|
|
||||||
func relError(file, path string) error {
|
|
||||||
return fmt.Errorf("%s resolves to executable in current directory (.%c%s)", file, filepath.Separator, path)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LookPath searches for an executable named file in the directories
|
|
||||||
// named by the PATH environment variable. If file contains a slash,
|
|
||||||
// it is tried directly and the PATH is not consulted. The result will be
|
|
||||||
// an absolute path.
|
|
||||||
//
|
|
||||||
// LookPath differs from exec.LookPath in its handling of PATH lookups,
|
|
||||||
// which are used for file names without slashes. If exec.LookPath's
|
|
||||||
// PATH lookup would have returned an executable from the current directory,
|
|
||||||
// LookPath instead returns an error.
|
|
||||||
func LookPath(file string) (string, error) {
|
|
||||||
path, err := exec.LookPath(file)
|
|
||||||
if err != nil && !isGo119ErrDot(err) {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if filepath.Base(file) == file && !filepath.IsAbs(path) {
|
|
||||||
return "", relError(file, path)
|
|
||||||
}
|
|
||||||
return path, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func fixCmd(name string, cmd *exec.Cmd) {
|
|
||||||
if filepath.Base(name) == name && !filepath.IsAbs(cmd.Path) && !isGo119ErrFieldSet(cmd) {
|
|
||||||
// exec.Command was called with a bare binary name and
|
|
||||||
// exec.LookPath returned a path which is not absolute.
|
|
||||||
// Set cmd.lookPathErr and clear cmd.Path so that it
|
|
||||||
// cannot be run.
|
|
||||||
lookPathErr := (*error)(unsafe.Pointer(reflect.ValueOf(cmd).Elem().FieldByName("lookPathErr").Addr().Pointer()))
|
|
||||||
if *lookPathErr == nil {
|
|
||||||
*lookPathErr = relError(name, cmd.Path)
|
|
||||||
}
|
|
||||||
cmd.Path = ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CommandContext is like Command but includes a context.
|
|
||||||
//
|
|
||||||
// The provided context is used to kill the process (by calling os.Process.Kill)
|
|
||||||
// if the context becomes done before the command completes on its own.
|
|
||||||
func CommandContext(ctx context.Context, name string, arg ...string) *exec.Cmd {
|
|
||||||
cmd := exec.CommandContext(ctx, name, arg...)
|
|
||||||
fixCmd(name, cmd)
|
|
||||||
return cmd
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command returns the Cmd struct to execute the named program with the given arguments.
|
|
||||||
// See exec.Command for most details.
|
|
||||||
//
|
|
||||||
// Command differs from exec.Command in its handling of PATH lookups,
|
|
||||||
// which are used when the program name contains no slashes.
|
|
||||||
// If exec.Command would have returned an exec.Cmd configured to run an
|
|
||||||
// executable from the current directory, Command instead
|
|
||||||
// returns an exec.Cmd that will return an error from Start or Run.
|
|
||||||
func Command(name string, arg ...string) *exec.Cmd {
|
|
||||||
cmd := exec.Command(name, arg...)
|
|
||||||
fixCmd(name, cmd)
|
|
||||||
return cmd
|
|
||||||
}
|
|
17
vendor/golang.org/x/sys/execabs/execabs_go118.go
generated
vendored
17
vendor/golang.org/x/sys/execabs/execabs_go118.go
generated
vendored
@@ -1,17 +0,0 @@
|
|||||||
// Copyright 2022 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.
|
|
||||||
|
|
||||||
//go:build !go1.19
|
|
||||||
|
|
||||||
package execabs
|
|
||||||
|
|
||||||
import "os/exec"
|
|
||||||
|
|
||||||
func isGo119ErrDot(err error) bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func isGo119ErrFieldSet(cmd *exec.Cmd) bool {
|
|
||||||
return false
|
|
||||||
}
|
|
20
vendor/golang.org/x/sys/execabs/execabs_go119.go
generated
vendored
20
vendor/golang.org/x/sys/execabs/execabs_go119.go
generated
vendored
@@ -1,20 +0,0 @@
|
|||||||
// Copyright 2022 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.
|
|
||||||
|
|
||||||
//go:build go1.19
|
|
||||||
|
|
||||||
package execabs
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"os/exec"
|
|
||||||
)
|
|
||||||
|
|
||||||
func isGo119ErrDot(err error) bool {
|
|
||||||
return errors.Is(err, exec.ErrDot)
|
|
||||||
}
|
|
||||||
|
|
||||||
func isGo119ErrFieldSet(cmd *exec.Cmd) bool {
|
|
||||||
return cmd.Err != nil
|
|
||||||
}
|
|
15
vendor/golang.org/x/tools/go/internal/packagesdriver/sizes.go
generated
vendored
15
vendor/golang.org/x/tools/go/internal/packagesdriver/sizes.go
generated
vendored
@@ -13,16 +13,17 @@ import (
|
|||||||
"golang.org/x/tools/internal/gocommand"
|
"golang.org/x/tools/internal/gocommand"
|
||||||
)
|
)
|
||||||
|
|
||||||
var debug = false
|
|
||||||
|
|
||||||
func GetSizesForArgsGolist(ctx context.Context, inv gocommand.Invocation, gocmdRunner *gocommand.Runner) (string, string, error) {
|
func GetSizesForArgsGolist(ctx context.Context, inv gocommand.Invocation, gocmdRunner *gocommand.Runner) (string, string, error) {
|
||||||
inv.Verb = "list"
|
inv.Verb = "list"
|
||||||
inv.Args = []string{"-f", "{{context.GOARCH}} {{context.Compiler}}", "--", "unsafe"}
|
inv.Args = []string{"-f", "{{context.GOARCH}} {{context.Compiler}}", "--", "unsafe"}
|
||||||
stdout, stderr, friendlyErr, rawErr := gocmdRunner.RunRaw(ctx, inv)
|
stdout, stderr, friendlyErr, rawErr := gocmdRunner.RunRaw(ctx, inv)
|
||||||
var goarch, compiler string
|
var goarch, compiler string
|
||||||
if rawErr != nil {
|
if rawErr != nil {
|
||||||
if rawErrMsg := rawErr.Error(); strings.Contains(rawErrMsg, "cannot find main module") || strings.Contains(rawErrMsg, "go.mod file not found") {
|
rawErrMsg := rawErr.Error()
|
||||||
// User's running outside of a module. All bets are off. Get GOARCH and guess compiler is gc.
|
if strings.Contains(rawErrMsg, "cannot find main module") ||
|
||||||
|
strings.Contains(rawErrMsg, "go.mod file not found") {
|
||||||
|
// User's running outside of a module.
|
||||||
|
// All bets are off. Get GOARCH and guess compiler is gc.
|
||||||
// TODO(matloob): Is this a problem in practice?
|
// TODO(matloob): Is this a problem in practice?
|
||||||
inv.Verb = "env"
|
inv.Verb = "env"
|
||||||
inv.Args = []string{"GOARCH"}
|
inv.Args = []string{"GOARCH"}
|
||||||
@@ -32,8 +33,12 @@ func GetSizesForArgsGolist(ctx context.Context, inv gocommand.Invocation, gocmdR
|
|||||||
}
|
}
|
||||||
goarch = strings.TrimSpace(envout.String())
|
goarch = strings.TrimSpace(envout.String())
|
||||||
compiler = "gc"
|
compiler = "gc"
|
||||||
} else {
|
} else if friendlyErr != nil {
|
||||||
return "", "", friendlyErr
|
return "", "", friendlyErr
|
||||||
|
} else {
|
||||||
|
// This should be unreachable, but be defensive
|
||||||
|
// in case RunRaw's error results are inconsistent.
|
||||||
|
return "", "", rawErr
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fields := strings.Fields(stdout.String())
|
fields := strings.Fields(stdout.String())
|
||||||
|
2
vendor/golang.org/x/tools/go/packages/external.go
generated
vendored
2
vendor/golang.org/x/tools/go/packages/external.go
generated
vendored
@@ -12,8 +12,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
exec "golang.org/x/sys/execabs"
|
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
76
vendor/golang.org/x/tools/go/packages/golist.go
generated
vendored
76
vendor/golang.org/x/tools/go/packages/golist.go
generated
vendored
@@ -11,6 +11,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -20,7 +21,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
exec "golang.org/x/sys/execabs"
|
|
||||||
"golang.org/x/tools/go/internal/packagesdriver"
|
"golang.org/x/tools/go/internal/packagesdriver"
|
||||||
"golang.org/x/tools/internal/gocommand"
|
"golang.org/x/tools/internal/gocommand"
|
||||||
"golang.org/x/tools/internal/packagesinternal"
|
"golang.org/x/tools/internal/packagesinternal"
|
||||||
@@ -208,62 +208,6 @@ extractQueries:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only use go/packages' overlay processing if we're using a Go version
|
|
||||||
// below 1.16. Otherwise, go list handles it.
|
|
||||||
if goVersion, err := state.getGoVersion(); err == nil && goVersion < 16 {
|
|
||||||
modifiedPkgs, needPkgs, err := state.processGolistOverlay(response)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var containsCandidates []string
|
|
||||||
if len(containFiles) > 0 {
|
|
||||||
containsCandidates = append(containsCandidates, modifiedPkgs...)
|
|
||||||
containsCandidates = append(containsCandidates, needPkgs...)
|
|
||||||
}
|
|
||||||
if err := state.addNeededOverlayPackages(response, needPkgs); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// Check candidate packages for containFiles.
|
|
||||||
if len(containFiles) > 0 {
|
|
||||||
for _, id := range containsCandidates {
|
|
||||||
pkg, ok := response.seenPackages[id]
|
|
||||||
if !ok {
|
|
||||||
response.addPackage(&Package{
|
|
||||||
ID: id,
|
|
||||||
Errors: []Error{{
|
|
||||||
Kind: ListError,
|
|
||||||
Msg: fmt.Sprintf("package %s expected but not seen", id),
|
|
||||||
}},
|
|
||||||
})
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, f := range containFiles {
|
|
||||||
for _, g := range pkg.GoFiles {
|
|
||||||
if sameFile(f, g) {
|
|
||||||
response.addRoot(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Add root for any package that matches a pattern. This applies only to
|
|
||||||
// packages that are modified by overlays, since they are not added as
|
|
||||||
// roots automatically.
|
|
||||||
for _, pattern := range restPatterns {
|
|
||||||
match := matchPattern(pattern)
|
|
||||||
for _, pkgID := range modifiedPkgs {
|
|
||||||
pkg, ok := response.seenPackages[pkgID]
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if match(pkg.PkgPath) {
|
|
||||||
response.addRoot(pkg.ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sizeswg.Wait()
|
sizeswg.Wait()
|
||||||
if sizeserr != nil {
|
if sizeserr != nil {
|
||||||
return nil, sizeserr
|
return nil, sizeserr
|
||||||
@@ -271,24 +215,6 @@ extractQueries:
|
|||||||
return response.dr, nil
|
return response.dr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *golistState) addNeededOverlayPackages(response *responseDeduper, pkgs []string) error {
|
|
||||||
if len(pkgs) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
dr, err := state.createDriverResponse(pkgs...)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, pkg := range dr.Packages {
|
|
||||||
response.addPackage(pkg)
|
|
||||||
}
|
|
||||||
_, needPkgs, err := state.processGolistOverlay(response)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return state.addNeededOverlayPackages(response, needPkgs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (state *golistState) runContainsQueries(response *responseDeduper, queries []string) error {
|
func (state *golistState) runContainsQueries(response *responseDeduper, queries []string) error {
|
||||||
for _, query := range queries {
|
for _, query := range queries {
|
||||||
// TODO(matloob): Do only one query per directory.
|
// TODO(matloob): Do only one query per directory.
|
||||||
|
492
vendor/golang.org/x/tools/go/packages/golist_overlay.go
generated
vendored
492
vendor/golang.org/x/tools/go/packages/golist_overlay.go
generated
vendored
@@ -6,314 +6,11 @@ package packages
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"go/parser"
|
|
||||||
"go/token"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"golang.org/x/tools/internal/gocommand"
|
"golang.org/x/tools/internal/gocommand"
|
||||||
)
|
)
|
||||||
|
|
||||||
// processGolistOverlay provides rudimentary support for adding
|
|
||||||
// files that don't exist on disk to an overlay. The results can be
|
|
||||||
// sometimes incorrect.
|
|
||||||
// TODO(matloob): Handle unsupported cases, including the following:
|
|
||||||
// - determining the correct package to add given a new import path
|
|
||||||
func (state *golistState) processGolistOverlay(response *responseDeduper) (modifiedPkgs, needPkgs []string, err error) {
|
|
||||||
havePkgs := make(map[string]string) // importPath -> non-test package ID
|
|
||||||
needPkgsSet := make(map[string]bool)
|
|
||||||
modifiedPkgsSet := make(map[string]bool)
|
|
||||||
|
|
||||||
pkgOfDir := make(map[string][]*Package)
|
|
||||||
for _, pkg := range response.dr.Packages {
|
|
||||||
// This is an approximation of import path to id. This can be
|
|
||||||
// wrong for tests, vendored packages, and a number of other cases.
|
|
||||||
havePkgs[pkg.PkgPath] = pkg.ID
|
|
||||||
dir, err := commonDir(pkg.GoFiles)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
if dir != "" {
|
|
||||||
pkgOfDir[dir] = append(pkgOfDir[dir], pkg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no new imports are added, it is safe to avoid loading any needPkgs.
|
|
||||||
// Otherwise, it's hard to tell which package is actually being loaded
|
|
||||||
// (due to vendoring) and whether any modified package will show up
|
|
||||||
// in the transitive set of dependencies (because new imports are added,
|
|
||||||
// potentially modifying the transitive set of dependencies).
|
|
||||||
var overlayAddsImports bool
|
|
||||||
|
|
||||||
// If both a package and its test package are created by the overlay, we
|
|
||||||
// need the real package first. Process all non-test files before test
|
|
||||||
// files, and make the whole process deterministic while we're at it.
|
|
||||||
var overlayFiles []string
|
|
||||||
for opath := range state.cfg.Overlay {
|
|
||||||
overlayFiles = append(overlayFiles, opath)
|
|
||||||
}
|
|
||||||
sort.Slice(overlayFiles, func(i, j int) bool {
|
|
||||||
iTest := strings.HasSuffix(overlayFiles[i], "_test.go")
|
|
||||||
jTest := strings.HasSuffix(overlayFiles[j], "_test.go")
|
|
||||||
if iTest != jTest {
|
|
||||||
return !iTest // non-tests are before tests.
|
|
||||||
}
|
|
||||||
return overlayFiles[i] < overlayFiles[j]
|
|
||||||
})
|
|
||||||
for _, opath := range overlayFiles {
|
|
||||||
contents := state.cfg.Overlay[opath]
|
|
||||||
base := filepath.Base(opath)
|
|
||||||
dir := filepath.Dir(opath)
|
|
||||||
var pkg *Package // if opath belongs to both a package and its test variant, this will be the test variant
|
|
||||||
var testVariantOf *Package // if opath is a test file, this is the package it is testing
|
|
||||||
var fileExists bool
|
|
||||||
isTestFile := strings.HasSuffix(opath, "_test.go")
|
|
||||||
pkgName, ok := extractPackageName(opath, contents)
|
|
||||||
if !ok {
|
|
||||||
// Don't bother adding a file that doesn't even have a parsable package statement
|
|
||||||
// to the overlay.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// If all the overlay files belong to a different package, change the
|
|
||||||
// package name to that package.
|
|
||||||
maybeFixPackageName(pkgName, isTestFile, pkgOfDir[dir])
|
|
||||||
nextPackage:
|
|
||||||
for _, p := range response.dr.Packages {
|
|
||||||
if pkgName != p.Name && p.ID != "command-line-arguments" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, f := range p.GoFiles {
|
|
||||||
if !sameFile(filepath.Dir(f), dir) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Make sure to capture information on the package's test variant, if needed.
|
|
||||||
if isTestFile && !hasTestFiles(p) {
|
|
||||||
// TODO(matloob): Are there packages other than the 'production' variant
|
|
||||||
// of a package that this can match? This shouldn't match the test main package
|
|
||||||
// because the file is generated in another directory.
|
|
||||||
testVariantOf = p
|
|
||||||
continue nextPackage
|
|
||||||
} else if !isTestFile && hasTestFiles(p) {
|
|
||||||
// We're examining a test variant, but the overlaid file is
|
|
||||||
// a non-test file. Because the overlay implementation
|
|
||||||
// (currently) only adds a file to one package, skip this
|
|
||||||
// package, so that we can add the file to the production
|
|
||||||
// variant of the package. (https://golang.org/issue/36857
|
|
||||||
// tracks handling overlays on both the production and test
|
|
||||||
// variant of a package).
|
|
||||||
continue nextPackage
|
|
||||||
}
|
|
||||||
if pkg != nil && p != pkg && pkg.PkgPath == p.PkgPath {
|
|
||||||
// We have already seen the production version of the
|
|
||||||
// for which p is a test variant.
|
|
||||||
if hasTestFiles(p) {
|
|
||||||
testVariantOf = pkg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pkg = p
|
|
||||||
if filepath.Base(f) == base {
|
|
||||||
fileExists = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// The overlay could have included an entirely new package or an
|
|
||||||
// ad-hoc package. An ad-hoc package is one that we have manually
|
|
||||||
// constructed from inadequate `go list` results for a file= query.
|
|
||||||
// It will have the ID command-line-arguments.
|
|
||||||
if pkg == nil || pkg.ID == "command-line-arguments" {
|
|
||||||
// Try to find the module or gopath dir the file is contained in.
|
|
||||||
// Then for modules, add the module opath to the beginning.
|
|
||||||
pkgPath, ok, err := state.getPkgPath(dir)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
if !ok {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
var forTest string // only set for x tests
|
|
||||||
isXTest := strings.HasSuffix(pkgName, "_test")
|
|
||||||
if isXTest {
|
|
||||||
forTest = pkgPath
|
|
||||||
pkgPath += "_test"
|
|
||||||
}
|
|
||||||
id := pkgPath
|
|
||||||
if isTestFile {
|
|
||||||
if isXTest {
|
|
||||||
id = fmt.Sprintf("%s [%s.test]", pkgPath, forTest)
|
|
||||||
} else {
|
|
||||||
id = fmt.Sprintf("%s [%s.test]", pkgPath, pkgPath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if pkg != nil {
|
|
||||||
// TODO(rstambler): We should change the package's path and ID
|
|
||||||
// here. The only issue is that this messes with the roots.
|
|
||||||
} else {
|
|
||||||
// Try to reclaim a package with the same ID, if it exists in the response.
|
|
||||||
for _, p := range response.dr.Packages {
|
|
||||||
if reclaimPackage(p, id, opath, contents) {
|
|
||||||
pkg = p
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Otherwise, create a new package.
|
|
||||||
if pkg == nil {
|
|
||||||
pkg = &Package{
|
|
||||||
PkgPath: pkgPath,
|
|
||||||
ID: id,
|
|
||||||
Name: pkgName,
|
|
||||||
Imports: make(map[string]*Package),
|
|
||||||
}
|
|
||||||
response.addPackage(pkg)
|
|
||||||
havePkgs[pkg.PkgPath] = id
|
|
||||||
// Add the production package's sources for a test variant.
|
|
||||||
if isTestFile && !isXTest && testVariantOf != nil {
|
|
||||||
pkg.GoFiles = append(pkg.GoFiles, testVariantOf.GoFiles...)
|
|
||||||
pkg.CompiledGoFiles = append(pkg.CompiledGoFiles, testVariantOf.CompiledGoFiles...)
|
|
||||||
// Add the package under test and its imports to the test variant.
|
|
||||||
pkg.forTest = testVariantOf.PkgPath
|
|
||||||
for k, v := range testVariantOf.Imports {
|
|
||||||
pkg.Imports[k] = &Package{ID: v.ID}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if isXTest {
|
|
||||||
pkg.forTest = forTest
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !fileExists {
|
|
||||||
pkg.GoFiles = append(pkg.GoFiles, opath)
|
|
||||||
// TODO(matloob): Adding the file to CompiledGoFiles can exhibit the wrong behavior
|
|
||||||
// if the file will be ignored due to its build tags.
|
|
||||||
pkg.CompiledGoFiles = append(pkg.CompiledGoFiles, opath)
|
|
||||||
modifiedPkgsSet[pkg.ID] = true
|
|
||||||
}
|
|
||||||
imports, err := extractImports(opath, contents)
|
|
||||||
if err != nil {
|
|
||||||
// Let the parser or type checker report errors later.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, imp := range imports {
|
|
||||||
// TODO(rstambler): If the package is an x test and the import has
|
|
||||||
// a test variant, make sure to replace it.
|
|
||||||
if _, found := pkg.Imports[imp]; found {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
overlayAddsImports = true
|
|
||||||
id, ok := havePkgs[imp]
|
|
||||||
if !ok {
|
|
||||||
var err error
|
|
||||||
id, err = state.resolveImport(dir, imp)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pkg.Imports[imp] = &Package{ID: id}
|
|
||||||
// Add dependencies to the non-test variant version of this package as well.
|
|
||||||
if testVariantOf != nil {
|
|
||||||
testVariantOf.Imports[imp] = &Package{ID: id}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// toPkgPath guesses the package path given the id.
|
|
||||||
toPkgPath := func(sourceDir, id string) (string, error) {
|
|
||||||
if i := strings.IndexByte(id, ' '); i >= 0 {
|
|
||||||
return state.resolveImport(sourceDir, id[:i])
|
|
||||||
}
|
|
||||||
return state.resolveImport(sourceDir, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now that new packages have been created, do another pass to determine
|
|
||||||
// the new set of missing packages.
|
|
||||||
for _, pkg := range response.dr.Packages {
|
|
||||||
for _, imp := range pkg.Imports {
|
|
||||||
if len(pkg.GoFiles) == 0 {
|
|
||||||
return nil, nil, fmt.Errorf("cannot resolve imports for package %q with no Go files", pkg.PkgPath)
|
|
||||||
}
|
|
||||||
pkgPath, err := toPkgPath(filepath.Dir(pkg.GoFiles[0]), imp.ID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
if _, ok := havePkgs[pkgPath]; !ok {
|
|
||||||
needPkgsSet[pkgPath] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if overlayAddsImports {
|
|
||||||
needPkgs = make([]string, 0, len(needPkgsSet))
|
|
||||||
for pkg := range needPkgsSet {
|
|
||||||
needPkgs = append(needPkgs, pkg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
modifiedPkgs = make([]string, 0, len(modifiedPkgsSet))
|
|
||||||
for pkg := range modifiedPkgsSet {
|
|
||||||
modifiedPkgs = append(modifiedPkgs, pkg)
|
|
||||||
}
|
|
||||||
return modifiedPkgs, needPkgs, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// resolveImport finds the ID of a package given its import path.
|
|
||||||
// In particular, it will find the right vendored copy when in GOPATH mode.
|
|
||||||
func (state *golistState) resolveImport(sourceDir, importPath string) (string, error) {
|
|
||||||
env, err := state.getEnv()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if env["GOMOD"] != "" {
|
|
||||||
return importPath, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
searchDir := sourceDir
|
|
||||||
for {
|
|
||||||
vendorDir := filepath.Join(searchDir, "vendor")
|
|
||||||
exists, ok := state.vendorDirs[vendorDir]
|
|
||||||
if !ok {
|
|
||||||
info, err := os.Stat(vendorDir)
|
|
||||||
exists = err == nil && info.IsDir()
|
|
||||||
state.vendorDirs[vendorDir] = exists
|
|
||||||
}
|
|
||||||
|
|
||||||
if exists {
|
|
||||||
vendoredPath := filepath.Join(vendorDir, importPath)
|
|
||||||
if info, err := os.Stat(vendoredPath); err == nil && info.IsDir() {
|
|
||||||
// We should probably check for .go files here, but shame on anyone who fools us.
|
|
||||||
path, ok, err := state.getPkgPath(vendoredPath)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if ok {
|
|
||||||
return path, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We know we've hit the top of the filesystem when we Dir / and get /,
|
|
||||||
// or C:\ and get C:\, etc.
|
|
||||||
next := filepath.Dir(searchDir)
|
|
||||||
if next == searchDir {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
searchDir = next
|
|
||||||
}
|
|
||||||
return importPath, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func hasTestFiles(p *Package) bool {
|
|
||||||
for _, f := range p.GoFiles {
|
|
||||||
if strings.HasSuffix(f, "_test.go") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// determineRootDirs returns a mapping from absolute directories that could
|
// determineRootDirs returns a mapping from absolute directories that could
|
||||||
// contain code to their corresponding import path prefixes.
|
// contain code to their corresponding import path prefixes.
|
||||||
func (state *golistState) determineRootDirs() (map[string]string, error) {
|
func (state *golistState) determineRootDirs() (map[string]string, error) {
|
||||||
@@ -384,192 +81,3 @@ func (state *golistState) determineRootDirsGOPATH() (map[string]string, error) {
|
|||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractImports(filename string, contents []byte) ([]string, error) {
|
|
||||||
f, err := parser.ParseFile(token.NewFileSet(), filename, contents, parser.ImportsOnly) // TODO(matloob): reuse fileset?
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var res []string
|
|
||||||
for _, imp := range f.Imports {
|
|
||||||
quotedPath := imp.Path.Value
|
|
||||||
path, err := strconv.Unquote(quotedPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
res = append(res, path)
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// reclaimPackage attempts to reuse a package that failed to load in an overlay.
|
|
||||||
//
|
|
||||||
// If the package has errors and has no Name, GoFiles, or Imports,
|
|
||||||
// then it's possible that it doesn't yet exist on disk.
|
|
||||||
func reclaimPackage(pkg *Package, id string, filename string, contents []byte) bool {
|
|
||||||
// TODO(rstambler): Check the message of the actual error?
|
|
||||||
// It differs between $GOPATH and module mode.
|
|
||||||
if pkg.ID != id {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if len(pkg.Errors) != 1 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if pkg.Name != "" || pkg.ExportFile != "" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if len(pkg.GoFiles) > 0 || len(pkg.CompiledGoFiles) > 0 || len(pkg.OtherFiles) > 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if len(pkg.Imports) > 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
pkgName, ok := extractPackageName(filename, contents)
|
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
pkg.Name = pkgName
|
|
||||||
pkg.Errors = nil
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func extractPackageName(filename string, contents []byte) (string, bool) {
|
|
||||||
// TODO(rstambler): Check the message of the actual error?
|
|
||||||
// It differs between $GOPATH and module mode.
|
|
||||||
f, err := parser.ParseFile(token.NewFileSet(), filename, contents, parser.PackageClauseOnly) // TODO(matloob): reuse fileset?
|
|
||||||
if err != nil {
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
return f.Name.Name, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// commonDir returns the directory that all files are in, "" if files is empty,
|
|
||||||
// or an error if they aren't in the same directory.
|
|
||||||
func commonDir(files []string) (string, error) {
|
|
||||||
seen := make(map[string]bool)
|
|
||||||
for _, f := range files {
|
|
||||||
seen[filepath.Dir(f)] = true
|
|
||||||
}
|
|
||||||
if len(seen) > 1 {
|
|
||||||
return "", fmt.Errorf("files (%v) are in more than one directory: %v", files, seen)
|
|
||||||
}
|
|
||||||
for k := range seen {
|
|
||||||
// seen has only one element; return it.
|
|
||||||
return k, nil
|
|
||||||
}
|
|
||||||
return "", nil // no files
|
|
||||||
}
|
|
||||||
|
|
||||||
// It is possible that the files in the disk directory dir have a different package
|
|
||||||
// name from newName, which is deduced from the overlays. If they all have a different
|
|
||||||
// package name, and they all have the same package name, then that name becomes
|
|
||||||
// the package name.
|
|
||||||
// It returns true if it changes the package name, false otherwise.
|
|
||||||
func maybeFixPackageName(newName string, isTestFile bool, pkgsOfDir []*Package) {
|
|
||||||
names := make(map[string]int)
|
|
||||||
for _, p := range pkgsOfDir {
|
|
||||||
names[p.Name]++
|
|
||||||
}
|
|
||||||
if len(names) != 1 {
|
|
||||||
// some files are in different packages
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var oldName string
|
|
||||||
for k := range names {
|
|
||||||
oldName = k
|
|
||||||
}
|
|
||||||
if newName == oldName {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// We might have a case where all of the package names in the directory are
|
|
||||||
// the same, but the overlay file is for an x test, which belongs to its
|
|
||||||
// own package. If the x test does not yet exist on disk, we may not yet
|
|
||||||
// have its package name on disk, but we should not rename the packages.
|
|
||||||
//
|
|
||||||
// We use a heuristic to determine if this file belongs to an x test:
|
|
||||||
// The test file should have a package name whose package name has a _test
|
|
||||||
// suffix or looks like "newName_test".
|
|
||||||
maybeXTest := strings.HasPrefix(oldName+"_test", newName) || strings.HasSuffix(newName, "_test")
|
|
||||||
if isTestFile && maybeXTest {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, p := range pkgsOfDir {
|
|
||||||
p.Name = newName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function is copy-pasted from
|
|
||||||
// https://github.com/golang/go/blob/9706f510a5e2754595d716bd64be8375997311fb/src/cmd/go/internal/search/search.go#L360.
|
|
||||||
// It should be deleted when we remove support for overlays from go/packages.
|
|
||||||
//
|
|
||||||
// NOTE: This does not handle any ./... or ./ style queries, as this function
|
|
||||||
// doesn't know the working directory.
|
|
||||||
//
|
|
||||||
// matchPattern(pattern)(name) reports whether
|
|
||||||
// name matches pattern. Pattern is a limited glob
|
|
||||||
// pattern in which '...' means 'any string' and there
|
|
||||||
// is no other special syntax.
|
|
||||||
// Unfortunately, there are two special cases. Quoting "go help packages":
|
|
||||||
//
|
|
||||||
// First, /... at the end of the pattern can match an empty string,
|
|
||||||
// so that net/... matches both net and packages in its subdirectories, like net/http.
|
|
||||||
// Second, any slash-separated pattern element containing a wildcard never
|
|
||||||
// participates in a match of the "vendor" element in the path of a vendored
|
|
||||||
// package, so that ./... does not match packages in subdirectories of
|
|
||||||
// ./vendor or ./mycode/vendor, but ./vendor/... and ./mycode/vendor/... do.
|
|
||||||
// Note, however, that a directory named vendor that itself contains code
|
|
||||||
// is not a vendored package: cmd/vendor would be a command named vendor,
|
|
||||||
// and the pattern cmd/... matches it.
|
|
||||||
func matchPattern(pattern string) func(name string) bool {
|
|
||||||
// Convert pattern to regular expression.
|
|
||||||
// The strategy for the trailing /... is to nest it in an explicit ? expression.
|
|
||||||
// The strategy for the vendor exclusion is to change the unmatchable
|
|
||||||
// vendor strings to a disallowed code point (vendorChar) and to use
|
|
||||||
// "(anything but that codepoint)*" as the implementation of the ... wildcard.
|
|
||||||
// This is a bit complicated but the obvious alternative,
|
|
||||||
// namely a hand-written search like in most shell glob matchers,
|
|
||||||
// is too easy to make accidentally exponential.
|
|
||||||
// Using package regexp guarantees linear-time matching.
|
|
||||||
|
|
||||||
const vendorChar = "\x00"
|
|
||||||
|
|
||||||
if strings.Contains(pattern, vendorChar) {
|
|
||||||
return func(name string) bool { return false }
|
|
||||||
}
|
|
||||||
|
|
||||||
re := regexp.QuoteMeta(pattern)
|
|
||||||
re = replaceVendor(re, vendorChar)
|
|
||||||
switch {
|
|
||||||
case strings.HasSuffix(re, `/`+vendorChar+`/\.\.\.`):
|
|
||||||
re = strings.TrimSuffix(re, `/`+vendorChar+`/\.\.\.`) + `(/vendor|/` + vendorChar + `/\.\.\.)`
|
|
||||||
case re == vendorChar+`/\.\.\.`:
|
|
||||||
re = `(/vendor|/` + vendorChar + `/\.\.\.)`
|
|
||||||
case strings.HasSuffix(re, `/\.\.\.`):
|
|
||||||
re = strings.TrimSuffix(re, `/\.\.\.`) + `(/\.\.\.)?`
|
|
||||||
}
|
|
||||||
re = strings.ReplaceAll(re, `\.\.\.`, `[^`+vendorChar+`]*`)
|
|
||||||
|
|
||||||
reg := regexp.MustCompile(`^` + re + `$`)
|
|
||||||
|
|
||||||
return func(name string) bool {
|
|
||||||
if strings.Contains(name, vendorChar) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return reg.MatchString(replaceVendor(name, vendorChar))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// replaceVendor returns the result of replacing
|
|
||||||
// non-trailing vendor path elements in x with repl.
|
|
||||||
func replaceVendor(x, repl string) string {
|
|
||||||
if !strings.Contains(x, "vendor") {
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
elem := strings.Split(x, "/")
|
|
||||||
for i := 0; i < len(elem)-1; i++ {
|
|
||||||
if elem[i] == "vendor" {
|
|
||||||
elem[i] = repl
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return strings.Join(elem, "/")
|
|
||||||
}
|
|
||||||
|
173
vendor/golang.org/x/tools/go/packages/packages.go
generated
vendored
173
vendor/golang.org/x/tools/go/packages/packages.go
generated
vendored
@@ -29,6 +29,7 @@ import (
|
|||||||
"golang.org/x/tools/internal/packagesinternal"
|
"golang.org/x/tools/internal/packagesinternal"
|
||||||
"golang.org/x/tools/internal/typeparams"
|
"golang.org/x/tools/internal/typeparams"
|
||||||
"golang.org/x/tools/internal/typesinternal"
|
"golang.org/x/tools/internal/typesinternal"
|
||||||
|
"golang.org/x/tools/internal/versions"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A LoadMode controls the amount of detail to return when loading.
|
// A LoadMode controls the amount of detail to return when loading.
|
||||||
@@ -258,31 +259,52 @@ type driverResponse struct {
|
|||||||
// proceeding with further analysis. The PrintErrors function is
|
// proceeding with further analysis. The PrintErrors function is
|
||||||
// provided for convenient display of all errors.
|
// provided for convenient display of all errors.
|
||||||
func Load(cfg *Config, patterns ...string) ([]*Package, error) {
|
func Load(cfg *Config, patterns ...string) ([]*Package, error) {
|
||||||
l := newLoader(cfg)
|
ld := newLoader(cfg)
|
||||||
response, err := defaultDriver(&l.Config, patterns...)
|
response, external, err := defaultDriver(&ld.Config, patterns...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
l.sizes = types.SizesFor(response.Compiler, response.Arch)
|
|
||||||
return l.refine(response)
|
ld.sizes = types.SizesFor(response.Compiler, response.Arch)
|
||||||
|
if ld.sizes == nil && ld.Config.Mode&(NeedTypes|NeedTypesSizes|NeedTypesInfo) != 0 {
|
||||||
|
// Type size information is needed but unavailable.
|
||||||
|
if external {
|
||||||
|
// An external driver may fail to populate the Compiler/GOARCH fields,
|
||||||
|
// especially since they are relatively new (see #63700).
|
||||||
|
// Provide a sensible fallback in this case.
|
||||||
|
ld.sizes = types.SizesFor("gc", runtime.GOARCH)
|
||||||
|
if ld.sizes == nil { // gccgo-only arch
|
||||||
|
ld.sizes = types.SizesFor("gc", "amd64")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Go list should never fail to deliver accurate size information.
|
||||||
|
// Reject the whole Load since the error is the same for every package.
|
||||||
|
return nil, fmt.Errorf("can't determine type sizes for compiler %q on GOARCH %q",
|
||||||
|
response.Compiler, response.Arch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ld.refine(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
// defaultDriver is a driver that implements go/packages' fallback behavior.
|
// defaultDriver is a driver that implements go/packages' fallback behavior.
|
||||||
// It will try to request to an external driver, if one exists. If there's
|
// It will try to request to an external driver, if one exists. If there's
|
||||||
// no external driver, or the driver returns a response with NotHandled set,
|
// no external driver, or the driver returns a response with NotHandled set,
|
||||||
// defaultDriver will fall back to the go list driver.
|
// defaultDriver will fall back to the go list driver.
|
||||||
func defaultDriver(cfg *Config, patterns ...string) (*driverResponse, error) {
|
// The boolean result indicates that an external driver handled the request.
|
||||||
driver := findExternalDriver(cfg)
|
func defaultDriver(cfg *Config, patterns ...string) (*driverResponse, bool, error) {
|
||||||
if driver == nil {
|
if driver := findExternalDriver(cfg); driver != nil {
|
||||||
driver = goListDriver
|
response, err := driver(cfg, patterns...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
} else if !response.NotHandled {
|
||||||
|
return response, true, nil
|
||||||
|
}
|
||||||
|
// (fall through)
|
||||||
}
|
}
|
||||||
response, err := driver(cfg, patterns...)
|
|
||||||
if err != nil {
|
response, err := goListDriver(cfg, patterns...)
|
||||||
return response, err
|
return response, false, err
|
||||||
} else if response.NotHandled {
|
|
||||||
return goListDriver(cfg, patterns...)
|
|
||||||
}
|
|
||||||
return response, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Package describes a loaded Go package.
|
// A Package describes a loaded Go package.
|
||||||
@@ -411,12 +433,6 @@ func init() {
|
|||||||
packagesinternal.GetDepsErrors = func(p interface{}) []*packagesinternal.PackageError {
|
packagesinternal.GetDepsErrors = func(p interface{}) []*packagesinternal.PackageError {
|
||||||
return p.(*Package).depsErrors
|
return p.(*Package).depsErrors
|
||||||
}
|
}
|
||||||
packagesinternal.GetGoCmdRunner = func(config interface{}) *gocommand.Runner {
|
|
||||||
return config.(*Config).gocmdRunner
|
|
||||||
}
|
|
||||||
packagesinternal.SetGoCmdRunner = func(config interface{}, runner *gocommand.Runner) {
|
|
||||||
config.(*Config).gocmdRunner = runner
|
|
||||||
}
|
|
||||||
packagesinternal.SetModFile = func(config interface{}, value string) {
|
packagesinternal.SetModFile = func(config interface{}, value string) {
|
||||||
config.(*Config).modFile = value
|
config.(*Config).modFile = value
|
||||||
}
|
}
|
||||||
@@ -553,7 +569,7 @@ type loaderPackage struct {
|
|||||||
type loader struct {
|
type loader struct {
|
||||||
pkgs map[string]*loaderPackage
|
pkgs map[string]*loaderPackage
|
||||||
Config
|
Config
|
||||||
sizes types.Sizes
|
sizes types.Sizes // non-nil if needed by mode
|
||||||
parseCache map[string]*parseValue
|
parseCache map[string]*parseValue
|
||||||
parseCacheMu sync.Mutex
|
parseCacheMu sync.Mutex
|
||||||
exportMu sync.Mutex // enforces mutual exclusion of exportdata operations
|
exportMu sync.Mutex // enforces mutual exclusion of exportdata operations
|
||||||
@@ -678,39 +694,38 @@ func (ld *loader) refine(response *driverResponse) ([]*Package, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Materialize the import graph.
|
if ld.Mode&NeedImports != 0 {
|
||||||
|
// Materialize the import graph.
|
||||||
|
|
||||||
const (
|
const (
|
||||||
white = 0 // new
|
white = 0 // new
|
||||||
grey = 1 // in progress
|
grey = 1 // in progress
|
||||||
black = 2 // complete
|
black = 2 // complete
|
||||||
)
|
)
|
||||||
|
|
||||||
// visit traverses the import graph, depth-first,
|
// visit traverses the import graph, depth-first,
|
||||||
// and materializes the graph as Packages.Imports.
|
// and materializes the graph as Packages.Imports.
|
||||||
//
|
//
|
||||||
// Valid imports are saved in the Packages.Import map.
|
// Valid imports are saved in the Packages.Import map.
|
||||||
// Invalid imports (cycles and missing nodes) are saved in the importErrors map.
|
// Invalid imports (cycles and missing nodes) are saved in the importErrors map.
|
||||||
// Thus, even in the presence of both kinds of errors, the Import graph remains a DAG.
|
// Thus, even in the presence of both kinds of errors,
|
||||||
//
|
// the Import graph remains a DAG.
|
||||||
// visit returns whether the package needs src or has a transitive
|
//
|
||||||
// dependency on a package that does. These are the only packages
|
// visit returns whether the package needs src or has a transitive
|
||||||
// for which we load source code.
|
// dependency on a package that does. These are the only packages
|
||||||
var stack []*loaderPackage
|
// for which we load source code.
|
||||||
var visit func(lpkg *loaderPackage) bool
|
var stack []*loaderPackage
|
||||||
var srcPkgs []*loaderPackage
|
var visit func(lpkg *loaderPackage) bool
|
||||||
visit = func(lpkg *loaderPackage) bool {
|
visit = func(lpkg *loaderPackage) bool {
|
||||||
switch lpkg.color {
|
switch lpkg.color {
|
||||||
case black:
|
case black:
|
||||||
return lpkg.needsrc
|
return lpkg.needsrc
|
||||||
case grey:
|
case grey:
|
||||||
panic("internal error: grey node")
|
panic("internal error: grey node")
|
||||||
}
|
}
|
||||||
lpkg.color = grey
|
lpkg.color = grey
|
||||||
stack = append(stack, lpkg) // push
|
stack = append(stack, lpkg) // push
|
||||||
stubs := lpkg.Imports // the structure form has only stubs with the ID in the Imports
|
stubs := lpkg.Imports // the structure form has only stubs with the ID in the Imports
|
||||||
// If NeedImports isn't set, the imports fields will all be zeroed out.
|
|
||||||
if ld.Mode&NeedImports != 0 {
|
|
||||||
lpkg.Imports = make(map[string]*Package, len(stubs))
|
lpkg.Imports = make(map[string]*Package, len(stubs))
|
||||||
for importPath, ipkg := range stubs {
|
for importPath, ipkg := range stubs {
|
||||||
var importErr error
|
var importErr error
|
||||||
@@ -734,40 +749,39 @@ func (ld *loader) refine(response *driverResponse) ([]*Package, error) {
|
|||||||
}
|
}
|
||||||
lpkg.Imports[importPath] = imp.Package
|
lpkg.Imports[importPath] = imp.Package
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if lpkg.needsrc {
|
|
||||||
srcPkgs = append(srcPkgs, lpkg)
|
|
||||||
}
|
|
||||||
if ld.Mode&NeedTypesSizes != 0 {
|
|
||||||
lpkg.TypesSizes = ld.sizes
|
|
||||||
}
|
|
||||||
stack = stack[:len(stack)-1] // pop
|
|
||||||
lpkg.color = black
|
|
||||||
|
|
||||||
return lpkg.needsrc
|
// Complete type information is required for the
|
||||||
}
|
// immediate dependencies of each source package.
|
||||||
|
if lpkg.needsrc && ld.Mode&NeedTypes != 0 {
|
||||||
|
for _, ipkg := range lpkg.Imports {
|
||||||
|
ld.pkgs[ipkg.ID].needtypes = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ld.Mode&NeedImports == 0 {
|
// NeedTypeSizes causes TypeSizes to be set even
|
||||||
// We do this to drop the stub import packages that we are not even going to try to resolve.
|
// on packages for which types aren't needed.
|
||||||
for _, lpkg := range initial {
|
if ld.Mode&NeedTypesSizes != 0 {
|
||||||
lpkg.Imports = nil
|
lpkg.TypesSizes = ld.sizes
|
||||||
|
}
|
||||||
|
stack = stack[:len(stack)-1] // pop
|
||||||
|
lpkg.color = black
|
||||||
|
|
||||||
|
return lpkg.needsrc
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// For each initial package, create its import DAG.
|
// For each initial package, create its import DAG.
|
||||||
for _, lpkg := range initial {
|
for _, lpkg := range initial {
|
||||||
visit(lpkg)
|
visit(lpkg)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if ld.Mode&NeedImports != 0 && ld.Mode&NeedTypes != 0 {
|
} else {
|
||||||
for _, lpkg := range srcPkgs {
|
// !NeedImports: drop the stub (ID-only) import packages
|
||||||
// Complete type information is required for the
|
// that we are not even going to try to resolve.
|
||||||
// immediate dependencies of each source package.
|
for _, lpkg := range initial {
|
||||||
for _, ipkg := range lpkg.Imports {
|
lpkg.Imports = nil
|
||||||
imp := ld.pkgs[ipkg.ID]
|
|
||||||
imp.needtypes = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load type data and syntax if needed, starting at
|
// Load type data and syntax if needed, starting at
|
||||||
// the initial packages (roots of the import DAG).
|
// the initial packages (roots of the import DAG).
|
||||||
if ld.Mode&NeedTypes != 0 || ld.Mode&NeedSyntax != 0 {
|
if ld.Mode&NeedTypes != 0 || ld.Mode&NeedSyntax != 0 {
|
||||||
@@ -1005,6 +1019,7 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
|
|||||||
Selections: make(map[*ast.SelectorExpr]*types.Selection),
|
Selections: make(map[*ast.SelectorExpr]*types.Selection),
|
||||||
}
|
}
|
||||||
typeparams.InitInstanceInfo(lpkg.TypesInfo)
|
typeparams.InitInstanceInfo(lpkg.TypesInfo)
|
||||||
|
versions.InitFileVersions(lpkg.TypesInfo)
|
||||||
lpkg.TypesSizes = ld.sizes
|
lpkg.TypesSizes = ld.sizes
|
||||||
|
|
||||||
importer := importerFunc(func(path string) (*types.Package, error) {
|
importer := importerFunc(func(path string) (*types.Package, error) {
|
||||||
@@ -1042,7 +1057,7 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
|
|||||||
IgnoreFuncBodies: ld.Mode&NeedDeps == 0 && !lpkg.initial,
|
IgnoreFuncBodies: ld.Mode&NeedDeps == 0 && !lpkg.initial,
|
||||||
|
|
||||||
Error: appendError,
|
Error: appendError,
|
||||||
Sizes: ld.sizes,
|
Sizes: ld.sizes, // may be nil
|
||||||
}
|
}
|
||||||
if lpkg.Module != nil && lpkg.Module.GoVersion != "" {
|
if lpkg.Module != nil && lpkg.Module.GoVersion != "" {
|
||||||
typesinternal.SetGoVersion(tc, "go"+lpkg.Module.GoVersion)
|
typesinternal.SetGoVersion(tc, "go"+lpkg.Module.GoVersion)
|
||||||
|
117
vendor/golang.org/x/tools/go/types/objectpath/objectpath.go
generated
vendored
117
vendor/golang.org/x/tools/go/types/objectpath/objectpath.go
generated
vendored
@@ -26,13 +26,10 @@ package objectpath
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/types"
|
"go/types"
|
||||||
"sort"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
_ "unsafe"
|
|
||||||
|
|
||||||
"golang.org/x/tools/internal/typeparams"
|
"golang.org/x/tools/internal/typeparams"
|
||||||
"golang.org/x/tools/internal/typesinternal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Path is an opaque name that identifies a types.Object
|
// A Path is an opaque name that identifies a types.Object
|
||||||
@@ -123,20 +120,7 @@ func For(obj types.Object) (Path, error) {
|
|||||||
// An Encoder amortizes the cost of encoding the paths of multiple objects.
|
// An Encoder amortizes the cost of encoding the paths of multiple objects.
|
||||||
// The zero value of an Encoder is ready to use.
|
// The zero value of an Encoder is ready to use.
|
||||||
type Encoder struct {
|
type Encoder struct {
|
||||||
scopeMemo map[*types.Scope][]types.Object // memoization of scopeObjects
|
scopeMemo map[*types.Scope][]types.Object // memoization of scopeObjects
|
||||||
namedMethodsMemo map[*types.Named][]*types.Func // memoization of namedMethods()
|
|
||||||
skipMethodSorting bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expose back doors so that gopls can avoid method sorting, which can dominate
|
|
||||||
// analysis on certain repositories.
|
|
||||||
//
|
|
||||||
// TODO(golang/go#61443): remove this.
|
|
||||||
func init() {
|
|
||||||
typesinternal.SkipEncoderMethodSorting = func(enc interface{}) {
|
|
||||||
enc.(*Encoder).skipMethodSorting = true
|
|
||||||
}
|
|
||||||
typesinternal.ObjectpathObject = object
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For returns the path to an object relative to its package,
|
// For returns the path to an object relative to its package,
|
||||||
@@ -328,31 +312,18 @@ func (enc *Encoder) For(obj types.Object) (Path, error) {
|
|||||||
// Inspect declared methods of defined types.
|
// Inspect declared methods of defined types.
|
||||||
if T, ok := o.Type().(*types.Named); ok {
|
if T, ok := o.Type().(*types.Named); ok {
|
||||||
path = append(path, opType)
|
path = append(path, opType)
|
||||||
if !enc.skipMethodSorting {
|
// The method index here is always with respect
|
||||||
// Note that method index here is always with respect
|
// to the underlying go/types data structures,
|
||||||
// to canonical ordering of methods, regardless of how
|
// which ultimately derives from source order
|
||||||
// they appear in the underlying type.
|
// and must be preserved by export data.
|
||||||
for i, m := range enc.namedMethods(T) {
|
for i := 0; i < T.NumMethods(); i++ {
|
||||||
path2 := appendOpArg(path, opMethod, i)
|
m := T.Method(i)
|
||||||
if m == obj {
|
path2 := appendOpArg(path, opMethod, i)
|
||||||
return Path(path2), nil // found declared method
|
if m == obj {
|
||||||
}
|
return Path(path2), nil // found declared method
|
||||||
if r := find(obj, m.Type(), append(path2, opType), nil); r != nil {
|
|
||||||
return Path(r), nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
if r := find(obj, m.Type(), append(path2, opType), nil); r != nil {
|
||||||
// This branch must match the logic in the branch above, using go/types
|
return Path(r), nil
|
||||||
// APIs without sorting.
|
|
||||||
for i := 0; i < T.NumMethods(); i++ {
|
|
||||||
m := T.Method(i)
|
|
||||||
path2 := appendOpArg(path, opMethod, i)
|
|
||||||
if m == obj {
|
|
||||||
return Path(path2), nil // found declared method
|
|
||||||
}
|
|
||||||
if r := find(obj, m.Type(), append(path2, opType), nil); r != nil {
|
|
||||||
return Path(r), nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -448,22 +419,13 @@ func (enc *Encoder) concreteMethod(meth *types.Func) (Path, bool) {
|
|||||||
path = append(path, name...)
|
path = append(path, name...)
|
||||||
path = append(path, opType)
|
path = append(path, opType)
|
||||||
|
|
||||||
if !enc.skipMethodSorting {
|
// Method indices are w.r.t. the go/types data structures,
|
||||||
for i, m := range enc.namedMethods(named) {
|
// ultimately deriving from source order,
|
||||||
if m == meth {
|
// which is preserved by export data.
|
||||||
path = appendOpArg(path, opMethod, i)
|
for i := 0; i < named.NumMethods(); i++ {
|
||||||
return Path(path), true
|
if named.Method(i) == meth {
|
||||||
}
|
path = appendOpArg(path, opMethod, i)
|
||||||
}
|
return Path(path), true
|
||||||
} else {
|
|
||||||
// This branch must match the logic of the branch above, using go/types
|
|
||||||
// APIs without sorting.
|
|
||||||
for i := 0; i < named.NumMethods(); i++ {
|
|
||||||
m := named.Method(i)
|
|
||||||
if m == meth {
|
|
||||||
path = appendOpArg(path, opMethod, i)
|
|
||||||
return Path(path), true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -576,12 +538,7 @@ func findTypeParam(obj types.Object, list *typeparams.TypeParamList, path []byte
|
|||||||
|
|
||||||
// Object returns the object denoted by path p within the package pkg.
|
// Object returns the object denoted by path p within the package pkg.
|
||||||
func Object(pkg *types.Package, p Path) (types.Object, error) {
|
func Object(pkg *types.Package, p Path) (types.Object, error) {
|
||||||
return object(pkg, string(p), false)
|
pathstr := string(p)
|
||||||
}
|
|
||||||
|
|
||||||
// Note: the skipMethodSorting parameter must match the value of
|
|
||||||
// Encoder.skipMethodSorting used during encoding.
|
|
||||||
func object(pkg *types.Package, pathstr string, skipMethodSorting bool) (types.Object, error) {
|
|
||||||
if pathstr == "" {
|
if pathstr == "" {
|
||||||
return nil, fmt.Errorf("empty path")
|
return nil, fmt.Errorf("empty path")
|
||||||
}
|
}
|
||||||
@@ -747,12 +704,7 @@ func object(pkg *types.Package, pathstr string, skipMethodSorting bool) (types.O
|
|||||||
if index >= t.NumMethods() {
|
if index >= t.NumMethods() {
|
||||||
return nil, fmt.Errorf("method index %d out of range [0-%d)", index, t.NumMethods())
|
return nil, fmt.Errorf("method index %d out of range [0-%d)", index, t.NumMethods())
|
||||||
}
|
}
|
||||||
if skipMethodSorting {
|
obj = t.Method(index)
|
||||||
obj = t.Method(index)
|
|
||||||
} else {
|
|
||||||
methods := namedMethods(t) // (unmemoized)
|
|
||||||
obj = methods[index] // Id-ordered
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("cannot apply %q to %s (got %T, want interface or named)", code, t, t)
|
return nil, fmt.Errorf("cannot apply %q to %s (got %T, want interface or named)", code, t, t)
|
||||||
@@ -779,33 +731,6 @@ func object(pkg *types.Package, pathstr string, skipMethodSorting bool) (types.O
|
|||||||
return obj, nil // success
|
return obj, nil // success
|
||||||
}
|
}
|
||||||
|
|
||||||
// namedMethods returns the methods of a Named type in ascending Id order.
|
|
||||||
func namedMethods(named *types.Named) []*types.Func {
|
|
||||||
methods := make([]*types.Func, named.NumMethods())
|
|
||||||
for i := range methods {
|
|
||||||
methods[i] = named.Method(i)
|
|
||||||
}
|
|
||||||
sort.Slice(methods, func(i, j int) bool {
|
|
||||||
return methods[i].Id() < methods[j].Id()
|
|
||||||
})
|
|
||||||
return methods
|
|
||||||
}
|
|
||||||
|
|
||||||
// namedMethods is a memoization of the namedMethods function. Callers must not modify the result.
|
|
||||||
func (enc *Encoder) namedMethods(named *types.Named) []*types.Func {
|
|
||||||
m := enc.namedMethodsMemo
|
|
||||||
if m == nil {
|
|
||||||
m = make(map[*types.Named][]*types.Func)
|
|
||||||
enc.namedMethodsMemo = m
|
|
||||||
}
|
|
||||||
methods, ok := m[named]
|
|
||||||
if !ok {
|
|
||||||
methods = namedMethods(named) // allocates and sorts
|
|
||||||
m[named] = methods
|
|
||||||
}
|
|
||||||
return methods
|
|
||||||
}
|
|
||||||
|
|
||||||
// scopeObjects is a memoization of scope objects.
|
// scopeObjects is a memoization of scope objects.
|
||||||
// Callers must not modify the result.
|
// Callers must not modify the result.
|
||||||
func (enc *Encoder) scopeObjects(scope *types.Scope) []types.Object {
|
func (enc *Encoder) scopeObjects(scope *types.Scope) []types.Object {
|
||||||
|
29
vendor/golang.org/x/tools/internal/gocommand/invoke.go
generated
vendored
29
vendor/golang.org/x/tools/internal/gocommand/invoke.go
generated
vendored
@@ -13,6 +13,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -21,8 +22,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
exec "golang.org/x/sys/execabs"
|
|
||||||
|
|
||||||
"golang.org/x/tools/internal/event"
|
"golang.org/x/tools/internal/event"
|
||||||
"golang.org/x/tools/internal/event/keys"
|
"golang.org/x/tools/internal/event/keys"
|
||||||
"golang.org/x/tools/internal/event/label"
|
"golang.org/x/tools/internal/event/label"
|
||||||
@@ -85,6 +84,7 @@ func (runner *Runner) RunPiped(ctx context.Context, inv Invocation, stdout, stde
|
|||||||
|
|
||||||
// RunRaw runs the invocation, serializing requests only if they fight over
|
// RunRaw runs the invocation, serializing requests only if they fight over
|
||||||
// go.mod changes.
|
// go.mod changes.
|
||||||
|
// Postcondition: both error results have same nilness.
|
||||||
func (runner *Runner) RunRaw(ctx context.Context, inv Invocation) (*bytes.Buffer, *bytes.Buffer, error, error) {
|
func (runner *Runner) RunRaw(ctx context.Context, inv Invocation) (*bytes.Buffer, *bytes.Buffer, error, error) {
|
||||||
ctx, done := event.Start(ctx, "gocommand.Runner.RunRaw", invLabels(inv)...)
|
ctx, done := event.Start(ctx, "gocommand.Runner.RunRaw", invLabels(inv)...)
|
||||||
defer done()
|
defer done()
|
||||||
@@ -95,23 +95,24 @@ func (runner *Runner) RunRaw(ctx context.Context, inv Invocation) (*bytes.Buffer
|
|||||||
stdout, stderr, friendlyErr, err := runner.runConcurrent(ctx, inv)
|
stdout, stderr, friendlyErr, err := runner.runConcurrent(ctx, inv)
|
||||||
|
|
||||||
// If we encounter a load concurrency error, we need to retry serially.
|
// If we encounter a load concurrency error, we need to retry serially.
|
||||||
if friendlyErr == nil || !modConcurrencyError.MatchString(friendlyErr.Error()) {
|
if friendlyErr != nil && modConcurrencyError.MatchString(friendlyErr.Error()) {
|
||||||
return stdout, stderr, friendlyErr, err
|
event.Error(ctx, "Load concurrency error, will retry serially", err)
|
||||||
}
|
|
||||||
event.Error(ctx, "Load concurrency error, will retry serially", err)
|
// Run serially by calling runPiped.
|
||||||
|
stdout.Reset()
|
||||||
|
stderr.Reset()
|
||||||
|
friendlyErr, err = runner.runPiped(ctx, inv, stdout, stderr)
|
||||||
|
}
|
||||||
|
|
||||||
// Run serially by calling runPiped.
|
|
||||||
stdout.Reset()
|
|
||||||
stderr.Reset()
|
|
||||||
friendlyErr, err = runner.runPiped(ctx, inv, stdout, stderr)
|
|
||||||
return stdout, stderr, friendlyErr, err
|
return stdout, stderr, friendlyErr, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Postcondition: both error results have same nilness.
|
||||||
func (runner *Runner) runConcurrent(ctx context.Context, inv Invocation) (*bytes.Buffer, *bytes.Buffer, error, error) {
|
func (runner *Runner) runConcurrent(ctx context.Context, inv Invocation) (*bytes.Buffer, *bytes.Buffer, error, error) {
|
||||||
// Wait for 1 worker to become available.
|
// Wait for 1 worker to become available.
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, nil, nil, ctx.Err()
|
return nil, nil, ctx.Err(), ctx.Err()
|
||||||
case runner.inFlight <- struct{}{}:
|
case runner.inFlight <- struct{}{}:
|
||||||
defer func() { <-runner.inFlight }()
|
defer func() { <-runner.inFlight }()
|
||||||
}
|
}
|
||||||
@@ -121,6 +122,7 @@ func (runner *Runner) runConcurrent(ctx context.Context, inv Invocation) (*bytes
|
|||||||
return stdout, stderr, friendlyErr, err
|
return stdout, stderr, friendlyErr, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Postcondition: both error results have same nilness.
|
||||||
func (runner *Runner) runPiped(ctx context.Context, inv Invocation, stdout, stderr io.Writer) (error, error) {
|
func (runner *Runner) runPiped(ctx context.Context, inv Invocation, stdout, stderr io.Writer) (error, error) {
|
||||||
// Make sure the runner is always initialized.
|
// Make sure the runner is always initialized.
|
||||||
runner.initialize()
|
runner.initialize()
|
||||||
@@ -129,7 +131,7 @@ func (runner *Runner) runPiped(ctx context.Context, inv Invocation, stdout, stde
|
|||||||
// runPiped commands.
|
// runPiped commands.
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, ctx.Err()
|
return ctx.Err(), ctx.Err()
|
||||||
case runner.serialized <- struct{}{}:
|
case runner.serialized <- struct{}{}:
|
||||||
defer func() { <-runner.serialized }()
|
defer func() { <-runner.serialized }()
|
||||||
}
|
}
|
||||||
@@ -139,7 +141,7 @@ func (runner *Runner) runPiped(ctx context.Context, inv Invocation, stdout, stde
|
|||||||
for i := 0; i < maxInFlight; i++ {
|
for i := 0; i < maxInFlight; i++ {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, ctx.Err()
|
return ctx.Err(), ctx.Err()
|
||||||
case runner.inFlight <- struct{}{}:
|
case runner.inFlight <- struct{}{}:
|
||||||
// Make sure we always "return" any workers we took.
|
// Make sure we always "return" any workers we took.
|
||||||
defer func() { <-runner.inFlight }()
|
defer func() { <-runner.inFlight }()
|
||||||
@@ -172,6 +174,7 @@ type Invocation struct {
|
|||||||
Logf func(format string, args ...interface{})
|
Logf func(format string, args ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Postcondition: both error results have same nilness.
|
||||||
func (i *Invocation) runWithFriendlyError(ctx context.Context, stdout, stderr io.Writer) (friendlyError error, rawError error) {
|
func (i *Invocation) runWithFriendlyError(ctx context.Context, stdout, stderr io.Writer) (friendlyError error, rawError error) {
|
||||||
rawError = i.run(ctx, stdout, stderr)
|
rawError = i.run(ctx, stdout, stderr)
|
||||||
if rawError != nil {
|
if rawError != nil {
|
||||||
|
8
vendor/golang.org/x/tools/internal/packagesinternal/packages.go
generated
vendored
8
vendor/golang.org/x/tools/internal/packagesinternal/packages.go
generated
vendored
@@ -5,10 +5,6 @@
|
|||||||
// Package packagesinternal exposes internal-only fields from go/packages.
|
// Package packagesinternal exposes internal-only fields from go/packages.
|
||||||
package packagesinternal
|
package packagesinternal
|
||||||
|
|
||||||
import (
|
|
||||||
"golang.org/x/tools/internal/gocommand"
|
|
||||||
)
|
|
||||||
|
|
||||||
var GetForTest = func(p interface{}) string { return "" }
|
var GetForTest = func(p interface{}) string { return "" }
|
||||||
var GetDepsErrors = func(p interface{}) []*PackageError { return nil }
|
var GetDepsErrors = func(p interface{}) []*PackageError { return nil }
|
||||||
|
|
||||||
@@ -18,10 +14,6 @@ type PackageError struct {
|
|||||||
Err string // the error itself
|
Err string // the error itself
|
||||||
}
|
}
|
||||||
|
|
||||||
var GetGoCmdRunner = func(config interface{}) *gocommand.Runner { return nil }
|
|
||||||
|
|
||||||
var SetGoCmdRunner = func(config interface{}, runner *gocommand.Runner) {}
|
|
||||||
|
|
||||||
var TypecheckCgo int
|
var TypecheckCgo int
|
||||||
var DepsErrors int // must be set as a LoadMode to call GetDepsErrors
|
var DepsErrors int // must be set as a LoadMode to call GetDepsErrors
|
||||||
var ForTest int // must be set as a LoadMode to call GetForTest
|
var ForTest int // must be set as a LoadMode to call GetForTest
|
||||||
|
24
vendor/golang.org/x/tools/internal/typesinternal/objectpath.go
generated
vendored
24
vendor/golang.org/x/tools/internal/typesinternal/objectpath.go
generated
vendored
@@ -1,24 +0,0 @@
|
|||||||
// Copyright 2023 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 typesinternal
|
|
||||||
|
|
||||||
import "go/types"
|
|
||||||
|
|
||||||
// This file contains back doors that allow gopls to avoid method sorting when
|
|
||||||
// using the objectpath package.
|
|
||||||
//
|
|
||||||
// This is performance-critical in certain repositories, but changing the
|
|
||||||
// behavior of the objectpath package is still being discussed in
|
|
||||||
// golang/go#61443. If we decide to remove the sorting in objectpath we can
|
|
||||||
// simply delete these back doors. Otherwise, we should add a new API to
|
|
||||||
// objectpath that allows controlling the sorting.
|
|
||||||
|
|
||||||
// SkipEncoderMethodSorting marks enc (which must be an *objectpath.Encoder) as
|
|
||||||
// not requiring sorted methods.
|
|
||||||
var SkipEncoderMethodSorting func(enc interface{})
|
|
||||||
|
|
||||||
// ObjectpathObject is like objectpath.Object, but allows suppressing method
|
|
||||||
// sorting.
|
|
||||||
var ObjectpathObject func(pkg *types.Package, p string, skipMethodSorting bool) (types.Object, error)
|
|
172
vendor/golang.org/x/tools/internal/versions/gover.go
generated
vendored
Normal file
172
vendor/golang.org/x/tools/internal/versions/gover.go
generated
vendored
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
// Copyright 2023 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.
|
||||||
|
|
||||||
|
// This is a fork of internal/gover for use by x/tools until
|
||||||
|
// go1.21 and earlier are no longer supported by x/tools.
|
||||||
|
|
||||||
|
package versions
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
// A gover is a parsed Go gover: major[.Minor[.Patch]][kind[pre]]
|
||||||
|
// The numbers are the original decimal strings to avoid integer overflows
|
||||||
|
// and since there is very little actual math. (Probably overflow doesn't matter in practice,
|
||||||
|
// but at the time this code was written, there was an existing test that used
|
||||||
|
// go1.99999999999, which does not fit in an int on 32-bit platforms.
|
||||||
|
// The "big decimal" representation avoids the problem entirely.)
|
||||||
|
type gover struct {
|
||||||
|
major string // decimal
|
||||||
|
minor string // decimal or ""
|
||||||
|
patch string // decimal or ""
|
||||||
|
kind string // "", "alpha", "beta", "rc"
|
||||||
|
pre string // decimal or ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// compare returns -1, 0, or +1 depending on whether
|
||||||
|
// x < y, x == y, or x > y, interpreted as toolchain versions.
|
||||||
|
// The versions x and y must not begin with a "go" prefix: just "1.21" not "go1.21".
|
||||||
|
// Malformed versions compare less than well-formed versions and equal to each other.
|
||||||
|
// The language version "1.21" compares less than the release candidate and eventual releases "1.21rc1" and "1.21.0".
|
||||||
|
func compare(x, y string) int {
|
||||||
|
vx := parse(x)
|
||||||
|
vy := parse(y)
|
||||||
|
|
||||||
|
if c := cmpInt(vx.major, vy.major); c != 0 {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
if c := cmpInt(vx.minor, vy.minor); c != 0 {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
if c := cmpInt(vx.patch, vy.patch); c != 0 {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
if c := strings.Compare(vx.kind, vy.kind); c != 0 { // "" < alpha < beta < rc
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
if c := cmpInt(vx.pre, vy.pre); c != 0 {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// lang returns the Go language version. For example, lang("1.2.3") == "1.2".
|
||||||
|
func lang(x string) string {
|
||||||
|
v := parse(x)
|
||||||
|
if v.minor == "" || v.major == "1" && v.minor == "0" {
|
||||||
|
return v.major
|
||||||
|
}
|
||||||
|
return v.major + "." + v.minor
|
||||||
|
}
|
||||||
|
|
||||||
|
// isValid reports whether the version x is valid.
|
||||||
|
func isValid(x string) bool {
|
||||||
|
return parse(x) != gover{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse parses the Go version string x into a version.
|
||||||
|
// It returns the zero version if x is malformed.
|
||||||
|
func parse(x string) gover {
|
||||||
|
var v gover
|
||||||
|
|
||||||
|
// Parse major version.
|
||||||
|
var ok bool
|
||||||
|
v.major, x, ok = cutInt(x)
|
||||||
|
if !ok {
|
||||||
|
return gover{}
|
||||||
|
}
|
||||||
|
if x == "" {
|
||||||
|
// Interpret "1" as "1.0.0".
|
||||||
|
v.minor = "0"
|
||||||
|
v.patch = "0"
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse . before minor version.
|
||||||
|
if x[0] != '.' {
|
||||||
|
return gover{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse minor version.
|
||||||
|
v.minor, x, ok = cutInt(x[1:])
|
||||||
|
if !ok {
|
||||||
|
return gover{}
|
||||||
|
}
|
||||||
|
if x == "" {
|
||||||
|
// Patch missing is same as "0" for older versions.
|
||||||
|
// Starting in Go 1.21, patch missing is different from explicit .0.
|
||||||
|
if cmpInt(v.minor, "21") < 0 {
|
||||||
|
v.patch = "0"
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse patch if present.
|
||||||
|
if x[0] == '.' {
|
||||||
|
v.patch, x, ok = cutInt(x[1:])
|
||||||
|
if !ok || x != "" {
|
||||||
|
// Note that we are disallowing prereleases (alpha, beta, rc) for patch releases here (x != "").
|
||||||
|
// Allowing them would be a bit confusing because we already have:
|
||||||
|
// 1.21 < 1.21rc1
|
||||||
|
// But a prerelease of a patch would have the opposite effect:
|
||||||
|
// 1.21.3rc1 < 1.21.3
|
||||||
|
// We've never needed them before, so let's not start now.
|
||||||
|
return gover{}
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse prerelease.
|
||||||
|
i := 0
|
||||||
|
for i < len(x) && (x[i] < '0' || '9' < x[i]) {
|
||||||
|
if x[i] < 'a' || 'z' < x[i] {
|
||||||
|
return gover{}
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
if i == 0 {
|
||||||
|
return gover{}
|
||||||
|
}
|
||||||
|
v.kind, x = x[:i], x[i:]
|
||||||
|
if x == "" {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
v.pre, x, ok = cutInt(x)
|
||||||
|
if !ok || x != "" {
|
||||||
|
return gover{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// cutInt scans the leading decimal number at the start of x to an integer
|
||||||
|
// and returns that value and the rest of the string.
|
||||||
|
func cutInt(x string) (n, rest string, ok bool) {
|
||||||
|
i := 0
|
||||||
|
for i < len(x) && '0' <= x[i] && x[i] <= '9' {
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
if i == 0 || x[0] == '0' && i != 1 { // no digits or unnecessary leading zero
|
||||||
|
return "", "", false
|
||||||
|
}
|
||||||
|
return x[:i], x[i:], true
|
||||||
|
}
|
||||||
|
|
||||||
|
// cmpInt returns cmp.Compare(x, y) interpreting x and y as decimal numbers.
|
||||||
|
// (Copied from golang.org/x/mod/semver's compareInt.)
|
||||||
|
func cmpInt(x, y string) int {
|
||||||
|
if x == y {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if len(x) < len(y) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if len(x) > len(y) {
|
||||||
|
return +1
|
||||||
|
}
|
||||||
|
if x < y {
|
||||||
|
return -1
|
||||||
|
} else {
|
||||||
|
return +1
|
||||||
|
}
|
||||||
|
}
|
19
vendor/golang.org/x/tools/internal/versions/types.go
generated
vendored
Normal file
19
vendor/golang.org/x/tools/internal/versions/types.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// Copyright 2023 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 versions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GoVersion returns the Go version of the type package.
|
||||||
|
// It returns zero if no version can be determined.
|
||||||
|
func GoVersion(pkg *types.Package) string {
|
||||||
|
// TODO(taking): x/tools can call GoVersion() [from 1.21] after 1.25.
|
||||||
|
if pkg, ok := any(pkg).(interface{ GoVersion() string }); ok {
|
||||||
|
return pkg.GoVersion()
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
20
vendor/golang.org/x/tools/internal/versions/types_go121.go
generated
vendored
Normal file
20
vendor/golang.org/x/tools/internal/versions/types_go121.go
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// Copyright 2023 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.
|
||||||
|
|
||||||
|
//go:build !go1.22
|
||||||
|
// +build !go1.22
|
||||||
|
|
||||||
|
package versions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go/ast"
|
||||||
|
"go/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FileVersions always reports the a file's Go version as the
|
||||||
|
// zero version at this Go version.
|
||||||
|
func FileVersions(info *types.Info, file *ast.File) string { return "" }
|
||||||
|
|
||||||
|
// InitFileVersions is a noop at this Go version.
|
||||||
|
func InitFileVersions(*types.Info) {}
|
24
vendor/golang.org/x/tools/internal/versions/types_go122.go
generated
vendored
Normal file
24
vendor/golang.org/x/tools/internal/versions/types_go122.go
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2023 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.
|
||||||
|
|
||||||
|
//go:build go1.22
|
||||||
|
// +build go1.22
|
||||||
|
|
||||||
|
package versions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go/ast"
|
||||||
|
"go/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FileVersions maps a file to the file's semantic Go version.
|
||||||
|
// The reported version is the zero version if a version cannot be determined.
|
||||||
|
func FileVersions(info *types.Info, file *ast.File) string {
|
||||||
|
return info.FileVersions[file]
|
||||||
|
}
|
||||||
|
|
||||||
|
// InitFileVersions initializes info to record Go versions for Go files.
|
||||||
|
func InitFileVersions(info *types.Info) {
|
||||||
|
info.FileVersions = make(map[*ast.File]string)
|
||||||
|
}
|
49
vendor/golang.org/x/tools/internal/versions/versions_go121.go
generated
vendored
Normal file
49
vendor/golang.org/x/tools/internal/versions/versions_go121.go
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
// Copyright 2023 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.
|
||||||
|
|
||||||
|
//go:build !go1.22
|
||||||
|
// +build !go1.22
|
||||||
|
|
||||||
|
package versions
|
||||||
|
|
||||||
|
// Lang returns the Go language version for version x.
|
||||||
|
// If x is not a valid version, Lang returns the empty string.
|
||||||
|
// For example:
|
||||||
|
//
|
||||||
|
// Lang("go1.21rc2") = "go1.21"
|
||||||
|
// Lang("go1.21.2") = "go1.21"
|
||||||
|
// Lang("go1.21") = "go1.21"
|
||||||
|
// Lang("go1") = "go1"
|
||||||
|
// Lang("bad") = ""
|
||||||
|
// Lang("1.21") = ""
|
||||||
|
func Lang(x string) string {
|
||||||
|
v := lang(stripGo(x))
|
||||||
|
if v == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return x[:2+len(v)] // "go"+v without allocation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare returns -1, 0, or +1 depending on whether
|
||||||
|
// x < y, x == y, or x > y, interpreted as Go versions.
|
||||||
|
// The versions x and y must begin with a "go" prefix: "go1.21" not "1.21".
|
||||||
|
// Invalid versions, including the empty string, compare less than
|
||||||
|
// valid versions and equal to each other.
|
||||||
|
// The language version "go1.21" compares less than the
|
||||||
|
// release candidate and eventual releases "go1.21rc1" and "go1.21.0".
|
||||||
|
// Custom toolchain suffixes are ignored during comparison:
|
||||||
|
// "go1.21.0" and "go1.21.0-bigcorp" are equal.
|
||||||
|
func Compare(x, y string) int { return compare(stripGo(x), stripGo(y)) }
|
||||||
|
|
||||||
|
// IsValid reports whether the version x is valid.
|
||||||
|
func IsValid(x string) bool { return isValid(stripGo(x)) }
|
||||||
|
|
||||||
|
// stripGo converts from a "go1.21" version to a "1.21" version.
|
||||||
|
// If v does not start with "go", stripGo returns the empty string (a known invalid version).
|
||||||
|
func stripGo(v string) string {
|
||||||
|
if len(v) < 2 || v[:2] != "go" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return v[2:]
|
||||||
|
}
|
38
vendor/golang.org/x/tools/internal/versions/versions_go122.go
generated
vendored
Normal file
38
vendor/golang.org/x/tools/internal/versions/versions_go122.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// Copyright 2023 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.
|
||||||
|
|
||||||
|
//go:build go1.22
|
||||||
|
// +build go1.22
|
||||||
|
|
||||||
|
package versions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Lang returns the Go language version for version x.
|
||||||
|
// If x is not a valid version, Lang returns the empty string.
|
||||||
|
// For example:
|
||||||
|
//
|
||||||
|
// Lang("go1.21rc2") = "go1.21"
|
||||||
|
// Lang("go1.21.2") = "go1.21"
|
||||||
|
// Lang("go1.21") = "go1.21"
|
||||||
|
// Lang("go1") = "go1"
|
||||||
|
// Lang("bad") = ""
|
||||||
|
// Lang("1.21") = ""
|
||||||
|
func Lang(x string) string { return version.Lang(x) }
|
||||||
|
|
||||||
|
// Compare returns -1, 0, or +1 depending on whether
|
||||||
|
// x < y, x == y, or x > y, interpreted as Go versions.
|
||||||
|
// The versions x and y must begin with a "go" prefix: "go1.21" not "1.21".
|
||||||
|
// Invalid versions, including the empty string, compare less than
|
||||||
|
// valid versions and equal to each other.
|
||||||
|
// The language version "go1.21" compares less than the
|
||||||
|
// release candidate and eventual releases "go1.21rc1" and "go1.21.0".
|
||||||
|
// Custom toolchain suffixes are ignored during comparison:
|
||||||
|
// "go1.21.0" and "go1.21.0-bigcorp" are equal.
|
||||||
|
func Compare(x, y string) int { return version.Compare(x, y) }
|
||||||
|
|
||||||
|
// IsValid reports whether the version x is valid.
|
||||||
|
func IsValid(x string) bool { return version.IsValid(x) }
|
12
vendor/modules.txt
vendored
12
vendor/modules.txt
vendored
@@ -599,7 +599,7 @@ go.opentelemetry.io/otel/metric/embedded
|
|||||||
# go.opentelemetry.io/otel/trace v1.19.0
|
# go.opentelemetry.io/otel/trace v1.19.0
|
||||||
## explicit; go 1.20
|
## explicit; go 1.20
|
||||||
go.opentelemetry.io/otel/trace
|
go.opentelemetry.io/otel/trace
|
||||||
# golang.org/x/crypto v0.15.0
|
# golang.org/x/crypto v0.16.0
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
golang.org/x/crypto/cast5
|
golang.org/x/crypto/cast5
|
||||||
golang.org/x/crypto/ed25519
|
golang.org/x/crypto/ed25519
|
||||||
@@ -617,16 +617,16 @@ golang.org/x/crypto/pbkdf2
|
|||||||
golang.org/x/crypto/salsa20/salsa
|
golang.org/x/crypto/salsa20/salsa
|
||||||
golang.org/x/crypto/scrypt
|
golang.org/x/crypto/scrypt
|
||||||
golang.org/x/crypto/sha3
|
golang.org/x/crypto/sha3
|
||||||
# golang.org/x/exp v0.0.0-20231006140011-7918f672742d
|
# golang.org/x/exp v0.0.0-20231127185646-65229373498e
|
||||||
## explicit; go 1.20
|
## explicit; go 1.20
|
||||||
golang.org/x/exp/constraints
|
golang.org/x/exp/constraints
|
||||||
golang.org/x/exp/maps
|
golang.org/x/exp/maps
|
||||||
golang.org/x/exp/slices
|
golang.org/x/exp/slices
|
||||||
# golang.org/x/mod v0.13.0
|
# golang.org/x/mod v0.14.0
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
golang.org/x/mod/semver
|
golang.org/x/mod/semver
|
||||||
golang.org/x/mod/sumdb/note
|
golang.org/x/mod/sumdb/note
|
||||||
# golang.org/x/net v0.18.0
|
# golang.org/x/net v0.19.0
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
golang.org/x/net/http/httpguts
|
golang.org/x/net/http/httpguts
|
||||||
golang.org/x/net/http2
|
golang.org/x/net/http2
|
||||||
@@ -647,7 +647,6 @@ golang.org/x/sync/semaphore
|
|||||||
# golang.org/x/sys v0.15.0
|
# golang.org/x/sys v0.15.0
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
golang.org/x/sys/cpu
|
golang.org/x/sys/cpu
|
||||||
golang.org/x/sys/execabs
|
|
||||||
golang.org/x/sys/plan9
|
golang.org/x/sys/plan9
|
||||||
golang.org/x/sys/unix
|
golang.org/x/sys/unix
|
||||||
golang.org/x/sys/windows
|
golang.org/x/sys/windows
|
||||||
@@ -661,7 +660,7 @@ golang.org/x/text/secure/bidirule
|
|||||||
golang.org/x/text/transform
|
golang.org/x/text/transform
|
||||||
golang.org/x/text/unicode/bidi
|
golang.org/x/text/unicode/bidi
|
||||||
golang.org/x/text/unicode/norm
|
golang.org/x/text/unicode/norm
|
||||||
# golang.org/x/tools v0.14.0
|
# golang.org/x/tools v0.16.0
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
golang.org/x/tools/cmd/stringer
|
golang.org/x/tools/cmd/stringer
|
||||||
golang.org/x/tools/go/gcexportdata
|
golang.org/x/tools/go/gcexportdata
|
||||||
@@ -680,6 +679,7 @@ golang.org/x/tools/internal/pkgbits
|
|||||||
golang.org/x/tools/internal/tokeninternal
|
golang.org/x/tools/internal/tokeninternal
|
||||||
golang.org/x/tools/internal/typeparams
|
golang.org/x/tools/internal/typeparams
|
||||||
golang.org/x/tools/internal/typesinternal
|
golang.org/x/tools/internal/typesinternal
|
||||||
|
golang.org/x/tools/internal/versions
|
||||||
# google.golang.org/appengine v1.6.8
|
# google.golang.org/appengine v1.6.8
|
||||||
## explicit; go 1.11
|
## explicit; go 1.11
|
||||||
google.golang.org/appengine/internal
|
google.golang.org/appengine/internal
|
||||||
|
Reference in New Issue
Block a user