mirror of https://github.com/knative/pkg.git
Bump golang.org/x/tools from 0.17.0 to 0.18.0 (#2961)
* Bump golang.org/x/tools from 0.17.0 to 0.18.0 Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.17.0 to 0.18.0. - [Release notes](https://github.com/golang/tools/releases) - [Commits](https://github.com/golang/tools/compare/v0.17.0...v0.18.0) --- updated-dependencies: - dependency-name: golang.org/x/tools dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Run ./hack/update-codegen.sh --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
f094d825cd
commit
0d884498af
4
go.mod
4
go.mod
|
@ -34,7 +34,7 @@ require (
|
||||||
golang.org/x/net v0.21.0
|
golang.org/x/net v0.21.0
|
||||||
golang.org/x/oauth2 v0.17.0
|
golang.org/x/oauth2 v0.17.0
|
||||||
golang.org/x/sync v0.6.0
|
golang.org/x/sync v0.6.0
|
||||||
golang.org/x/tools v0.17.0
|
golang.org/x/tools v0.18.0
|
||||||
gomodules.xyz/jsonpatch/v2 v2.4.0
|
gomodules.xyz/jsonpatch/v2 v2.4.0
|
||||||
google.golang.org/api v0.163.0
|
google.golang.org/api v0.163.0
|
||||||
google.golang.org/grpc v1.61.0
|
google.golang.org/grpc v1.61.0
|
||||||
|
@ -98,7 +98,7 @@ require (
|
||||||
go.uber.org/goleak v1.2.1 // indirect
|
go.uber.org/goleak v1.2.1 // indirect
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
golang.org/x/crypto v0.19.0 // indirect
|
golang.org/x/crypto v0.19.0 // indirect
|
||||||
golang.org/x/mod v0.14.0 // indirect
|
golang.org/x/mod v0.15.0 // indirect
|
||||||
golang.org/x/sys v0.17.0 // indirect
|
golang.org/x/sys v0.17.0 // indirect
|
||||||
golang.org/x/term v0.17.0 // indirect
|
golang.org/x/term v0.17.0 // indirect
|
||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
|
|
8
go.sum
8
go.sum
|
@ -443,8 +443,8 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB
|
||||||
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.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
|
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
|
||||||
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
golang.org/x/mod v0.15.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-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
@ -616,8 +616,8 @@ golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc
|
||||||
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||||
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.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
|
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
|
||||||
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
|
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
|
||||||
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=
|
||||||
|
|
|
@ -15,22 +15,10 @@ Load passes most patterns directly to the underlying build tool.
|
||||||
The default build tool is the go command.
|
The default build tool is the go command.
|
||||||
Its supported patterns are described at
|
Its supported patterns are described at
|
||||||
https://pkg.go.dev/cmd/go#hdr-Package_lists_and_patterns.
|
https://pkg.go.dev/cmd/go#hdr-Package_lists_and_patterns.
|
||||||
|
Other build systems may be supported by providing a "driver";
|
||||||
|
see [The driver protocol].
|
||||||
|
|
||||||
Load may be used in Go projects that use alternative build systems, by
|
All patterns with the prefix "query=", where query is a
|
||||||
installing an appropriate "driver" program for the build system and
|
|
||||||
specifying its location in the GOPACKAGESDRIVER environment variable.
|
|
||||||
For example,
|
|
||||||
https://github.com/bazelbuild/rules_go/wiki/Editor-and-tool-integration
|
|
||||||
explains how to use the driver for Bazel.
|
|
||||||
The driver program is responsible for interpreting patterns in its
|
|
||||||
preferred notation and reporting information about the packages that
|
|
||||||
they identify.
|
|
||||||
(See driverRequest and driverResponse types for the JSON
|
|
||||||
schema used by the protocol.
|
|
||||||
Though the protocol is supported, these types are currently unexported;
|
|
||||||
see #64608 for a proposal to publish them.)
|
|
||||||
|
|
||||||
Regardless of driver, all patterns with the prefix "query=", where query is a
|
|
||||||
non-empty string of letters from [a-z], are reserved and may be
|
non-empty string of letters from [a-z], are reserved and may be
|
||||||
interpreted as query operators.
|
interpreted as query operators.
|
||||||
|
|
||||||
|
@ -86,7 +74,29 @@ for details.
|
||||||
Most tools should pass their command-line arguments (after any flags)
|
Most tools should pass their command-line arguments (after any flags)
|
||||||
uninterpreted to [Load], so that it can interpret them
|
uninterpreted to [Load], so that it can interpret them
|
||||||
according to the conventions of the underlying build system.
|
according to the conventions of the underlying build system.
|
||||||
|
|
||||||
See the Example function for typical usage.
|
See the Example function for typical usage.
|
||||||
|
|
||||||
|
# The driver protocol
|
||||||
|
|
||||||
|
[Load] may be used to load Go packages even in Go projects that use
|
||||||
|
alternative build systems, by installing an appropriate "driver"
|
||||||
|
program for the build system and specifying its location in the
|
||||||
|
GOPACKAGESDRIVER environment variable.
|
||||||
|
For example,
|
||||||
|
https://github.com/bazelbuild/rules_go/wiki/Editor-and-tool-integration
|
||||||
|
explains how to use the driver for Bazel.
|
||||||
|
|
||||||
|
The driver program is responsible for interpreting patterns in its
|
||||||
|
preferred notation and reporting information about the packages that
|
||||||
|
those patterns identify. Drivers must also support the special "file="
|
||||||
|
and "pattern=" patterns described above.
|
||||||
|
|
||||||
|
The patterns are provided as positional command-line arguments. A
|
||||||
|
JSON-encoded [DriverRequest] message providing additional information
|
||||||
|
is written to the driver's standard input. The driver must write a
|
||||||
|
JSON-encoded [DriverResponse] message to its standard output. (This
|
||||||
|
message differs from the JSON schema produced by 'go list'.)
|
||||||
*/
|
*/
|
||||||
package packages // import "golang.org/x/tools/go/packages"
|
package packages // import "golang.org/x/tools/go/packages"
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,11 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// This file enables an external tool to intercept package requests.
|
|
||||||
// If the tool is present then its results are used in preference to
|
|
||||||
// the go list command.
|
|
||||||
|
|
||||||
package packages
|
package packages
|
||||||
|
|
||||||
|
// This file defines the protocol that enables an external "driver"
|
||||||
|
// tool to supply package metadata in place of 'go list'.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -17,31 +16,71 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The Driver Protocol
|
// DriverRequest defines the schema of a request for package metadata
|
||||||
|
// from an external driver program. The JSON-encoded DriverRequest
|
||||||
|
// message is provided to the driver program's standard input. The
|
||||||
|
// query patterns are provided as command-line arguments.
|
||||||
//
|
//
|
||||||
// The driver, given the inputs to a call to Load, returns metadata about the packages specified.
|
// See the package documentation for an overview.
|
||||||
// This allows for different build systems to support go/packages by telling go/packages how the
|
type DriverRequest struct {
|
||||||
// packages' source is organized.
|
|
||||||
// The driver is a binary, either specified by the GOPACKAGESDRIVER environment variable or in
|
|
||||||
// the path as gopackagesdriver. It's given the inputs to load in its argv. See the package
|
|
||||||
// documentation in doc.go for the full description of the patterns that need to be supported.
|
|
||||||
// A driver receives as a JSON-serialized driverRequest struct in standard input and will
|
|
||||||
// produce a JSON-serialized driverResponse (see definition in packages.go) in its standard output.
|
|
||||||
|
|
||||||
// driverRequest is used to provide the portion of Load's Config that is needed by a driver.
|
|
||||||
type driverRequest struct {
|
|
||||||
Mode LoadMode `json:"mode"`
|
Mode LoadMode `json:"mode"`
|
||||||
|
|
||||||
// Env specifies the environment the underlying build system should be run in.
|
// Env specifies the environment the underlying build system should be run in.
|
||||||
Env []string `json:"env"`
|
Env []string `json:"env"`
|
||||||
|
|
||||||
// BuildFlags are flags that should be passed to the underlying build system.
|
// BuildFlags are flags that should be passed to the underlying build system.
|
||||||
BuildFlags []string `json:"build_flags"`
|
BuildFlags []string `json:"build_flags"`
|
||||||
|
|
||||||
// Tests specifies whether the patterns should also return test packages.
|
// Tests specifies whether the patterns should also return test packages.
|
||||||
Tests bool `json:"tests"`
|
Tests bool `json:"tests"`
|
||||||
|
|
||||||
// Overlay maps file paths (relative to the driver's working directory) to the byte contents
|
// Overlay maps file paths (relative to the driver's working directory) to the byte contents
|
||||||
// of overlay files.
|
// of overlay files.
|
||||||
Overlay map[string][]byte `json:"overlay"`
|
Overlay map[string][]byte `json:"overlay"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DriverResponse defines the schema of a response from an external
|
||||||
|
// driver program, providing the results of a query for package
|
||||||
|
// metadata. The driver program must write a JSON-encoded
|
||||||
|
// DriverResponse message to its standard output.
|
||||||
|
//
|
||||||
|
// See the package documentation for an overview.
|
||||||
|
type DriverResponse struct {
|
||||||
|
// NotHandled is returned if the request can't be handled by the current
|
||||||
|
// driver. If an external driver returns a response with NotHandled, the
|
||||||
|
// rest of the DriverResponse is ignored, and go/packages will fallback
|
||||||
|
// to the next driver. If go/packages is extended in the future to support
|
||||||
|
// lists of multiple drivers, go/packages will fall back to the next driver.
|
||||||
|
NotHandled bool
|
||||||
|
|
||||||
|
// Compiler and Arch are the arguments pass of types.SizesFor
|
||||||
|
// to get a types.Sizes to use when type checking.
|
||||||
|
Compiler string
|
||||||
|
Arch string
|
||||||
|
|
||||||
|
// Roots is the set of package IDs that make up the root packages.
|
||||||
|
// We have to encode this separately because when we encode a single package
|
||||||
|
// we cannot know if it is one of the roots as that requires knowledge of the
|
||||||
|
// graph it is part of.
|
||||||
|
Roots []string `json:",omitempty"`
|
||||||
|
|
||||||
|
// Packages is the full set of packages in the graph.
|
||||||
|
// The packages are not connected into a graph.
|
||||||
|
// The Imports if populated will be stubs that only have their ID set.
|
||||||
|
// Imports will be connected and then type and syntax information added in a
|
||||||
|
// later pass (see refine).
|
||||||
|
Packages []*Package
|
||||||
|
|
||||||
|
// GoVersion is the minor version number used by the driver
|
||||||
|
// (e.g. the go command on the PATH) when selecting .go files.
|
||||||
|
// Zero means unknown.
|
||||||
|
GoVersion int
|
||||||
|
}
|
||||||
|
|
||||||
|
// driver is the type for functions that query the build system for the
|
||||||
|
// packages named by the patterns.
|
||||||
|
type driver func(cfg *Config, patterns ...string) (*DriverResponse, error)
|
||||||
|
|
||||||
// findExternalDriver returns the file path of a tool that supplies
|
// findExternalDriver returns the file path of a tool that supplies
|
||||||
// the build system package structure, or "" if not found."
|
// the build system package structure, or "" if not found."
|
||||||
// If GOPACKAGESDRIVER is set in the environment findExternalTool returns its
|
// If GOPACKAGESDRIVER is set in the environment findExternalTool returns its
|
||||||
|
@ -64,8 +103,8 @@ func findExternalDriver(cfg *Config) driver {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return func(cfg *Config, words ...string) (*driverResponse, error) {
|
return func(cfg *Config, words ...string) (*DriverResponse, error) {
|
||||||
req, err := json.Marshal(driverRequest{
|
req, err := json.Marshal(DriverRequest{
|
||||||
Mode: cfg.Mode,
|
Mode: cfg.Mode,
|
||||||
Env: cfg.Env,
|
Env: cfg.Env,
|
||||||
BuildFlags: cfg.BuildFlags,
|
BuildFlags: cfg.BuildFlags,
|
||||||
|
@ -92,7 +131,7 @@ func findExternalDriver(cfg *Config) driver {
|
||||||
fmt.Fprintf(os.Stderr, "%s stderr: <<%s>>\n", cmdDebugStr(cmd), stderr)
|
fmt.Fprintf(os.Stderr, "%s stderr: <<%s>>\n", cmdDebugStr(cmd), stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
var response driverResponse
|
var response DriverResponse
|
||||||
if err := json.Unmarshal(buf.Bytes(), &response); err != nil {
|
if err := json.Unmarshal(buf.Bytes(), &response); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,23 +35,23 @@ type goTooOldError struct {
|
||||||
error
|
error
|
||||||
}
|
}
|
||||||
|
|
||||||
// responseDeduper wraps a driverResponse, deduplicating its contents.
|
// responseDeduper wraps a DriverResponse, deduplicating its contents.
|
||||||
type responseDeduper struct {
|
type responseDeduper struct {
|
||||||
seenRoots map[string]bool
|
seenRoots map[string]bool
|
||||||
seenPackages map[string]*Package
|
seenPackages map[string]*Package
|
||||||
dr *driverResponse
|
dr *DriverResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDeduper() *responseDeduper {
|
func newDeduper() *responseDeduper {
|
||||||
return &responseDeduper{
|
return &responseDeduper{
|
||||||
dr: &driverResponse{},
|
dr: &DriverResponse{},
|
||||||
seenRoots: map[string]bool{},
|
seenRoots: map[string]bool{},
|
||||||
seenPackages: map[string]*Package{},
|
seenPackages: map[string]*Package{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// addAll fills in r with a driverResponse.
|
// addAll fills in r with a DriverResponse.
|
||||||
func (r *responseDeduper) addAll(dr *driverResponse) {
|
func (r *responseDeduper) addAll(dr *DriverResponse) {
|
||||||
for _, pkg := range dr.Packages {
|
for _, pkg := range dr.Packages {
|
||||||
r.addPackage(pkg)
|
r.addPackage(pkg)
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ func (state *golistState) mustGetEnv() map[string]string {
|
||||||
// goListDriver uses the go list command to interpret the patterns and produce
|
// goListDriver uses the go list command to interpret the patterns and produce
|
||||||
// the build system package structure.
|
// the build system package structure.
|
||||||
// See driver for more details.
|
// See driver for more details.
|
||||||
func goListDriver(cfg *Config, patterns ...string) (*driverResponse, error) {
|
func goListDriver(cfg *Config, patterns ...string) (_ *DriverResponse, err error) {
|
||||||
// Make sure that any asynchronous go commands are killed when we return.
|
// Make sure that any asynchronous go commands are killed when we return.
|
||||||
parentCtx := cfg.Context
|
parentCtx := cfg.Context
|
||||||
if parentCtx == nil {
|
if parentCtx == nil {
|
||||||
|
@ -146,16 +146,18 @@ func goListDriver(cfg *Config, patterns ...string) (*driverResponse, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in response.Sizes asynchronously if necessary.
|
// Fill in response.Sizes asynchronously if necessary.
|
||||||
var sizeserr error
|
|
||||||
var sizeswg sync.WaitGroup
|
|
||||||
if cfg.Mode&NeedTypesSizes != 0 || cfg.Mode&NeedTypes != 0 {
|
if cfg.Mode&NeedTypesSizes != 0 || cfg.Mode&NeedTypes != 0 {
|
||||||
sizeswg.Add(1)
|
errCh := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
compiler, arch, err := packagesdriver.GetSizesForArgsGolist(ctx, state.cfgInvocation(), cfg.gocmdRunner)
|
compiler, arch, err := packagesdriver.GetSizesForArgsGolist(ctx, state.cfgInvocation(), cfg.gocmdRunner)
|
||||||
sizeserr = err
|
|
||||||
response.dr.Compiler = compiler
|
response.dr.Compiler = compiler
|
||||||
response.dr.Arch = arch
|
response.dr.Arch = arch
|
||||||
sizeswg.Done()
|
errCh <- err
|
||||||
|
}()
|
||||||
|
defer func() {
|
||||||
|
if sizesErr := <-errCh; sizesErr != nil {
|
||||||
|
err = sizesErr
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,10 +210,7 @@ extractQueries:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sizeswg.Wait()
|
// (We may yet return an error due to defer.)
|
||||||
if sizeserr != nil {
|
|
||||||
return nil, sizeserr
|
|
||||||
}
|
|
||||||
return response.dr, nil
|
return response.dr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +265,7 @@ func (state *golistState) runContainsQueries(response *responseDeduper, queries
|
||||||
|
|
||||||
// adhocPackage attempts to load or construct an ad-hoc package for a given
|
// adhocPackage attempts to load or construct an ad-hoc package for a given
|
||||||
// query, if the original call to the driver produced inadequate results.
|
// query, if the original call to the driver produced inadequate results.
|
||||||
func (state *golistState) adhocPackage(pattern, query string) (*driverResponse, error) {
|
func (state *golistState) adhocPackage(pattern, query string) (*DriverResponse, error) {
|
||||||
response, err := state.createDriverResponse(query)
|
response, err := state.createDriverResponse(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -357,7 +356,7 @@ func otherFiles(p *jsonPackage) [][]string {
|
||||||
|
|
||||||
// createDriverResponse uses the "go list" command to expand the pattern
|
// createDriverResponse uses the "go list" command to expand the pattern
|
||||||
// words and return a response for the specified packages.
|
// words and return a response for the specified packages.
|
||||||
func (state *golistState) createDriverResponse(words ...string) (*driverResponse, error) {
|
func (state *golistState) createDriverResponse(words ...string) (*DriverResponse, error) {
|
||||||
// go list uses the following identifiers in ImportPath and Imports:
|
// go list uses the following identifiers in ImportPath and Imports:
|
||||||
//
|
//
|
||||||
// "p" -- importable package or main (command)
|
// "p" -- importable package or main (command)
|
||||||
|
@ -384,7 +383,7 @@ func (state *golistState) createDriverResponse(words ...string) (*driverResponse
|
||||||
pkgs := make(map[string]*Package)
|
pkgs := make(map[string]*Package)
|
||||||
additionalErrors := make(map[string][]Error)
|
additionalErrors := make(map[string][]Error)
|
||||||
// Decode the JSON and convert it to Package form.
|
// Decode the JSON and convert it to Package form.
|
||||||
response := &driverResponse{
|
response := &DriverResponse{
|
||||||
GoVersion: goVersion,
|
GoVersion: goVersion,
|
||||||
}
|
}
|
||||||
for dec := json.NewDecoder(buf); dec.More(); {
|
for dec := json.NewDecoder(buf); dec.More(); {
|
||||||
|
|
|
@ -206,43 +206,6 @@ type Config struct {
|
||||||
Overlay map[string][]byte
|
Overlay map[string][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// driver is the type for functions that query the build system for the
|
|
||||||
// packages named by the patterns.
|
|
||||||
type driver func(cfg *Config, patterns ...string) (*driverResponse, error)
|
|
||||||
|
|
||||||
// driverResponse contains the results for a driver query.
|
|
||||||
type driverResponse struct {
|
|
||||||
// NotHandled is returned if the request can't be handled by the current
|
|
||||||
// driver. If an external driver returns a response with NotHandled, the
|
|
||||||
// rest of the driverResponse is ignored, and go/packages will fallback
|
|
||||||
// to the next driver. If go/packages is extended in the future to support
|
|
||||||
// lists of multiple drivers, go/packages will fall back to the next driver.
|
|
||||||
NotHandled bool
|
|
||||||
|
|
||||||
// Compiler and Arch are the arguments pass of types.SizesFor
|
|
||||||
// to get a types.Sizes to use when type checking.
|
|
||||||
Compiler string
|
|
||||||
Arch string
|
|
||||||
|
|
||||||
// Roots is the set of package IDs that make up the root packages.
|
|
||||||
// We have to encode this separately because when we encode a single package
|
|
||||||
// we cannot know if it is one of the roots as that requires knowledge of the
|
|
||||||
// graph it is part of.
|
|
||||||
Roots []string `json:",omitempty"`
|
|
||||||
|
|
||||||
// Packages is the full set of packages in the graph.
|
|
||||||
// The packages are not connected into a graph.
|
|
||||||
// The Imports if populated will be stubs that only have their ID set.
|
|
||||||
// Imports will be connected and then type and syntax information added in a
|
|
||||||
// later pass (see refine).
|
|
||||||
Packages []*Package
|
|
||||||
|
|
||||||
// GoVersion is the minor version number used by the driver
|
|
||||||
// (e.g. the go command on the PATH) when selecting .go files.
|
|
||||||
// Zero means unknown.
|
|
||||||
GoVersion int
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load loads and returns the Go packages named by the given patterns.
|
// Load loads and returns the Go packages named by the given patterns.
|
||||||
//
|
//
|
||||||
// Config specifies loading options;
|
// Config specifies loading options;
|
||||||
|
@ -291,7 +254,7 @@ func Load(cfg *Config, patterns ...string) ([]*Package, error) {
|
||||||
// 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.
|
||||||
// The boolean result indicates that an external driver handled the request.
|
// The boolean result indicates that an external driver handled the request.
|
||||||
func defaultDriver(cfg *Config, patterns ...string) (*driverResponse, bool, error) {
|
func defaultDriver(cfg *Config, patterns ...string) (*DriverResponse, bool, error) {
|
||||||
if driver := findExternalDriver(cfg); driver != nil {
|
if driver := findExternalDriver(cfg); driver != nil {
|
||||||
response, err := driver(cfg, patterns...)
|
response, err := driver(cfg, patterns...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -303,7 +266,10 @@ func defaultDriver(cfg *Config, patterns ...string) (*driverResponse, bool, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := goListDriver(cfg, patterns...)
|
response, err := goListDriver(cfg, patterns...)
|
||||||
return response, false, err
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
return response, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Package describes a loaded Go package.
|
// A Package describes a loaded Go package.
|
||||||
|
@ -648,7 +614,7 @@ func newLoader(cfg *Config) *loader {
|
||||||
|
|
||||||
// refine connects the supplied packages into a graph and then adds type
|
// refine connects the supplied packages into a graph and then adds type
|
||||||
// and syntax information as requested by the LoadMode.
|
// and syntax information as requested by the LoadMode.
|
||||||
func (ld *loader) refine(response *driverResponse) ([]*Package, error) {
|
func (ld *loader) refine(response *DriverResponse) ([]*Package, error) {
|
||||||
roots := response.Roots
|
roots := response.Roots
|
||||||
rootMap := make(map[string]int, len(roots))
|
rootMap := make(map[string]int, len(roots))
|
||||||
for i, root := range roots {
|
for i, root := range roots {
|
||||||
|
|
|
@ -224,6 +224,7 @@ func iimportCommon(fset *token.FileSet, getPackages GetPackagesFunc, data []byte
|
||||||
|
|
||||||
// Gather the relevant packages from the manifest.
|
// Gather the relevant packages from the manifest.
|
||||||
items := make([]GetPackagesItem, r.uint64())
|
items := make([]GetPackagesItem, r.uint64())
|
||||||
|
uniquePkgPaths := make(map[string]bool)
|
||||||
for i := range items {
|
for i := range items {
|
||||||
pkgPathOff := r.uint64()
|
pkgPathOff := r.uint64()
|
||||||
pkgPath := p.stringAt(pkgPathOff)
|
pkgPath := p.stringAt(pkgPathOff)
|
||||||
|
@ -248,6 +249,12 @@ func iimportCommon(fset *token.FileSet, getPackages GetPackagesFunc, data []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
items[i].nameIndex = nameIndex
|
items[i].nameIndex = nameIndex
|
||||||
|
|
||||||
|
uniquePkgPaths[pkgPath] = true
|
||||||
|
}
|
||||||
|
// Debugging #63822; hypothesis: there are duplicate PkgPaths.
|
||||||
|
if len(uniquePkgPaths) != len(items) {
|
||||||
|
reportf("found duplicate PkgPaths while reading export data manifest: %v", items)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request packages all at once from the client,
|
// Request packages all at once from the client,
|
||||||
|
|
|
@ -9,11 +9,13 @@ package gopathwalk
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,8 +23,13 @@ import (
|
||||||
type Options struct {
|
type Options struct {
|
||||||
// If Logf is non-nil, debug logging is enabled through this function.
|
// If Logf is non-nil, debug logging is enabled through this function.
|
||||||
Logf func(format string, args ...interface{})
|
Logf func(format string, args ...interface{})
|
||||||
|
|
||||||
// Search module caches. Also disables legacy goimports ignore rules.
|
// Search module caches. Also disables legacy goimports ignore rules.
|
||||||
ModulesEnabled bool
|
ModulesEnabled bool
|
||||||
|
|
||||||
|
// Maximum number of concurrent calls to user-provided callbacks,
|
||||||
|
// or 0 for GOMAXPROCS.
|
||||||
|
Concurrency int
|
||||||
}
|
}
|
||||||
|
|
||||||
// RootType indicates the type of a Root.
|
// RootType indicates the type of a Root.
|
||||||
|
@ -43,19 +50,28 @@ type Root struct {
|
||||||
Type RootType
|
Type RootType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk walks Go source directories ($GOROOT, $GOPATH, etc) to find packages.
|
// Walk concurrently walks Go source directories ($GOROOT, $GOPATH, etc) to find packages.
|
||||||
|
//
|
||||||
// For each package found, add will be called with the absolute
|
// For each package found, add will be called with the absolute
|
||||||
// paths of the containing source directory and the package directory.
|
// paths of the containing source directory and the package directory.
|
||||||
|
//
|
||||||
|
// Unlike filepath.WalkDir, Walk follows symbolic links
|
||||||
|
// (while guarding against cycles).
|
||||||
func Walk(roots []Root, add func(root Root, dir string), opts Options) {
|
func Walk(roots []Root, add func(root Root, dir string), opts Options) {
|
||||||
WalkSkip(roots, add, func(Root, string) bool { return false }, opts)
|
WalkSkip(roots, add, func(Root, string) bool { return false }, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WalkSkip walks Go source directories ($GOROOT, $GOPATH, etc) to find packages.
|
// WalkSkip concurrently walks Go source directories ($GOROOT, $GOPATH, etc) to
|
||||||
|
// find packages.
|
||||||
|
//
|
||||||
// For each package found, add will be called with the absolute
|
// For each package found, add will be called with the absolute
|
||||||
// paths of the containing source directory and the package directory.
|
// paths of the containing source directory and the package directory.
|
||||||
// For each directory that will be scanned, skip will be called
|
// For each directory that will be scanned, skip will be called
|
||||||
// with the absolute paths of the containing source directory and the directory.
|
// with the absolute paths of the containing source directory and the directory.
|
||||||
// If skip returns false on a directory it will be processed.
|
// If skip returns false on a directory it will be processed.
|
||||||
|
//
|
||||||
|
// Unlike filepath.WalkDir, WalkSkip follows symbolic links
|
||||||
|
// (while guarding against cycles).
|
||||||
func WalkSkip(roots []Root, add func(root Root, dir string), skip func(root Root, dir string) bool, opts Options) {
|
func WalkSkip(roots []Root, add func(root Root, dir string), skip func(root Root, dir string) bool, opts Options) {
|
||||||
for _, root := range roots {
|
for _, root := range roots {
|
||||||
walkDir(root, add, skip, opts)
|
walkDir(root, add, skip, opts)
|
||||||
|
@ -64,45 +80,51 @@ func WalkSkip(roots []Root, add func(root Root, dir string), skip func(root Root
|
||||||
|
|
||||||
// walkDir creates a walker and starts fastwalk with this walker.
|
// walkDir creates a walker and starts fastwalk with this walker.
|
||||||
func walkDir(root Root, add func(Root, string), skip func(root Root, dir string) bool, opts Options) {
|
func walkDir(root Root, add func(Root, string), skip func(root Root, dir string) bool, opts Options) {
|
||||||
|
if opts.Logf == nil {
|
||||||
|
opts.Logf = func(format string, args ...interface{}) {}
|
||||||
|
}
|
||||||
if _, err := os.Stat(root.Path); os.IsNotExist(err) {
|
if _, err := os.Stat(root.Path); os.IsNotExist(err) {
|
||||||
if opts.Logf != nil {
|
opts.Logf("skipping nonexistent directory: %v", root.Path)
|
||||||
opts.Logf("skipping nonexistent directory: %v", root.Path)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
if opts.Logf != nil {
|
opts.Logf("scanning %s", root.Path)
|
||||||
opts.Logf("scanning %s", root.Path)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
concurrency := opts.Concurrency
|
||||||
|
if concurrency == 0 {
|
||||||
|
// The walk be either CPU-bound or I/O-bound, depending on what the
|
||||||
|
// caller-supplied add function does and the details of the user's platform
|
||||||
|
// and machine. Rather than trying to fine-tune the concurrency level for a
|
||||||
|
// specific environment, we default to GOMAXPROCS: it is likely to be a good
|
||||||
|
// choice for a CPU-bound add function, and if it is instead I/O-bound, then
|
||||||
|
// dealing with I/O saturation is arguably the job of the kernel and/or
|
||||||
|
// runtime. (Oversaturating I/O seems unlikely to harm performance as badly
|
||||||
|
// as failing to saturate would.)
|
||||||
|
concurrency = runtime.GOMAXPROCS(0)
|
||||||
|
}
|
||||||
w := &walker{
|
w := &walker{
|
||||||
root: root,
|
root: root,
|
||||||
add: add,
|
add: add,
|
||||||
skip: skip,
|
skip: skip,
|
||||||
opts: opts,
|
opts: opts,
|
||||||
added: make(map[string]bool),
|
sem: make(chan struct{}, concurrency),
|
||||||
}
|
}
|
||||||
w.init()
|
w.init()
|
||||||
|
|
||||||
// Add a trailing path separator to cause filepath.WalkDir to traverse symlinks.
|
w.sem <- struct{}{}
|
||||||
path := root.Path
|
path := root.Path
|
||||||
if len(path) == 0 {
|
if path == "" {
|
||||||
path = "." + string(filepath.Separator)
|
path = "."
|
||||||
} else if !os.IsPathSeparator(path[len(path)-1]) {
|
|
||||||
path = path + string(filepath.Separator)
|
|
||||||
}
|
}
|
||||||
|
if fi, err := os.Lstat(path); err == nil {
|
||||||
|
w.walk(path, nil, fs.FileInfoToDirEntry(fi))
|
||||||
|
} else {
|
||||||
|
w.opts.Logf("scanning directory %v: %v", root.Path, err)
|
||||||
|
}
|
||||||
|
<-w.sem
|
||||||
|
w.walking.Wait()
|
||||||
|
|
||||||
if err := filepath.WalkDir(path, w.walk); err != nil {
|
opts.Logf("scanned %s in %v", root.Path, time.Since(start))
|
||||||
logf := opts.Logf
|
|
||||||
if logf == nil {
|
|
||||||
logf = log.Printf
|
|
||||||
}
|
|
||||||
logf("scanning directory %v: %v", root.Path, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.Logf != nil {
|
|
||||||
opts.Logf("scanned %s in %v", root.Path, time.Since(start))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// walker is the callback for fastwalk.Walk.
|
// walker is the callback for fastwalk.Walk.
|
||||||
|
@ -112,10 +134,18 @@ type walker struct {
|
||||||
skip func(Root, string) bool // The callback that will be invoked for every dir. dir is skipped if it returns true.
|
skip func(Root, string) bool // The callback that will be invoked for every dir. dir is skipped if it returns true.
|
||||||
opts Options // Options passed to Walk by the user.
|
opts Options // Options passed to Walk by the user.
|
||||||
|
|
||||||
pathSymlinks []os.FileInfo
|
walking sync.WaitGroup
|
||||||
ignoredDirs []string
|
sem chan struct{} // Channel of semaphore tokens; send to acquire, receive to release.
|
||||||
|
ignoredDirs []string
|
||||||
|
|
||||||
added map[string]bool
|
added sync.Map // map[string]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// A symlinkList is a linked list of os.FileInfos for parent directories
|
||||||
|
// reached via symlinks.
|
||||||
|
type symlinkList struct {
|
||||||
|
info os.FileInfo
|
||||||
|
prev *symlinkList
|
||||||
}
|
}
|
||||||
|
|
||||||
// init initializes the walker based on its Options
|
// init initializes the walker based on its Options
|
||||||
|
@ -132,9 +162,7 @@ func (w *walker) init() {
|
||||||
for _, p := range ignoredPaths {
|
for _, p := range ignoredPaths {
|
||||||
full := filepath.Join(w.root.Path, p)
|
full := filepath.Join(w.root.Path, p)
|
||||||
w.ignoredDirs = append(w.ignoredDirs, full)
|
w.ignoredDirs = append(w.ignoredDirs, full)
|
||||||
if w.opts.Logf != nil {
|
w.opts.Logf("Directory added to ignore list: %s", full)
|
||||||
w.opts.Logf("Directory added to ignore list: %s", full)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,12 +172,10 @@ func (w *walker) init() {
|
||||||
func (w *walker) getIgnoredDirs(path string) []string {
|
func (w *walker) getIgnoredDirs(path string) []string {
|
||||||
file := filepath.Join(path, ".goimportsignore")
|
file := filepath.Join(path, ".goimportsignore")
|
||||||
slurp, err := os.ReadFile(file)
|
slurp, err := os.ReadFile(file)
|
||||||
if w.opts.Logf != nil {
|
if err != nil {
|
||||||
if err != nil {
|
w.opts.Logf("%v", err)
|
||||||
w.opts.Logf("%v", err)
|
} else {
|
||||||
} else {
|
w.opts.Logf("Read %s", file)
|
||||||
w.opts.Logf("Read %s", file)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -183,63 +209,22 @@ func (w *walker) shouldSkipDir(dir string) bool {
|
||||||
|
|
||||||
// walk walks through the given path.
|
// walk walks through the given path.
|
||||||
//
|
//
|
||||||
// Errors are logged if w.opts.Logf is non-nil, but otherwise ignored:
|
// Errors are logged if w.opts.Logf is non-nil, but otherwise ignored.
|
||||||
// walk returns only nil or fs.SkipDir.
|
func (w *walker) walk(path string, pathSymlinks *symlinkList, d fs.DirEntry) {
|
||||||
func (w *walker) walk(path string, d fs.DirEntry, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
// We have no way to report errors back through Walk or WalkSkip,
|
|
||||||
// so just log and ignore them.
|
|
||||||
if w.opts.Logf != nil {
|
|
||||||
w.opts.Logf("%v", err)
|
|
||||||
}
|
|
||||||
if d == nil {
|
|
||||||
// Nothing more to do: the error prevents us from knowing
|
|
||||||
// what path even represents.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if d.Type().IsRegular() {
|
|
||||||
if !strings.HasSuffix(path, ".go") {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
dir := filepath.Dir(path)
|
|
||||||
if dir == w.root.Path && (w.root.Type == RootGOROOT || w.root.Type == RootGOPATH) {
|
|
||||||
// Doesn't make sense to have regular files
|
|
||||||
// directly in your $GOPATH/src or $GOROOT/src.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if !w.added[dir] {
|
|
||||||
w.add(w.root, dir)
|
|
||||||
w.added[dir] = true
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if d.IsDir() {
|
|
||||||
base := filepath.Base(path)
|
|
||||||
if base == "" || base[0] == '.' || base[0] == '_' ||
|
|
||||||
base == "testdata" ||
|
|
||||||
(w.root.Type == RootGOROOT && w.opts.ModulesEnabled && base == "vendor") ||
|
|
||||||
(!w.opts.ModulesEnabled && base == "node_modules") {
|
|
||||||
return fs.SkipDir
|
|
||||||
}
|
|
||||||
if w.shouldSkipDir(path) {
|
|
||||||
return fs.SkipDir
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if d.Type()&os.ModeSymlink != 0 {
|
if d.Type()&os.ModeSymlink != 0 {
|
||||||
|
// Walk the symlink's target rather than the symlink itself.
|
||||||
|
//
|
||||||
|
// (Note that os.Stat, unlike the lower-lever os.Readlink,
|
||||||
|
// follows arbitrarily many layers of symlinks, so it will eventually
|
||||||
|
// reach either a non-symlink or a nonexistent target.)
|
||||||
|
//
|
||||||
// TODO(bcmills): 'go list all' itself ignores symlinks within GOROOT/src
|
// TODO(bcmills): 'go list all' itself ignores symlinks within GOROOT/src
|
||||||
// and GOPATH/src. Do we really need to traverse them here? If so, why?
|
// and GOPATH/src. Do we really need to traverse them here? If so, why?
|
||||||
|
|
||||||
fi, err := os.Stat(path)
|
fi, err := os.Stat(path)
|
||||||
if err != nil || !fi.IsDir() {
|
if err != nil {
|
||||||
// Not a directory. Just walk the file (or broken link) and be done.
|
w.opts.Logf("%v", err)
|
||||||
return w.walk(path, fs.FileInfoToDirEntry(fi), err)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid walking symlink cycles: if we have already followed a symlink to
|
// Avoid walking symlink cycles: if we have already followed a symlink to
|
||||||
|
@ -249,83 +234,104 @@ func (w *walker) walk(path string, d fs.DirEntry, err error) error {
|
||||||
// the number of extra stat calls we make if we *don't* encounter a cycle.
|
// the number of extra stat calls we make if we *don't* encounter a cycle.
|
||||||
// Since we don't actually expect to encounter symlink cycles in practice,
|
// Since we don't actually expect to encounter symlink cycles in practice,
|
||||||
// this seems like the right tradeoff.
|
// this seems like the right tradeoff.
|
||||||
for _, parent := range w.pathSymlinks {
|
for parent := pathSymlinks; parent != nil; parent = parent.prev {
|
||||||
if os.SameFile(fi, parent) {
|
if os.SameFile(fi, parent.info) {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.pathSymlinks = append(w.pathSymlinks, fi)
|
pathSymlinks = &symlinkList{
|
||||||
defer func() {
|
info: fi,
|
||||||
w.pathSymlinks = w.pathSymlinks[:len(w.pathSymlinks)-1]
|
prev: pathSymlinks,
|
||||||
}()
|
}
|
||||||
|
d = fs.FileInfoToDirEntry(fi)
|
||||||
|
}
|
||||||
|
|
||||||
// On some platforms the OS (or the Go os package) sometimes fails to
|
if d.Type().IsRegular() {
|
||||||
// resolve directory symlinks before a trailing slash
|
if !strings.HasSuffix(path, ".go") {
|
||||||
// (even though POSIX requires it to do so).
|
return
|
||||||
//
|
|
||||||
// On macOS that failure may be caused by a known libc/kernel bug;
|
|
||||||
// see https://go.dev/issue/59586.
|
|
||||||
//
|
|
||||||
// On Windows before Go 1.21, it may be caused by a bug in
|
|
||||||
// os.Lstat (fixed in https://go.dev/cl/463177).
|
|
||||||
//
|
|
||||||
// Since we need to handle this explicitly on broken platforms anyway,
|
|
||||||
// it is simplest to just always do that and not rely on POSIX pathname
|
|
||||||
// resolution to walk the directory (such as by calling WalkDir with
|
|
||||||
// a trailing slash appended to the path).
|
|
||||||
//
|
|
||||||
// Instead, we make a sequence of walk calls — directly and through
|
|
||||||
// recursive calls to filepath.WalkDir — simulating what WalkDir would do
|
|
||||||
// if the symlink were a regular directory.
|
|
||||||
|
|
||||||
// First we call walk on the path as a directory
|
|
||||||
// (instead of a symlink).
|
|
||||||
err = w.walk(path, fs.FileInfoToDirEntry(fi), nil)
|
|
||||||
if err == fs.SkipDir {
|
|
||||||
return nil
|
|
||||||
} else if err != nil {
|
|
||||||
// This should be impossible, but handle it anyway in case
|
|
||||||
// walk is changed to return other errors.
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now read the directory and walk its entries.
|
dir := filepath.Dir(path)
|
||||||
ents, err := os.ReadDir(path)
|
if dir == w.root.Path && (w.root.Type == RootGOROOT || w.root.Type == RootGOPATH) {
|
||||||
|
// Doesn't make sense to have regular files
|
||||||
|
// directly in your $GOPATH/src or $GOROOT/src.
|
||||||
|
//
|
||||||
|
// TODO(bcmills): there are many levels of directory within
|
||||||
|
// RootModuleCache where this also wouldn't make sense,
|
||||||
|
// Can we generalize this to any directory without a corresponding
|
||||||
|
// import path?
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, dup := w.added.LoadOrStore(dir, true); !dup {
|
||||||
|
w.add(w.root, dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !d.IsDir() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
base := filepath.Base(path)
|
||||||
|
if base == "" || base[0] == '.' || base[0] == '_' ||
|
||||||
|
base == "testdata" ||
|
||||||
|
(w.root.Type == RootGOROOT && w.opts.ModulesEnabled && base == "vendor") ||
|
||||||
|
(!w.opts.ModulesEnabled && base == "node_modules") ||
|
||||||
|
w.shouldSkipDir(path) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the directory and walk its entries.
|
||||||
|
|
||||||
|
f, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
w.opts.Logf("%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
for {
|
||||||
|
// We impose an arbitrary limit on the number of ReadDir results per
|
||||||
|
// directory to limit the amount of memory consumed for stale or upcoming
|
||||||
|
// directory entries. The limit trades off CPU (number of syscalls to read
|
||||||
|
// the whole directory) against RAM (reachable directory entries other than
|
||||||
|
// the one currently being processed).
|
||||||
|
//
|
||||||
|
// Since we process the directories recursively, we will end up maintaining
|
||||||
|
// a slice of entries for each level of the directory tree.
|
||||||
|
// (Compare https://go.dev/issue/36197.)
|
||||||
|
ents, err := f.ReadDir(1024)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Report the ReadDir error, as filepath.WalkDir would do.
|
if err != io.EOF {
|
||||||
err = w.walk(path, fs.FileInfoToDirEntry(fi), err)
|
w.opts.Logf("%v", err)
|
||||||
if err == fs.SkipDir {
|
|
||||||
return nil
|
|
||||||
} else if err != nil {
|
|
||||||
return err // Again, should be impossible.
|
|
||||||
}
|
}
|
||||||
// Fall through and iterate over whatever entries we did manage to get.
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range ents {
|
for _, d := range ents {
|
||||||
nextPath := filepath.Join(path, d.Name())
|
nextPath := filepath.Join(path, d.Name())
|
||||||
if d.IsDir() {
|
if d.IsDir() {
|
||||||
// We want to walk the whole directory tree rooted at nextPath,
|
select {
|
||||||
// not just the single entry for the directory.
|
case w.sem <- struct{}{}:
|
||||||
err := filepath.WalkDir(nextPath, w.walk)
|
// Got a new semaphore token, so we can traverse the directory concurrently.
|
||||||
if err != nil && w.opts.Logf != nil {
|
d := d
|
||||||
w.opts.Logf("%v", err)
|
w.walking.Add(1)
|
||||||
}
|
go func() {
|
||||||
} else {
|
defer func() {
|
||||||
err := w.walk(nextPath, d, nil)
|
<-w.sem
|
||||||
if err == fs.SkipDir {
|
w.walking.Done()
|
||||||
// Skip the rest of the entries in the parent directory of nextPath
|
}()
|
||||||
// (that is, path itself).
|
w.walk(nextPath, pathSymlinks, d)
|
||||||
break
|
}()
|
||||||
} else if err != nil {
|
continue
|
||||||
return err // Again, should be impossible.
|
|
||||||
|
default:
|
||||||
|
// No tokens available, so traverse serially.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not a file, regular directory, or symlink; skip.
|
w.walk(nextPath, pathSymlinks, d)
|
||||||
return nil
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"go/build"
|
"go/build"
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
|
"go/types"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -700,20 +701,21 @@ func ScoreImportPaths(ctx context.Context, env *ProcessEnv, paths []string) (map
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrimeCache(ctx context.Context, env *ProcessEnv) error {
|
func PrimeCache(ctx context.Context, resolver Resolver) error {
|
||||||
// Fully scan the disk for directories, but don't actually read any Go files.
|
// Fully scan the disk for directories, but don't actually read any Go files.
|
||||||
callback := &scanCallback{
|
callback := &scanCallback{
|
||||||
rootFound: func(gopathwalk.Root) bool {
|
rootFound: func(root gopathwalk.Root) bool {
|
||||||
return true
|
// See getCandidatePkgs: walking GOROOT is apparently expensive and
|
||||||
|
// unnecessary.
|
||||||
|
return root.Type != gopathwalk.RootGOROOT
|
||||||
},
|
},
|
||||||
dirFound: func(pkg *pkg) bool {
|
dirFound: func(pkg *pkg) bool {
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
packageNameLoaded: func(pkg *pkg) bool {
|
// packageNameLoaded and exportsLoaded must never be called.
|
||||||
return false
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
return getCandidatePkgs(ctx, callback, "", "", env)
|
|
||||||
|
return resolver.scan(ctx, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func candidateImportName(pkg *pkg) string {
|
func candidateImportName(pkg *pkg) string {
|
||||||
|
@ -827,16 +829,45 @@ func GetPackageExports(ctx context.Context, wrapped func(PackageExport), searchP
|
||||||
return getCandidatePkgs(ctx, callback, filename, filePkg, env)
|
return getCandidatePkgs(ctx, callback, filename, filePkg, env)
|
||||||
}
|
}
|
||||||
|
|
||||||
var requiredGoEnvVars = []string{"GO111MODULE", "GOFLAGS", "GOINSECURE", "GOMOD", "GOMODCACHE", "GONOPROXY", "GONOSUMDB", "GOPATH", "GOPROXY", "GOROOT", "GOSUMDB", "GOWORK"}
|
// TODO(rfindley): we should depend on GOOS and GOARCH, to provide accurate
|
||||||
|
// imports when doing cross-platform development.
|
||||||
|
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
|
// ProcessEnv contains environment variables and settings that affect the use of
|
||||||
// the go command, the go/build package, etc.
|
// the go command, the go/build package, etc.
|
||||||
|
//
|
||||||
|
// ...a ProcessEnv *also* overwrites its Env along with derived state in the
|
||||||
|
// form of the resolver. And because it is lazily initialized, an env may just
|
||||||
|
// be broken and unusable, but there is no way for the caller to detect that:
|
||||||
|
// all queries will just fail.
|
||||||
|
//
|
||||||
|
// TODO(rfindley): refactor this package so that this type (perhaps renamed to
|
||||||
|
// just Env or Config) is an immutable configuration struct, to be exchanged
|
||||||
|
// for an initialized object via a constructor that returns an error. Perhaps
|
||||||
|
// the signature should be `func NewResolver(*Env) (*Resolver, error)`, where
|
||||||
|
// resolver is a concrete type used for resolving imports. Via this
|
||||||
|
// refactoring, we can avoid the need to call ProcessEnv.init and
|
||||||
|
// ProcessEnv.GoEnv everywhere, and implicitly fix all the places where this
|
||||||
|
// these are misused. Also, we'd delegate the caller the decision of how to
|
||||||
|
// handle a broken environment.
|
||||||
type ProcessEnv struct {
|
type ProcessEnv struct {
|
||||||
GocmdRunner *gocommand.Runner
|
GocmdRunner *gocommand.Runner
|
||||||
|
|
||||||
BuildFlags []string
|
BuildFlags []string
|
||||||
ModFlag string
|
ModFlag string
|
||||||
ModFile string
|
|
||||||
|
|
||||||
// SkipPathInScan returns true if the path should be skipped from scans of
|
// SkipPathInScan returns true if the path should be skipped from scans of
|
||||||
// the RootCurrentModule root type. The function argument is a clean,
|
// the RootCurrentModule root type. The function argument is a clean,
|
||||||
|
@ -846,7 +877,7 @@ type ProcessEnv struct {
|
||||||
// Env overrides the OS environment, and can be used to specify
|
// Env overrides the OS environment, and can be used to specify
|
||||||
// GOPROXY, GO111MODULE, etc. PATH cannot be set here, because
|
// GOPROXY, GO111MODULE, etc. PATH cannot be set here, because
|
||||||
// exec.Command will not honor it.
|
// exec.Command will not honor it.
|
||||||
// Specifying all of RequiredGoEnvVars avoids a call to `go env`.
|
// Specifying all of requiredGoEnvVars avoids a call to `go env`.
|
||||||
Env map[string]string
|
Env map[string]string
|
||||||
|
|
||||||
WorkingDir string
|
WorkingDir string
|
||||||
|
@ -854,9 +885,17 @@ type ProcessEnv struct {
|
||||||
// If Logf is non-nil, debug logging is enabled through this function.
|
// If Logf is non-nil, debug logging is enabled through this function.
|
||||||
Logf func(format string, args ...interface{})
|
Logf func(format string, args ...interface{})
|
||||||
|
|
||||||
initialized bool
|
// If set, ModCache holds a shared cache of directory info to use across
|
||||||
|
// multiple ProcessEnvs.
|
||||||
|
ModCache *DirInfoCache
|
||||||
|
|
||||||
resolver Resolver
|
initialized bool // see TODO above
|
||||||
|
|
||||||
|
// resolver and resolverErr are lazily evaluated (see GetResolver).
|
||||||
|
// This is unclean, but see the big TODO in the docstring for ProcessEnv
|
||||||
|
// above: for now, we can't be sure that the ProcessEnv is fully initialized.
|
||||||
|
resolver Resolver
|
||||||
|
resolverErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ProcessEnv) goEnv() (map[string]string, error) {
|
func (e *ProcessEnv) goEnv() (map[string]string, error) {
|
||||||
|
@ -936,20 +975,31 @@ func (e *ProcessEnv) env() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ProcessEnv) GetResolver() (Resolver, error) {
|
func (e *ProcessEnv) GetResolver() (Resolver, error) {
|
||||||
if e.resolver != nil {
|
|
||||||
return e.resolver, nil
|
|
||||||
}
|
|
||||||
if err := e.init(); err != nil {
|
if err := e.init(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(e.Env["GOMOD"]) == 0 && len(e.Env["GOWORK"]) == 0 {
|
|
||||||
e.resolver = newGopathResolver(e)
|
if e.resolver == nil && e.resolverErr == nil {
|
||||||
return e.resolver, nil
|
// TODO(rfindley): we should only use a gopathResolver here if the working
|
||||||
|
// directory is actually *in* GOPATH. (I seem to recall an open gopls issue
|
||||||
|
// for this behavior, but I can't find it).
|
||||||
|
//
|
||||||
|
// For gopls, we can optionally explicitly choose a resolver type, since we
|
||||||
|
// already know the view type.
|
||||||
|
if len(e.Env["GOMOD"]) == 0 && len(e.Env["GOWORK"]) == 0 {
|
||||||
|
e.resolver = newGopathResolver(e)
|
||||||
|
} else {
|
||||||
|
e.resolver, e.resolverErr = newModuleResolver(e, e.ModCache)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
e.resolver = newModuleResolver(e)
|
|
||||||
return e.resolver, nil
|
return e.resolver, e.resolverErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// buildContext returns the build.Context to use for matching files.
|
||||||
|
//
|
||||||
|
// TODO(rfindley): support dynamic GOOS, GOARCH here, when doing cross-platform
|
||||||
|
// development.
|
||||||
func (e *ProcessEnv) buildContext() (*build.Context, error) {
|
func (e *ProcessEnv) buildContext() (*build.Context, error) {
|
||||||
ctx := build.Default
|
ctx := build.Default
|
||||||
goenv, err := e.goEnv()
|
goenv, err := e.goEnv()
|
||||||
|
@ -1029,15 +1079,23 @@ func addStdlibCandidates(pass *pass, refs references) error {
|
||||||
type Resolver interface {
|
type Resolver interface {
|
||||||
// loadPackageNames loads the package names in importPaths.
|
// loadPackageNames loads the package names in importPaths.
|
||||||
loadPackageNames(importPaths []string, srcDir string) (map[string]string, error)
|
loadPackageNames(importPaths []string, srcDir string) (map[string]string, error)
|
||||||
|
|
||||||
// scan works with callback to search for packages. See scanCallback for details.
|
// scan works with callback to search for packages. See scanCallback for details.
|
||||||
scan(ctx context.Context, callback *scanCallback) error
|
scan(ctx context.Context, callback *scanCallback) error
|
||||||
|
|
||||||
// loadExports returns the set of exported symbols in the package at dir.
|
// loadExports returns the set of exported symbols in the package at dir.
|
||||||
// loadExports may be called concurrently.
|
// loadExports may be called concurrently.
|
||||||
loadExports(ctx context.Context, pkg *pkg, includeTest bool) (string, []string, error)
|
loadExports(ctx context.Context, pkg *pkg, includeTest bool) (string, []string, error)
|
||||||
|
|
||||||
// scoreImportPath returns the relevance for an import path.
|
// scoreImportPath returns the relevance for an import path.
|
||||||
scoreImportPath(ctx context.Context, path string) float64
|
scoreImportPath(ctx context.Context, path string) float64
|
||||||
|
|
||||||
ClearForNewScan()
|
// ClearForNewScan returns a new Resolver based on the receiver that has
|
||||||
|
// cleared its internal caches of directory contents.
|
||||||
|
//
|
||||||
|
// The new resolver should be primed and then set via
|
||||||
|
// [ProcessEnv.UpdateResolver].
|
||||||
|
ClearForNewScan() Resolver
|
||||||
}
|
}
|
||||||
|
|
||||||
// A scanCallback controls a call to scan and receives its results.
|
// A scanCallback controls a call to scan and receives its results.
|
||||||
|
@ -1120,7 +1178,7 @@ func addExternalCandidates(ctx context.Context, pass *pass, refs references, fil
|
||||||
go func(pkgName string, symbols map[string]bool) {
|
go func(pkgName string, symbols map[string]bool) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
found, err := findImport(ctx, pass, found[pkgName], pkgName, symbols, filename)
|
found, err := findImport(ctx, pass, found[pkgName], pkgName, symbols)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
firstErrOnce.Do(func() {
|
firstErrOnce.Do(func() {
|
||||||
|
@ -1151,6 +1209,17 @@ func addExternalCandidates(ctx context.Context, pass *pass, refs references, fil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for result := range results {
|
for result := range results {
|
||||||
|
// Don't offer completions that would shadow predeclared
|
||||||
|
// names, such as github.com/coreos/etcd/error.
|
||||||
|
if types.Universe.Lookup(result.pkg.name) != nil { // predeclared
|
||||||
|
// Ideally we would skip this candidate only
|
||||||
|
// if the predeclared name is actually
|
||||||
|
// referenced by the file, but that's a lot
|
||||||
|
// trickier to compute and would still create
|
||||||
|
// an import that is likely to surprise the
|
||||||
|
// user before long.
|
||||||
|
continue
|
||||||
|
}
|
||||||
pass.addCandidate(result.imp, result.pkg)
|
pass.addCandidate(result.imp, result.pkg)
|
||||||
}
|
}
|
||||||
return firstErr
|
return firstErr
|
||||||
|
@ -1193,31 +1262,22 @@ func ImportPathToAssumedName(importPath string) string {
|
||||||
type gopathResolver struct {
|
type gopathResolver struct {
|
||||||
env *ProcessEnv
|
env *ProcessEnv
|
||||||
walked bool
|
walked bool
|
||||||
cache *dirInfoCache
|
cache *DirInfoCache
|
||||||
scanSema chan struct{} // scanSema prevents concurrent scans.
|
scanSema chan struct{} // scanSema prevents concurrent scans.
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGopathResolver(env *ProcessEnv) *gopathResolver {
|
func newGopathResolver(env *ProcessEnv) *gopathResolver {
|
||||||
r := &gopathResolver{
|
r := &gopathResolver{
|
||||||
env: env,
|
env: env,
|
||||||
cache: &dirInfoCache{
|
cache: NewDirInfoCache(),
|
||||||
dirs: map[string]*directoryPackageInfo{},
|
|
||||||
listeners: map[*int]cacheListener{},
|
|
||||||
},
|
|
||||||
scanSema: make(chan struct{}, 1),
|
scanSema: make(chan struct{}, 1),
|
||||||
}
|
}
|
||||||
r.scanSema <- struct{}{}
|
r.scanSema <- struct{}{}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *gopathResolver) ClearForNewScan() {
|
func (r *gopathResolver) ClearForNewScan() Resolver {
|
||||||
<-r.scanSema
|
return newGopathResolver(r.env)
|
||||||
r.cache = &dirInfoCache{
|
|
||||||
dirs: map[string]*directoryPackageInfo{},
|
|
||||||
listeners: map[*int]cacheListener{},
|
|
||||||
}
|
|
||||||
r.walked = false
|
|
||||||
r.scanSema <- struct{}{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *gopathResolver) loadPackageNames(importPaths []string, srcDir string) (map[string]string, error) {
|
func (r *gopathResolver) loadPackageNames(importPaths []string, srcDir string) (map[string]string, error) {
|
||||||
|
@ -1538,7 +1598,7 @@ func loadExportsFromFiles(ctx context.Context, env *ProcessEnv, dir string, incl
|
||||||
|
|
||||||
// findImport searches for a package with the given symbols.
|
// findImport searches for a package with the given symbols.
|
||||||
// If no package is found, findImport returns ("", false, nil)
|
// If no package is found, findImport returns ("", false, nil)
|
||||||
func findImport(ctx context.Context, pass *pass, candidates []pkgDistance, pkgName string, symbols map[string]bool, filename string) (*pkg, error) {
|
func findImport(ctx context.Context, pass *pass, candidates []pkgDistance, pkgName string, symbols map[string]bool) (*pkg, error) {
|
||||||
// Sort the candidates by their import package length,
|
// Sort the candidates by their import package length,
|
||||||
// assuming that shorter package names are better than long
|
// assuming that shorter package names are better than long
|
||||||
// ones. Note that this sorts by the de-vendored name, so
|
// ones. Note that this sorts by the de-vendored name, so
|
||||||
|
|
|
@ -236,7 +236,7 @@ func parse(fset *token.FileSet, filename string, src []byte, opt *Options) (*ast
|
||||||
src = src[:len(src)-len("}\n")]
|
src = src[:len(src)-len("}\n")]
|
||||||
// Gofmt has also indented the function body one level.
|
// Gofmt has also indented the function body one level.
|
||||||
// Remove that indent.
|
// Remove that indent.
|
||||||
src = bytes.Replace(src, []byte("\n\t"), []byte("\n"), -1)
|
src = bytes.ReplaceAll(src, []byte("\n\t"), []byte("\n"))
|
||||||
return matchSpace(orig, src)
|
return matchSpace(orig, src)
|
||||||
}
|
}
|
||||||
return file, adjust, nil
|
return file, adjust, nil
|
||||||
|
|
|
@ -23,49 +23,88 @@ import (
|
||||||
"golang.org/x/tools/internal/gopathwalk"
|
"golang.org/x/tools/internal/gopathwalk"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ModuleResolver implements resolver for modules using the go command as little
|
// Notes(rfindley): ModuleResolver appears to be heavily optimized for scanning
|
||||||
// as feasible.
|
// as fast as possible, which is desirable for a call to goimports from the
|
||||||
|
// command line, but it doesn't work as well for gopls, where it suffers from
|
||||||
|
// slow startup (golang/go#44863) and intermittent hanging (golang/go#59216),
|
||||||
|
// both caused by populating the cache, albeit in slightly different ways.
|
||||||
|
//
|
||||||
|
// A high level list of TODOs:
|
||||||
|
// - Optimize the scan itself, as there is some redundancy statting and
|
||||||
|
// reading go.mod files.
|
||||||
|
// - Invert the relationship between ProcessEnv and Resolver (see the
|
||||||
|
// docstring of ProcessEnv).
|
||||||
|
// - Make it easier to use an external resolver implementation.
|
||||||
|
//
|
||||||
|
// Smaller TODOs are annotated in the code below.
|
||||||
|
|
||||||
|
// ModuleResolver implements the Resolver interface for a workspace using
|
||||||
|
// modules.
|
||||||
|
//
|
||||||
|
// A goal of the ModuleResolver is to invoke the Go command as little as
|
||||||
|
// possible. To this end, it runs the Go command only for listing module
|
||||||
|
// information (i.e. `go list -m -e -json ...`). Package scanning, the process
|
||||||
|
// of loading package information for the modules, is implemented internally
|
||||||
|
// via the scan method.
|
||||||
|
//
|
||||||
|
// It has two types of state: the state derived from the go command, which
|
||||||
|
// is populated by init, and the state derived from scans, which is populated
|
||||||
|
// via scan. A root is considered scanned if it has been walked to discover
|
||||||
|
// directories. However, if the scan did not require additional information
|
||||||
|
// from the directory (such as package name or exports), the directory
|
||||||
|
// information itself may be partially populated. It will be lazily filled in
|
||||||
|
// as needed by scans, using the scanCallback.
|
||||||
type ModuleResolver struct {
|
type ModuleResolver struct {
|
||||||
env *ProcessEnv
|
env *ProcessEnv
|
||||||
moduleCacheDir string
|
|
||||||
dummyVendorMod *gocommand.ModuleJSON // If vendoring is enabled, the pseudo-module that represents the /vendor directory.
|
|
||||||
roots []gopathwalk.Root
|
|
||||||
scanSema chan struct{} // scanSema prevents concurrent scans and guards scannedRoots.
|
|
||||||
scannedRoots map[gopathwalk.Root]bool
|
|
||||||
|
|
||||||
initialized bool
|
// Module state, populated during construction
|
||||||
mains []*gocommand.ModuleJSON
|
dummyVendorMod *gocommand.ModuleJSON // if vendoring is enabled, a pseudo-module to represent the /vendor directory
|
||||||
mainByDir map[string]*gocommand.ModuleJSON
|
moduleCacheDir string // GOMODCACHE, inferred from GOPATH if unset
|
||||||
modsByModPath []*gocommand.ModuleJSON // All modules, ordered by # of path components in module Path...
|
roots []gopathwalk.Root // roots to scan, in approximate order of importance
|
||||||
modsByDir []*gocommand.ModuleJSON // ...or number of path components in their Dir.
|
mains []*gocommand.ModuleJSON // main modules
|
||||||
|
mainByDir map[string]*gocommand.ModuleJSON // module information by dir, to join with roots
|
||||||
|
modsByModPath []*gocommand.ModuleJSON // all modules, ordered by # of path components in their module path
|
||||||
|
modsByDir []*gocommand.ModuleJSON // ...or by the number of path components in their Dir.
|
||||||
|
|
||||||
// moduleCacheCache stores information about the module cache.
|
// Scanning state, populated by scan
|
||||||
moduleCacheCache *dirInfoCache
|
|
||||||
otherCache *dirInfoCache
|
// scanSema prevents concurrent scans, and guards scannedRoots and the cache
|
||||||
|
// fields below (though the caches themselves are concurrency safe).
|
||||||
|
// Receive to acquire, send to release.
|
||||||
|
scanSema chan struct{}
|
||||||
|
scannedRoots map[gopathwalk.Root]bool // if true, root has been walked
|
||||||
|
|
||||||
|
// Caches of directory info, populated by scans and scan callbacks
|
||||||
|
//
|
||||||
|
// moduleCacheCache stores cached information about roots in the module
|
||||||
|
// cache, which are immutable and therefore do not need to be invalidated.
|
||||||
|
//
|
||||||
|
// otherCache stores information about all other roots (even GOROOT), which
|
||||||
|
// may change.
|
||||||
|
moduleCacheCache *DirInfoCache
|
||||||
|
otherCache *DirInfoCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func newModuleResolver(e *ProcessEnv) *ModuleResolver {
|
// newModuleResolver returns a new module-aware goimports resolver.
|
||||||
|
//
|
||||||
|
// Note: use caution when modifying this constructor: changes must also be
|
||||||
|
// reflected in ModuleResolver.ClearForNewScan.
|
||||||
|
func newModuleResolver(e *ProcessEnv, moduleCacheCache *DirInfoCache) (*ModuleResolver, error) {
|
||||||
r := &ModuleResolver{
|
r := &ModuleResolver{
|
||||||
env: e,
|
env: e,
|
||||||
scanSema: make(chan struct{}, 1),
|
scanSema: make(chan struct{}, 1),
|
||||||
}
|
}
|
||||||
r.scanSema <- struct{}{}
|
r.scanSema <- struct{}{} // release
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *ModuleResolver) init() error {
|
|
||||||
if r.initialized {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
goenv, err := r.env.goEnv()
|
goenv, err := r.env.goEnv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(rfindley): can we refactor to share logic with r.env.invokeGo?
|
||||||
inv := gocommand.Invocation{
|
inv := gocommand.Invocation{
|
||||||
BuildFlags: r.env.BuildFlags,
|
BuildFlags: r.env.BuildFlags,
|
||||||
ModFlag: r.env.ModFlag,
|
ModFlag: r.env.ModFlag,
|
||||||
ModFile: r.env.ModFile,
|
|
||||||
Env: r.env.env(),
|
Env: r.env.env(),
|
||||||
Logf: r.env.Logf,
|
Logf: r.env.Logf,
|
||||||
WorkingDir: r.env.WorkingDir,
|
WorkingDir: r.env.WorkingDir,
|
||||||
|
@ -77,9 +116,12 @@ func (r *ModuleResolver) init() error {
|
||||||
// Module vendor directories are ignored in workspace mode:
|
// Module vendor directories are ignored in workspace mode:
|
||||||
// https://go.googlesource.com/proposal/+/master/design/45713-workspace.md
|
// https://go.googlesource.com/proposal/+/master/design/45713-workspace.md
|
||||||
if len(r.env.Env["GOWORK"]) == 0 {
|
if len(r.env.Env["GOWORK"]) == 0 {
|
||||||
|
// TODO(rfindley): VendorEnabled runs the go command to get GOFLAGS, but
|
||||||
|
// they should be available from the ProcessEnv. Can we avoid the redundant
|
||||||
|
// invocation?
|
||||||
vendorEnabled, mainModVendor, err = gocommand.VendorEnabled(context.TODO(), inv, r.env.GocmdRunner)
|
vendorEnabled, mainModVendor, err = gocommand.VendorEnabled(context.TODO(), inv, r.env.GocmdRunner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,19 +142,14 @@ func (r *ModuleResolver) init() error {
|
||||||
// GO111MODULE=on. Other errors are fatal.
|
// GO111MODULE=on. Other errors are fatal.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errMsg := err.Error(); !strings.Contains(errMsg, "working directory is not part of a module") && !strings.Contains(errMsg, "go.mod file not found") {
|
if errMsg := err.Error(); !strings.Contains(errMsg, "working directory is not part of a module") && !strings.Contains(errMsg, "go.mod file not found") {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if gmc := r.env.Env["GOMODCACHE"]; gmc != "" {
|
r.moduleCacheDir = gomodcacheForEnv(goenv)
|
||||||
r.moduleCacheDir = gmc
|
if r.moduleCacheDir == "" {
|
||||||
} else {
|
return nil, fmt.Errorf("cannot resolve GOMODCACHE")
|
||||||
gopaths := filepath.SplitList(goenv["GOPATH"])
|
|
||||||
if len(gopaths) == 0 {
|
|
||||||
return fmt.Errorf("empty GOPATH")
|
|
||||||
}
|
|
||||||
r.moduleCacheDir = filepath.Join(gopaths[0], "/pkg/mod")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(r.modsByModPath, func(i, j int) bool {
|
sort.Slice(r.modsByModPath, func(i, j int) bool {
|
||||||
|
@ -141,7 +178,11 @@ func (r *ModuleResolver) init() error {
|
||||||
} else {
|
} else {
|
||||||
addDep := func(mod *gocommand.ModuleJSON) {
|
addDep := func(mod *gocommand.ModuleJSON) {
|
||||||
if mod.Replace == nil {
|
if mod.Replace == nil {
|
||||||
// This is redundant with the cache, but we'll skip it cheaply enough.
|
// This is redundant with the cache, but we'll skip it cheaply enough
|
||||||
|
// when we encounter it in the module cache scan.
|
||||||
|
//
|
||||||
|
// Including it at a lower index in r.roots than the module cache dir
|
||||||
|
// helps prioritize matches from within existing dependencies.
|
||||||
r.roots = append(r.roots, gopathwalk.Root{Path: mod.Dir, Type: gopathwalk.RootModuleCache})
|
r.roots = append(r.roots, gopathwalk.Root{Path: mod.Dir, Type: gopathwalk.RootModuleCache})
|
||||||
} else {
|
} else {
|
||||||
r.roots = append(r.roots, gopathwalk.Root{Path: mod.Dir, Type: gopathwalk.RootOther})
|
r.roots = append(r.roots, gopathwalk.Root{Path: mod.Dir, Type: gopathwalk.RootOther})
|
||||||
|
@ -158,24 +199,40 @@ func (r *ModuleResolver) init() error {
|
||||||
addDep(mod)
|
addDep(mod)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If provided, share the moduleCacheCache.
|
||||||
|
//
|
||||||
|
// TODO(rfindley): The module cache is immutable. However, the loaded
|
||||||
|
// exports do depend on GOOS and GOARCH. Fortunately, the
|
||||||
|
// ProcessEnv.buildContext does not adjust these from build.DefaultContext
|
||||||
|
// (even though it should). So for now, this is OK to share, but we need to
|
||||||
|
// add logic for handling GOOS/GOARCH.
|
||||||
|
r.moduleCacheCache = moduleCacheCache
|
||||||
r.roots = append(r.roots, gopathwalk.Root{Path: r.moduleCacheDir, Type: gopathwalk.RootModuleCache})
|
r.roots = append(r.roots, gopathwalk.Root{Path: r.moduleCacheDir, Type: gopathwalk.RootModuleCache})
|
||||||
}
|
}
|
||||||
|
|
||||||
r.scannedRoots = map[gopathwalk.Root]bool{}
|
r.scannedRoots = map[gopathwalk.Root]bool{}
|
||||||
if r.moduleCacheCache == nil {
|
if r.moduleCacheCache == nil {
|
||||||
r.moduleCacheCache = &dirInfoCache{
|
r.moduleCacheCache = NewDirInfoCache()
|
||||||
dirs: map[string]*directoryPackageInfo{},
|
|
||||||
listeners: map[*int]cacheListener{},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if r.otherCache == nil {
|
r.otherCache = NewDirInfoCache()
|
||||||
r.otherCache = &dirInfoCache{
|
return r, nil
|
||||||
dirs: map[string]*directoryPackageInfo{},
|
}
|
||||||
listeners: map[*int]cacheListener{},
|
|
||||||
}
|
// gomodcacheForEnv returns the GOMODCACHE value to use based on the given env
|
||||||
|
// map, which must have GOMODCACHE and GOPATH populated.
|
||||||
|
//
|
||||||
|
// TODO(rfindley): this is defensive refactoring.
|
||||||
|
// 1. Is this even relevant anymore? Can't we just read GOMODCACHE.
|
||||||
|
// 2. Use this to separate module cache scanning from other scanning.
|
||||||
|
func gomodcacheForEnv(goenv map[string]string) string {
|
||||||
|
if gmc := goenv["GOMODCACHE"]; gmc != "" {
|
||||||
|
return gmc
|
||||||
}
|
}
|
||||||
r.initialized = true
|
gopaths := filepath.SplitList(goenv["GOPATH"])
|
||||||
return nil
|
if len(gopaths) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return filepath.Join(gopaths[0], "/pkg/mod")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ModuleResolver) initAllMods() error {
|
func (r *ModuleResolver) initAllMods() error {
|
||||||
|
@ -206,30 +263,82 @@ func (r *ModuleResolver) initAllMods() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ModuleResolver) ClearForNewScan() {
|
// ClearForNewScan invalidates the last scan.
|
||||||
<-r.scanSema
|
//
|
||||||
r.scannedRoots = map[gopathwalk.Root]bool{}
|
// It preserves the set of roots, but forgets about the set of directories.
|
||||||
r.otherCache = &dirInfoCache{
|
// Though it forgets the set of module cache directories, it remembers their
|
||||||
dirs: map[string]*directoryPackageInfo{},
|
// contents, since they are assumed to be immutable.
|
||||||
listeners: map[*int]cacheListener{},
|
func (r *ModuleResolver) ClearForNewScan() Resolver {
|
||||||
}
|
<-r.scanSema // acquire r, to guard scannedRoots
|
||||||
r.scanSema <- struct{}{}
|
r2 := &ModuleResolver{
|
||||||
}
|
env: r.env,
|
||||||
|
dummyVendorMod: r.dummyVendorMod,
|
||||||
|
moduleCacheDir: r.moduleCacheDir,
|
||||||
|
roots: r.roots,
|
||||||
|
mains: r.mains,
|
||||||
|
mainByDir: r.mainByDir,
|
||||||
|
modsByModPath: r.modsByModPath,
|
||||||
|
|
||||||
func (r *ModuleResolver) ClearForNewMod() {
|
scanSema: make(chan struct{}, 1),
|
||||||
<-r.scanSema
|
scannedRoots: make(map[gopathwalk.Root]bool),
|
||||||
*r = ModuleResolver{
|
otherCache: NewDirInfoCache(),
|
||||||
env: r.env,
|
|
||||||
moduleCacheCache: r.moduleCacheCache,
|
moduleCacheCache: r.moduleCacheCache,
|
||||||
otherCache: r.otherCache,
|
|
||||||
scanSema: r.scanSema,
|
|
||||||
}
|
}
|
||||||
r.init()
|
r2.scanSema <- struct{}{} // r2 must start released
|
||||||
r.scanSema <- struct{}{}
|
// Invalidate root scans. We don't need to invalidate module cache roots,
|
||||||
|
// because they are immutable.
|
||||||
|
// (We don't support a use case where GOMODCACHE is cleaned in the middle of
|
||||||
|
// e.g. a gopls session: the user must restart gopls to get accurate
|
||||||
|
// imports.)
|
||||||
|
//
|
||||||
|
// Scanning for new directories in GOMODCACHE should be handled elsewhere,
|
||||||
|
// via a call to ScanModuleCache.
|
||||||
|
for _, root := range r.roots {
|
||||||
|
if root.Type == gopathwalk.RootModuleCache && r.scannedRoots[root] {
|
||||||
|
r2.scannedRoots[root] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r.scanSema <- struct{}{} // release r
|
||||||
|
return r2
|
||||||
}
|
}
|
||||||
|
|
||||||
// findPackage returns the module and directory that contains the package at
|
// ClearModuleInfo invalidates resolver state that depends on go.mod file
|
||||||
// the given import path, or returns nil, "" if no module is in scope.
|
// contents (essentially, the output of go list -m -json ...).
|
||||||
|
//
|
||||||
|
// Notably, it does not forget directory contents, which are reset
|
||||||
|
// asynchronously via ClearForNewScan.
|
||||||
|
//
|
||||||
|
// If the ProcessEnv is a GOPATH environment, ClearModuleInfo is a no op.
|
||||||
|
//
|
||||||
|
// TODO(rfindley): move this to a new env.go, consolidating ProcessEnv methods.
|
||||||
|
func (e *ProcessEnv) ClearModuleInfo() {
|
||||||
|
if r, ok := e.resolver.(*ModuleResolver); ok {
|
||||||
|
resolver, resolverErr := newModuleResolver(e, e.ModCache)
|
||||||
|
if resolverErr == nil {
|
||||||
|
<-r.scanSema // acquire (guards caches)
|
||||||
|
resolver.moduleCacheCache = r.moduleCacheCache
|
||||||
|
resolver.otherCache = r.otherCache
|
||||||
|
r.scanSema <- struct{}{} // release
|
||||||
|
}
|
||||||
|
e.resolver = resolver
|
||||||
|
e.resolverErr = resolverErr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateResolver sets the resolver for the ProcessEnv to use in imports
|
||||||
|
// operations. Only for use with the result of [Resolver.ClearForNewScan].
|
||||||
|
//
|
||||||
|
// TODO(rfindley): this awkward API is a result of the (arguably) inverted
|
||||||
|
// relationship between configuration and state described in the doc comment
|
||||||
|
// for [ProcessEnv].
|
||||||
|
func (e *ProcessEnv) UpdateResolver(r Resolver) {
|
||||||
|
e.resolver = r
|
||||||
|
e.resolverErr = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// findPackage returns the module and directory from within the main modules
|
||||||
|
// and their dependencies that contains the package at the given import path,
|
||||||
|
// or returns nil, "" if no module is in scope.
|
||||||
func (r *ModuleResolver) findPackage(importPath string) (*gocommand.ModuleJSON, string) {
|
func (r *ModuleResolver) findPackage(importPath string) (*gocommand.ModuleJSON, string) {
|
||||||
// This can't find packages in the stdlib, but that's harmless for all
|
// This can't find packages in the stdlib, but that's harmless for all
|
||||||
// the existing code paths.
|
// the existing code paths.
|
||||||
|
@ -295,10 +404,6 @@ func (r *ModuleResolver) cacheStore(info directoryPackageInfo) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ModuleResolver) cacheKeys() []string {
|
|
||||||
return append(r.moduleCacheCache.Keys(), r.otherCache.Keys()...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// cachePackageName caches the package name for a dir already in the cache.
|
// cachePackageName caches the package name for a dir already in the cache.
|
||||||
func (r *ModuleResolver) cachePackageName(info directoryPackageInfo) (string, error) {
|
func (r *ModuleResolver) cachePackageName(info directoryPackageInfo) (string, error) {
|
||||||
if info.rootType == gopathwalk.RootModuleCache {
|
if info.rootType == gopathwalk.RootModuleCache {
|
||||||
|
@ -367,15 +472,15 @@ func (r *ModuleResolver) dirIsNestedModule(dir string, mod *gocommand.ModuleJSON
|
||||||
return modDir != mod.Dir
|
return modDir != mod.Dir
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ModuleResolver) modInfo(dir string) (modDir string, modName string) {
|
func readModName(modFile string) string {
|
||||||
readModName := func(modFile string) string {
|
modBytes, err := os.ReadFile(modFile)
|
||||||
modBytes, err := os.ReadFile(modFile)
|
if err != nil {
|
||||||
if err != nil {
|
return ""
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return modulePath(modBytes)
|
|
||||||
}
|
}
|
||||||
|
return modulePath(modBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ModuleResolver) modInfo(dir string) (modDir, modName string) {
|
||||||
if r.dirInModuleCache(dir) {
|
if r.dirInModuleCache(dir) {
|
||||||
if matches := modCacheRegexp.FindStringSubmatch(dir); len(matches) == 3 {
|
if matches := modCacheRegexp.FindStringSubmatch(dir); len(matches) == 3 {
|
||||||
index := strings.Index(dir, matches[1]+"@"+matches[2])
|
index := strings.Index(dir, matches[1]+"@"+matches[2])
|
||||||
|
@ -409,11 +514,9 @@ func (r *ModuleResolver) dirInModuleCache(dir string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ModuleResolver) loadPackageNames(importPaths []string, srcDir string) (map[string]string, error) {
|
func (r *ModuleResolver) loadPackageNames(importPaths []string, srcDir string) (map[string]string, error) {
|
||||||
if err := r.init(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
names := map[string]string{}
|
names := map[string]string{}
|
||||||
for _, path := range importPaths {
|
for _, path := range importPaths {
|
||||||
|
// TODO(rfindley): shouldn't this use the dirInfoCache?
|
||||||
_, packageDir := r.findPackage(path)
|
_, packageDir := r.findPackage(path)
|
||||||
if packageDir == "" {
|
if packageDir == "" {
|
||||||
continue
|
continue
|
||||||
|
@ -431,10 +534,6 @@ func (r *ModuleResolver) scan(ctx context.Context, callback *scanCallback) error
|
||||||
ctx, done := event.Start(ctx, "imports.ModuleResolver.scan")
|
ctx, done := event.Start(ctx, "imports.ModuleResolver.scan")
|
||||||
defer done()
|
defer done()
|
||||||
|
|
||||||
if err := r.init(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
processDir := func(info directoryPackageInfo) {
|
processDir := func(info directoryPackageInfo) {
|
||||||
// Skip this directory if we were not able to get the package information successfully.
|
// Skip this directory if we were not able to get the package information successfully.
|
||||||
if scanned, err := info.reachedStatus(directoryScanned); !scanned || err != nil {
|
if scanned, err := info.reachedStatus(directoryScanned); !scanned || err != nil {
|
||||||
|
@ -444,18 +543,18 @@ func (r *ModuleResolver) scan(ctx context.Context, callback *scanCallback) error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !callback.dirFound(pkg) {
|
if !callback.dirFound(pkg) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg.packageName, err = r.cachePackageName(info)
|
pkg.packageName, err = r.cachePackageName(info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !callback.packageNameLoaded(pkg) {
|
if !callback.packageNameLoaded(pkg) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, exports, err := r.loadExports(ctx, pkg, false)
|
_, exports, err := r.loadExports(ctx, pkg, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -494,7 +593,6 @@ func (r *ModuleResolver) scan(ctx context.Context, callback *scanCallback) error
|
||||||
return packageScanned
|
return packageScanned
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add anything new to the cache, and process it if we're still listening.
|
|
||||||
add := func(root gopathwalk.Root, dir string) {
|
add := func(root gopathwalk.Root, dir string) {
|
||||||
r.cacheStore(r.scanDirForPackage(root, dir))
|
r.cacheStore(r.scanDirForPackage(root, dir))
|
||||||
}
|
}
|
||||||
|
@ -509,9 +607,9 @@ func (r *ModuleResolver) scan(ctx context.Context, callback *scanCallback) error
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case <-r.scanSema:
|
case <-r.scanSema: // acquire
|
||||||
}
|
}
|
||||||
defer func() { r.scanSema <- struct{}{} }()
|
defer func() { r.scanSema <- struct{}{} }() // release
|
||||||
// We have the lock on r.scannedRoots, and no other scans can run.
|
// We have the lock on r.scannedRoots, and no other scans can run.
|
||||||
for _, root := range roots {
|
for _, root := range roots {
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
|
@ -613,9 +711,6 @@ func (r *ModuleResolver) canonicalize(info directoryPackageInfo) (*pkg, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ModuleResolver) loadExports(ctx context.Context, pkg *pkg, includeTest bool) (string, []string, error) {
|
func (r *ModuleResolver) loadExports(ctx context.Context, pkg *pkg, includeTest bool) (string, []string, error) {
|
||||||
if err := r.init(); err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
if info, ok := r.cacheLoad(pkg.dir); ok && !includeTest {
|
if info, ok := r.cacheLoad(pkg.dir); ok && !includeTest {
|
||||||
return r.cacheExports(ctx, r.env, info)
|
return r.cacheExports(ctx, r.env, info)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,12 @@ package imports
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"golang.org/x/mod/module"
|
||||||
"golang.org/x/tools/internal/gopathwalk"
|
"golang.org/x/tools/internal/gopathwalk"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -39,6 +43,8 @@ const (
|
||||||
exportsLoaded
|
exportsLoaded
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// directoryPackageInfo holds (possibly incomplete) information about packages
|
||||||
|
// contained in a given directory.
|
||||||
type directoryPackageInfo struct {
|
type directoryPackageInfo struct {
|
||||||
// status indicates the extent to which this struct has been filled in.
|
// status indicates the extent to which this struct has been filled in.
|
||||||
status directoryPackageStatus
|
status directoryPackageStatus
|
||||||
|
@ -63,7 +69,10 @@ type directoryPackageInfo struct {
|
||||||
packageName string // the package name, as declared in the source.
|
packageName string // the package name, as declared in the source.
|
||||||
|
|
||||||
// Set when status >= exportsLoaded.
|
// Set when status >= exportsLoaded.
|
||||||
|
// TODO(rfindley): it's hard to see this, but exports depend implicitly on
|
||||||
|
// the default build context GOOS and GOARCH.
|
||||||
|
//
|
||||||
|
// We can make this explicit, and key exports by GOOS, GOARCH.
|
||||||
exports []string
|
exports []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +88,7 @@ func (info *directoryPackageInfo) reachedStatus(target directoryPackageStatus) (
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// dirInfoCache is a concurrency safe map for storing information about
|
// DirInfoCache is a concurrency-safe map for storing information about
|
||||||
// directories that may contain packages.
|
// directories that may contain packages.
|
||||||
//
|
//
|
||||||
// The information in this cache is built incrementally. Entries are initialized in scan.
|
// The information in this cache is built incrementally. Entries are initialized in scan.
|
||||||
|
@ -92,21 +101,26 @@ func (info *directoryPackageInfo) reachedStatus(target directoryPackageStatus) (
|
||||||
// The information in the cache is not expected to change for the cache's
|
// The information in the cache is not expected to change for the cache's
|
||||||
// lifetime, so there is no protection against competing writes. Users should
|
// lifetime, so there is no protection against competing writes. Users should
|
||||||
// take care not to hold the cache across changes to the underlying files.
|
// take care not to hold the cache across changes to the underlying files.
|
||||||
//
|
type DirInfoCache struct {
|
||||||
// TODO(suzmue): consider other concurrency strategies and data structures (RWLocks, sync.Map, etc)
|
|
||||||
type dirInfoCache struct {
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
// dirs stores information about packages in directories, keyed by absolute path.
|
// dirs stores information about packages in directories, keyed by absolute path.
|
||||||
dirs map[string]*directoryPackageInfo
|
dirs map[string]*directoryPackageInfo
|
||||||
listeners map[*int]cacheListener
|
listeners map[*int]cacheListener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewDirInfoCache() *DirInfoCache {
|
||||||
|
return &DirInfoCache{
|
||||||
|
dirs: make(map[string]*directoryPackageInfo),
|
||||||
|
listeners: make(map[*int]cacheListener),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type cacheListener func(directoryPackageInfo)
|
type cacheListener func(directoryPackageInfo)
|
||||||
|
|
||||||
// ScanAndListen calls listener on all the items in the cache, and on anything
|
// ScanAndListen calls listener on all the items in the cache, and on anything
|
||||||
// newly added. The returned stop function waits for all in-flight callbacks to
|
// newly added. The returned stop function waits for all in-flight callbacks to
|
||||||
// finish and blocks new ones.
|
// finish and blocks new ones.
|
||||||
func (d *dirInfoCache) ScanAndListen(ctx context.Context, listener cacheListener) func() {
|
func (d *DirInfoCache) ScanAndListen(ctx context.Context, listener cacheListener) func() {
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
|
||||||
// Flushing out all the callbacks is tricky without knowing how many there
|
// Flushing out all the callbacks is tricky without knowing how many there
|
||||||
|
@ -162,8 +176,10 @@ func (d *dirInfoCache) ScanAndListen(ctx context.Context, listener cacheListener
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store stores the package info for dir.
|
// Store stores the package info for dir.
|
||||||
func (d *dirInfoCache) Store(dir string, info directoryPackageInfo) {
|
func (d *DirInfoCache) Store(dir string, info directoryPackageInfo) {
|
||||||
d.mu.Lock()
|
d.mu.Lock()
|
||||||
|
// TODO(rfindley, golang/go#59216): should we overwrite an existing entry?
|
||||||
|
// That seems incorrect as the cache should be idempotent.
|
||||||
_, old := d.dirs[dir]
|
_, old := d.dirs[dir]
|
||||||
d.dirs[dir] = &info
|
d.dirs[dir] = &info
|
||||||
var listeners []cacheListener
|
var listeners []cacheListener
|
||||||
|
@ -180,7 +196,7 @@ func (d *dirInfoCache) Store(dir string, info directoryPackageInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load returns a copy of the directoryPackageInfo for absolute directory dir.
|
// Load returns a copy of the directoryPackageInfo for absolute directory dir.
|
||||||
func (d *dirInfoCache) Load(dir string) (directoryPackageInfo, bool) {
|
func (d *DirInfoCache) Load(dir string) (directoryPackageInfo, bool) {
|
||||||
d.mu.Lock()
|
d.mu.Lock()
|
||||||
defer d.mu.Unlock()
|
defer d.mu.Unlock()
|
||||||
info, ok := d.dirs[dir]
|
info, ok := d.dirs[dir]
|
||||||
|
@ -191,7 +207,7 @@ func (d *dirInfoCache) Load(dir string) (directoryPackageInfo, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keys returns the keys currently present in d.
|
// Keys returns the keys currently present in d.
|
||||||
func (d *dirInfoCache) Keys() (keys []string) {
|
func (d *DirInfoCache) Keys() (keys []string) {
|
||||||
d.mu.Lock()
|
d.mu.Lock()
|
||||||
defer d.mu.Unlock()
|
defer d.mu.Unlock()
|
||||||
for key := range d.dirs {
|
for key := range d.dirs {
|
||||||
|
@ -200,7 +216,7 @@ func (d *dirInfoCache) Keys() (keys []string) {
|
||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dirInfoCache) CachePackageName(info directoryPackageInfo) (string, error) {
|
func (d *DirInfoCache) CachePackageName(info directoryPackageInfo) (string, error) {
|
||||||
if loaded, err := info.reachedStatus(nameLoaded); loaded {
|
if loaded, err := info.reachedStatus(nameLoaded); loaded {
|
||||||
return info.packageName, err
|
return info.packageName, err
|
||||||
}
|
}
|
||||||
|
@ -213,7 +229,7 @@ func (d *dirInfoCache) CachePackageName(info directoryPackageInfo) (string, erro
|
||||||
return info.packageName, info.err
|
return info.packageName, info.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dirInfoCache) CacheExports(ctx context.Context, env *ProcessEnv, info directoryPackageInfo) (string, []string, error) {
|
func (d *DirInfoCache) CacheExports(ctx context.Context, env *ProcessEnv, info directoryPackageInfo) (string, []string, error) {
|
||||||
if reached, _ := info.reachedStatus(exportsLoaded); reached {
|
if reached, _ := info.reachedStatus(exportsLoaded); reached {
|
||||||
return info.packageName, info.exports, info.err
|
return info.packageName, info.exports, info.err
|
||||||
}
|
}
|
||||||
|
@ -234,3 +250,81 @@ func (d *dirInfoCache) CacheExports(ctx context.Context, env *ProcessEnv, info d
|
||||||
d.Store(info.dir, info)
|
d.Store(info.dir, info)
|
||||||
return info.packageName, info.exports, info.err
|
return info.packageName, info.exports, info.err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ScanModuleCache walks the given directory, which must be a GOMODCACHE value,
|
||||||
|
// for directory package information, storing the results in cache.
|
||||||
|
func ScanModuleCache(dir string, cache *DirInfoCache, logf func(string, ...any)) {
|
||||||
|
// Note(rfindley): it's hard to see, but this function attempts to implement
|
||||||
|
// just the side effects on cache of calling PrimeCache with a ProcessEnv
|
||||||
|
// that has the given dir as its GOMODCACHE.
|
||||||
|
//
|
||||||
|
// Teasing out the control flow, we see that we can avoid any handling of
|
||||||
|
// vendor/ and can infer module info entirely from the path, simplifying the
|
||||||
|
// logic here.
|
||||||
|
|
||||||
|
root := gopathwalk.Root{
|
||||||
|
Path: filepath.Clean(dir),
|
||||||
|
Type: gopathwalk.RootModuleCache,
|
||||||
|
}
|
||||||
|
|
||||||
|
directoryInfo := func(root gopathwalk.Root, dir string) directoryPackageInfo {
|
||||||
|
// This is a copy of ModuleResolver.scanDirForPackage, trimmed down to
|
||||||
|
// logic that applies to a module cache directory.
|
||||||
|
|
||||||
|
subdir := ""
|
||||||
|
if dir != root.Path {
|
||||||
|
subdir = dir[len(root.Path)+len("/"):]
|
||||||
|
}
|
||||||
|
|
||||||
|
matches := modCacheRegexp.FindStringSubmatch(subdir)
|
||||||
|
if len(matches) == 0 {
|
||||||
|
return directoryPackageInfo{
|
||||||
|
status: directoryScanned,
|
||||||
|
err: fmt.Errorf("invalid module cache path: %v", subdir),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modPath, err := module.UnescapePath(filepath.ToSlash(matches[1]))
|
||||||
|
if err != nil {
|
||||||
|
if logf != nil {
|
||||||
|
logf("decoding module cache path %q: %v", subdir, err)
|
||||||
|
}
|
||||||
|
return directoryPackageInfo{
|
||||||
|
status: directoryScanned,
|
||||||
|
err: fmt.Errorf("decoding module cache path %q: %v", subdir, err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
importPath := path.Join(modPath, filepath.ToSlash(matches[3]))
|
||||||
|
index := strings.Index(dir, matches[1]+"@"+matches[2])
|
||||||
|
modDir := filepath.Join(dir[:index], matches[1]+"@"+matches[2])
|
||||||
|
modName := readModName(filepath.Join(modDir, "go.mod"))
|
||||||
|
return directoryPackageInfo{
|
||||||
|
status: directoryScanned,
|
||||||
|
dir: dir,
|
||||||
|
rootType: root.Type,
|
||||||
|
nonCanonicalImportPath: importPath,
|
||||||
|
moduleDir: modDir,
|
||||||
|
moduleName: modName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
add := func(root gopathwalk.Root, dir string) {
|
||||||
|
info := directoryInfo(root, dir)
|
||||||
|
cache.Store(info.dir, info)
|
||||||
|
}
|
||||||
|
|
||||||
|
skip := func(_ gopathwalk.Root, dir string) bool {
|
||||||
|
// Skip directories that have already been scanned.
|
||||||
|
//
|
||||||
|
// Note that gopathwalk only adds "package" directories, which must contain
|
||||||
|
// a .go file, and all such package directories in the module cache are
|
||||||
|
// immutable. So if we can load a dir, it can be skipped.
|
||||||
|
info, ok := cache.Load(dir)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
packageScanned, _ := info.reachedStatus(directoryScanned)
|
||||||
|
return packageScanned
|
||||||
|
}
|
||||||
|
|
||||||
|
gopathwalk.WalkSkip([]gopathwalk.Root{root}, add, skip, gopathwalk.Options{Logf: logf, ModulesEnabled: true})
|
||||||
|
}
|
||||||
|
|
|
@ -151,6 +151,7 @@ var stdlib = map[string][]string{
|
||||||
"cmp": {
|
"cmp": {
|
||||||
"Compare",
|
"Compare",
|
||||||
"Less",
|
"Less",
|
||||||
|
"Or",
|
||||||
"Ordered",
|
"Ordered",
|
||||||
},
|
},
|
||||||
"compress/bzip2": {
|
"compress/bzip2": {
|
||||||
|
@ -632,6 +633,8 @@ var stdlib = map[string][]string{
|
||||||
"NameMismatch",
|
"NameMismatch",
|
||||||
"NewCertPool",
|
"NewCertPool",
|
||||||
"NotAuthorizedToSign",
|
"NotAuthorizedToSign",
|
||||||
|
"OID",
|
||||||
|
"OIDFromInts",
|
||||||
"PEMCipher",
|
"PEMCipher",
|
||||||
"PEMCipher3DES",
|
"PEMCipher3DES",
|
||||||
"PEMCipherAES128",
|
"PEMCipherAES128",
|
||||||
|
@ -706,6 +709,7 @@ var stdlib = map[string][]string{
|
||||||
"LevelWriteCommitted",
|
"LevelWriteCommitted",
|
||||||
"Named",
|
"Named",
|
||||||
"NamedArg",
|
"NamedArg",
|
||||||
|
"Null",
|
||||||
"NullBool",
|
"NullBool",
|
||||||
"NullByte",
|
"NullByte",
|
||||||
"NullFloat64",
|
"NullFloat64",
|
||||||
|
@ -1921,6 +1925,7 @@ var stdlib = map[string][]string{
|
||||||
"R_LARCH_32",
|
"R_LARCH_32",
|
||||||
"R_LARCH_32_PCREL",
|
"R_LARCH_32_PCREL",
|
||||||
"R_LARCH_64",
|
"R_LARCH_64",
|
||||||
|
"R_LARCH_64_PCREL",
|
||||||
"R_LARCH_ABS64_HI12",
|
"R_LARCH_ABS64_HI12",
|
||||||
"R_LARCH_ABS64_LO20",
|
"R_LARCH_ABS64_LO20",
|
||||||
"R_LARCH_ABS_HI20",
|
"R_LARCH_ABS_HI20",
|
||||||
|
@ -1928,12 +1933,17 @@ var stdlib = map[string][]string{
|
||||||
"R_LARCH_ADD16",
|
"R_LARCH_ADD16",
|
||||||
"R_LARCH_ADD24",
|
"R_LARCH_ADD24",
|
||||||
"R_LARCH_ADD32",
|
"R_LARCH_ADD32",
|
||||||
|
"R_LARCH_ADD6",
|
||||||
"R_LARCH_ADD64",
|
"R_LARCH_ADD64",
|
||||||
"R_LARCH_ADD8",
|
"R_LARCH_ADD8",
|
||||||
|
"R_LARCH_ADD_ULEB128",
|
||||||
|
"R_LARCH_ALIGN",
|
||||||
"R_LARCH_B16",
|
"R_LARCH_B16",
|
||||||
"R_LARCH_B21",
|
"R_LARCH_B21",
|
||||||
"R_LARCH_B26",
|
"R_LARCH_B26",
|
||||||
|
"R_LARCH_CFA",
|
||||||
"R_LARCH_COPY",
|
"R_LARCH_COPY",
|
||||||
|
"R_LARCH_DELETE",
|
||||||
"R_LARCH_GNU_VTENTRY",
|
"R_LARCH_GNU_VTENTRY",
|
||||||
"R_LARCH_GNU_VTINHERIT",
|
"R_LARCH_GNU_VTINHERIT",
|
||||||
"R_LARCH_GOT64_HI12",
|
"R_LARCH_GOT64_HI12",
|
||||||
|
@ -1953,6 +1963,7 @@ var stdlib = map[string][]string{
|
||||||
"R_LARCH_PCALA64_LO20",
|
"R_LARCH_PCALA64_LO20",
|
||||||
"R_LARCH_PCALA_HI20",
|
"R_LARCH_PCALA_HI20",
|
||||||
"R_LARCH_PCALA_LO12",
|
"R_LARCH_PCALA_LO12",
|
||||||
|
"R_LARCH_PCREL20_S2",
|
||||||
"R_LARCH_RELATIVE",
|
"R_LARCH_RELATIVE",
|
||||||
"R_LARCH_RELAX",
|
"R_LARCH_RELAX",
|
||||||
"R_LARCH_SOP_ADD",
|
"R_LARCH_SOP_ADD",
|
||||||
|
@ -1983,8 +1994,10 @@ var stdlib = map[string][]string{
|
||||||
"R_LARCH_SUB16",
|
"R_LARCH_SUB16",
|
||||||
"R_LARCH_SUB24",
|
"R_LARCH_SUB24",
|
||||||
"R_LARCH_SUB32",
|
"R_LARCH_SUB32",
|
||||||
|
"R_LARCH_SUB6",
|
||||||
"R_LARCH_SUB64",
|
"R_LARCH_SUB64",
|
||||||
"R_LARCH_SUB8",
|
"R_LARCH_SUB8",
|
||||||
|
"R_LARCH_SUB_ULEB128",
|
||||||
"R_LARCH_TLS_DTPMOD32",
|
"R_LARCH_TLS_DTPMOD32",
|
||||||
"R_LARCH_TLS_DTPMOD64",
|
"R_LARCH_TLS_DTPMOD64",
|
||||||
"R_LARCH_TLS_DTPREL32",
|
"R_LARCH_TLS_DTPREL32",
|
||||||
|
@ -2035,6 +2048,7 @@ var stdlib = map[string][]string{
|
||||||
"R_MIPS_LO16",
|
"R_MIPS_LO16",
|
||||||
"R_MIPS_NONE",
|
"R_MIPS_NONE",
|
||||||
"R_MIPS_PC16",
|
"R_MIPS_PC16",
|
||||||
|
"R_MIPS_PC32",
|
||||||
"R_MIPS_PJUMP",
|
"R_MIPS_PJUMP",
|
||||||
"R_MIPS_REL16",
|
"R_MIPS_REL16",
|
||||||
"R_MIPS_REL32",
|
"R_MIPS_REL32",
|
||||||
|
@ -2952,6 +2966,8 @@ var stdlib = map[string][]string{
|
||||||
"RegisterName",
|
"RegisterName",
|
||||||
},
|
},
|
||||||
"encoding/hex": {
|
"encoding/hex": {
|
||||||
|
"AppendDecode",
|
||||||
|
"AppendEncode",
|
||||||
"Decode",
|
"Decode",
|
||||||
"DecodeString",
|
"DecodeString",
|
||||||
"DecodedLen",
|
"DecodedLen",
|
||||||
|
@ -3233,6 +3249,7 @@ var stdlib = map[string][]string{
|
||||||
"TypeSpec",
|
"TypeSpec",
|
||||||
"TypeSwitchStmt",
|
"TypeSwitchStmt",
|
||||||
"UnaryExpr",
|
"UnaryExpr",
|
||||||
|
"Unparen",
|
||||||
"ValueSpec",
|
"ValueSpec",
|
||||||
"Var",
|
"Var",
|
||||||
"Visitor",
|
"Visitor",
|
||||||
|
@ -3492,6 +3509,7 @@ var stdlib = map[string][]string{
|
||||||
"XOR_ASSIGN",
|
"XOR_ASSIGN",
|
||||||
},
|
},
|
||||||
"go/types": {
|
"go/types": {
|
||||||
|
"Alias",
|
||||||
"ArgumentError",
|
"ArgumentError",
|
||||||
"Array",
|
"Array",
|
||||||
"AssertableTo",
|
"AssertableTo",
|
||||||
|
@ -3559,6 +3577,7 @@ var stdlib = map[string][]string{
|
||||||
"MethodVal",
|
"MethodVal",
|
||||||
"MissingMethod",
|
"MissingMethod",
|
||||||
"Named",
|
"Named",
|
||||||
|
"NewAlias",
|
||||||
"NewArray",
|
"NewArray",
|
||||||
"NewChan",
|
"NewChan",
|
||||||
"NewChecker",
|
"NewChecker",
|
||||||
|
@ -3627,6 +3646,7 @@ var stdlib = map[string][]string{
|
||||||
"Uint64",
|
"Uint64",
|
||||||
"Uint8",
|
"Uint8",
|
||||||
"Uintptr",
|
"Uintptr",
|
||||||
|
"Unalias",
|
||||||
"Union",
|
"Union",
|
||||||
"Universe",
|
"Universe",
|
||||||
"Unsafe",
|
"Unsafe",
|
||||||
|
@ -3643,6 +3663,11 @@ var stdlib = map[string][]string{
|
||||||
"WriteSignature",
|
"WriteSignature",
|
||||||
"WriteType",
|
"WriteType",
|
||||||
},
|
},
|
||||||
|
"go/version": {
|
||||||
|
"Compare",
|
||||||
|
"IsValid",
|
||||||
|
"Lang",
|
||||||
|
},
|
||||||
"hash": {
|
"hash": {
|
||||||
"Hash",
|
"Hash",
|
||||||
"Hash32",
|
"Hash32",
|
||||||
|
@ -4078,6 +4103,7 @@ var stdlib = map[string][]string{
|
||||||
"NewTextHandler",
|
"NewTextHandler",
|
||||||
"Record",
|
"Record",
|
||||||
"SetDefault",
|
"SetDefault",
|
||||||
|
"SetLogLoggerLevel",
|
||||||
"Source",
|
"Source",
|
||||||
"SourceKey",
|
"SourceKey",
|
||||||
"String",
|
"String",
|
||||||
|
@ -4367,6 +4393,35 @@ var stdlib = map[string][]string{
|
||||||
"Uint64",
|
"Uint64",
|
||||||
"Zipf",
|
"Zipf",
|
||||||
},
|
},
|
||||||
|
"math/rand/v2": {
|
||||||
|
"ChaCha8",
|
||||||
|
"ExpFloat64",
|
||||||
|
"Float32",
|
||||||
|
"Float64",
|
||||||
|
"Int",
|
||||||
|
"Int32",
|
||||||
|
"Int32N",
|
||||||
|
"Int64",
|
||||||
|
"Int64N",
|
||||||
|
"IntN",
|
||||||
|
"N",
|
||||||
|
"New",
|
||||||
|
"NewChaCha8",
|
||||||
|
"NewPCG",
|
||||||
|
"NewZipf",
|
||||||
|
"NormFloat64",
|
||||||
|
"PCG",
|
||||||
|
"Perm",
|
||||||
|
"Rand",
|
||||||
|
"Shuffle",
|
||||||
|
"Source",
|
||||||
|
"Uint32",
|
||||||
|
"Uint32N",
|
||||||
|
"Uint64",
|
||||||
|
"Uint64N",
|
||||||
|
"UintN",
|
||||||
|
"Zipf",
|
||||||
|
},
|
||||||
"mime": {
|
"mime": {
|
||||||
"AddExtensionType",
|
"AddExtensionType",
|
||||||
"BEncoding",
|
"BEncoding",
|
||||||
|
@ -4540,6 +4595,7 @@ var stdlib = map[string][]string{
|
||||||
"FS",
|
"FS",
|
||||||
"File",
|
"File",
|
||||||
"FileServer",
|
"FileServer",
|
||||||
|
"FileServerFS",
|
||||||
"FileSystem",
|
"FileSystem",
|
||||||
"Flusher",
|
"Flusher",
|
||||||
"Get",
|
"Get",
|
||||||
|
@ -4566,6 +4622,7 @@ var stdlib = map[string][]string{
|
||||||
"MethodPut",
|
"MethodPut",
|
||||||
"MethodTrace",
|
"MethodTrace",
|
||||||
"NewFileTransport",
|
"NewFileTransport",
|
||||||
|
"NewFileTransportFS",
|
||||||
"NewRequest",
|
"NewRequest",
|
||||||
"NewRequestWithContext",
|
"NewRequestWithContext",
|
||||||
"NewResponseController",
|
"NewResponseController",
|
||||||
|
@ -4599,6 +4656,7 @@ var stdlib = map[string][]string{
|
||||||
"Serve",
|
"Serve",
|
||||||
"ServeContent",
|
"ServeContent",
|
||||||
"ServeFile",
|
"ServeFile",
|
||||||
|
"ServeFileFS",
|
||||||
"ServeMux",
|
"ServeMux",
|
||||||
"ServeTLS",
|
"ServeTLS",
|
||||||
"Server",
|
"Server",
|
||||||
|
@ -5106,6 +5164,7 @@ var stdlib = map[string][]string{
|
||||||
"StructTag",
|
"StructTag",
|
||||||
"Swapper",
|
"Swapper",
|
||||||
"Type",
|
"Type",
|
||||||
|
"TypeFor",
|
||||||
"TypeOf",
|
"TypeOf",
|
||||||
"Uint",
|
"Uint",
|
||||||
"Uint16",
|
"Uint16",
|
||||||
|
@ -5342,6 +5401,7 @@ var stdlib = map[string][]string{
|
||||||
"CompactFunc",
|
"CompactFunc",
|
||||||
"Compare",
|
"Compare",
|
||||||
"CompareFunc",
|
"CompareFunc",
|
||||||
|
"Concat",
|
||||||
"Contains",
|
"Contains",
|
||||||
"ContainsFunc",
|
"ContainsFunc",
|
||||||
"Delete",
|
"Delete",
|
||||||
|
@ -10824,6 +10884,7 @@ var stdlib = map[string][]string{
|
||||||
"Value",
|
"Value",
|
||||||
},
|
},
|
||||||
"testing/slogtest": {
|
"testing/slogtest": {
|
||||||
|
"Run",
|
||||||
"TestHandler",
|
"TestHandler",
|
||||||
},
|
},
|
||||||
"text/scanner": {
|
"text/scanner": {
|
||||||
|
|
|
@ -362,7 +362,7 @@ golang.org/x/crypto/openpgp/elgamal
|
||||||
golang.org/x/crypto/openpgp/errors
|
golang.org/x/crypto/openpgp/errors
|
||||||
golang.org/x/crypto/openpgp/packet
|
golang.org/x/crypto/openpgp/packet
|
||||||
golang.org/x/crypto/openpgp/s2k
|
golang.org/x/crypto/openpgp/s2k
|
||||||
# golang.org/x/mod v0.14.0
|
# golang.org/x/mod v0.15.0
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
golang.org/x/mod/internal/lazyregexp
|
golang.org/x/mod/internal/lazyregexp
|
||||||
golang.org/x/mod/module
|
golang.org/x/mod/module
|
||||||
|
@ -413,7 +413,7 @@ golang.org/x/text/unicode/norm
|
||||||
# golang.org/x/time v0.5.0
|
# golang.org/x/time v0.5.0
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
golang.org/x/time/rate
|
golang.org/x/time/rate
|
||||||
# golang.org/x/tools v0.17.0
|
# golang.org/x/tools v0.18.0
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
golang.org/x/tools/go/ast/astutil
|
golang.org/x/tools/go/ast/astutil
|
||||||
golang.org/x/tools/go/gcexportdata
|
golang.org/x/tools/go/gcexportdata
|
||||||
|
|
Loading…
Reference in New Issue