Involved Source Files
Package packages loads Go packages for inspection and analysis.
The Load function takes as input a list of patterns and return a list of Package
structs describing individual packages matched by those patterns.
The LoadMode controls the amount of detail in the loaded packages.
Load passes most patterns directly to the underlying build tool,
but all patterns with the prefix "query=", where query is a
non-empty string of letters from [a-z], are reserved and may be
interpreted as query operators.
Two query operators are currently supported: "file" and "pattern".
The query "file=path/to/file.go" matches the package or packages enclosing
the Go source file path/to/file.go. For example "file=~/go/src/fmt/print.go"
might return the packages "fmt" and "fmt [fmt.test]".
The query "pattern=string" causes "string" to be passed directly to
the underlying build tool. In most cases this is unnecessary,
but an application can use Load("pattern=" + x) as an escaping mechanism
to ensure that x is not interpreted as a query operator if it contains '='.
All other query operators are reserved for future use and currently
cause Load to report an error.
The Package struct provides basic information about the package, including
- ID, a unique identifier for the package in the returned set;
- GoFiles, the names of the package's Go source files;
- Imports, a map from source import strings to the Packages they name;
- Types, the type information for the package's exported symbols;
- Syntax, the parsed syntax trees for the package's source code; and
- TypeInfo, the result of a complete type-check of the package syntax trees.
(See the documentation for type Package for the complete list of fields
and more detailed descriptions.)
For example,
Load(nil, "bytes", "unicode...")
returns four Package structs describing the standard library packages
bytes, unicode, unicode/utf16, and unicode/utf8. Note that one pattern
can match multiple packages and that a package might be matched by
multiple patterns: in general it is not possible to determine which
packages correspond to which patterns.
Note that the list returned by Load contains only the packages matched
by the patterns. Their dependencies can be found by walking the import
graph using the Imports fields.
The Load function can be configured by passing a pointer to a Config as
the first argument. A nil Config is equivalent to the zero Config, which
causes Load to run in LoadFiles mode, collecting minimal information.
See the documentation for type Config for details.
As noted earlier, the Config.Mode controls the amount of detail
reported about the loaded packages. See the documentation for type LoadMode
for details.
Most tools should pass their command-line arguments (after any flags)
uninterpreted to the loader, so that the loader can interpret them
according to the conventions of the underlying build system.
See the Example function for typical usage.
external.gogolist.gogolist_overlay.goloadmode_string.gopackages.govisit.go
Code Examples
package main
import (
"flag"
"fmt"
"golang.org/x/tools/go/packages"
"os"
)
func main() {
flag.Parse()
// Many tools pass their command-line arguments (after any flags)
// uninterpreted to packages.Load so that it can interpret them
// according to the conventions of the underlying build system.
cfg := &packages.Config{Mode: packages.NeedFiles | packages.NeedSyntax}
pkgs, err := packages.Load(cfg, flag.Args()...)
if err != nil {
fmt.Fprintf(os.Stderr, "load: %v\n", err)
os.Exit(1)
}
if packages.PrintErrors(pkgs) > 0 {
os.Exit(1)
}
// Print the names of the source files
// for each package listed on the command line.
for _, pkg := range pkgs {
fmt.Println(pkg.ID, pkg.GoFiles)
}
}
Package-Level Type Names (total 21, in which 8 are exported)
/* sort exporteds by: | */
A Config specifies details about how packages should be loaded.
The zero value is a valid configuration.
Calls to Load do not modify this struct.
BuildFlags is a list of command-line flags to be passed through to
the build system's query tool.
Context specifies the context for the load operation.
If the context is cancelled, the loader may stop early
and return an ErrCancelled error.
If Context is nil, the load cannot be cancelled.
Dir is the directory in which to run the build system's query tool
that provides information about the packages.
If Dir is empty, the tool is run in the current directory.
Env is the environment to use when invoking the build system's query tool.
If Env is nil, the current environment is used.
As in os/exec's Cmd, only the last value in the slice for
each environment key is used. To specify the setting of only
a few variables, append to the current environment, as in:
opt.Env = append(os.Environ(), "GOOS=plan9", "GOARCH=386")
Fset provides source position information for syntax trees and types.
If Fset is nil, Load will use a new fileset, but preserve Fset's value.
Logf is the logger for the config.
If the user provides a logger, debug logging is enabled.
If the GOPACKAGESDEBUG environment variable is set to true,
but the logger is nil, default to log.Printf.
Mode controls the level of information returned for each package.
Overlay provides a mapping of absolute file paths to file contents.
If the file with the given path already exists, the parser will use the
alternative file contents provided by the map.
Overlays provide incomplete support for when a given file doesn't
already exist on disk. See the package doc above for more details.
ParseFile is called to read and parse each file
when preparing a package's type-checked syntax tree.
It must be safe to call ParseFile simultaneously from multiple goroutines.
If ParseFile is nil, the loader will uses parser.ParseFile.
ParseFile should parse the source from src and use filename only for
recording position information.
An application may supply a custom implementation of ParseFile
to change the effective file contents or the behavior of the parser,
or to modify the syntax tree. For example, selectively eliminating
unwanted function bodies can significantly accelerate type checking.
If Tests is set, the loader includes not just the packages
matching a particular pattern but also any related test packages,
including test-only variants of the package and the test executable.
For example, when using the go command, loading "fmt" with Tests=true
returns four packages, with IDs "fmt" (the standard package),
"fmt [fmt.test]" (the package as compiled for the test),
"fmt_test" (the test functions from source files in package fmt_test),
and "fmt.test" (the test binary).
In build systems with explicit names for tests,
setting Tests may have no effect.
gocmdRunner guards go command calls from concurrency errors.
modFile will be used for -modfile in go command invocations.
modFlag will be used for -modfile in go command invocations.
func Load(cfg *Config, patterns ...string) ([]*Package, error)
func defaultDriver(cfg *Config, patterns ...string) (*driverResponse, error)
func findExternalDriver(cfg *Config) driver
func golistargs(cfg *Config, words []string, goVersion int) []string
func goListDriver(cfg *Config, patterns ...string) (*driverResponse, error)
func jsonFlag(cfg *Config, goVersion int) string
func newLoader(cfg *Config) *loader
func usesExportData(cfg *Config) bool
An Error describes a problem with a package's metadata, syntax, or types.
KindErrorKindMsgstring
// "file:line:col" or "file:line" or "" or "-"
( Error) Error() string
Error : error
ErrorKind describes the source of the error, allowing the user to
differentiate between errors generated by the driver, the parser, or the
type-checker.
const ListError
const ParseError
const TypeError
const UnknownError
Module provides module information for a package.
// directory holding files for this module, if any
// error loading module
// path to go.mod file used when loading this module, if any
// go version used in module
// is this module only an indirect dependency of main module?
// is this the main module?
// module path
// replaced by this module
// time version was created
// module version
func go.pact.im/x/goupdate.modulesNotInSet(modules []Module, moduleByPath map[string]Module) []Module
func go.pact.im/x/goupdate.packagesByModule(pkgs []*Package) (map[string][]*Package, map[string]Module)
func go.pact.im/x/goupdate.sortedModules(moduleByPath map[string]Module) []Module
func go.pact.im/x/goupdate.intersectModuleSets(moduleByPath, otherModuleByPath map[string]Module) []string
func go.pact.im/x/goupdate.modulesNotInSet(modules []Module, moduleByPath map[string]Module) []Module
func go.pact.im/x/goupdate.modulesNotInSet(modules []Module, moduleByPath map[string]Module) []Module
func go.pact.im/x/goupdate.sortedModules(moduleByPath map[string]Module) []Module
ModuleError holds errors loading a module.
// the error itself
OverlayJSON is the format overlay files are expected to be in.
The Replace map maps from overlaid paths to replacement paths:
the Go command will forward all reads trying to open
each overlaid path to its replacement path, or consider the overlaid
path not to exist if the replacement path is empty.
From golang/go#39958.
Replacemap[string]string
A Package describes a loaded Go package.
CompiledGoFiles lists the absolute file paths of the package's source
files that are suitable for type checking.
This may differ from GoFiles if files are processed before compilation.
EmbedFiles lists the absolute file paths of the package's files
embedded with go:embed.
EmbedPatterns lists the absolute file patterns of the package's
files embedded with go:embed.
Errors contains any errors encountered querying the metadata
of the package, or while parsing or type-checking its files.
ExportFile is the absolute path to a file containing type
information for the package as provided by the build system.
Fset provides position information for Types, TypesInfo, and Syntax.
It is set only when Types is set.
GoFiles lists the absolute file paths of the package's Go source files.
ID is a unique identifier for a package,
in a syntax provided by the underlying build system.
Because the syntax varies based on the build system,
clients should treat IDs as opaque and not attempt to
interpret them.
IgnoredFiles lists source files that are not part of the package
using the current build configuration but that might be part of
the package using other build configurations.
IllTyped indicates whether the package or any dependency contains errors.
It is set only when Types is set.
Imports maps import paths appearing in the package's Go source files
to corresponding loaded Packages.
module is the module information for the package if it exists.
Name is the package name as it appears in the package source code.
OtherFiles lists the absolute file paths of the package's non-Go source files,
including assembly, C, C++, Fortran, Objective-C, SWIG, and so on.
PkgPath is the package path as used by the go/types package.
Syntax is the package's syntax trees, for the files listed in CompiledGoFiles.
The NeedSyntax LoadMode bit populates this field for packages matching the patterns.
If NeedDeps and NeedImports are also set, this field will also be populated
for dependencies.
Syntax is kept in the same order as CompiledGoFiles, with the caveat that nils are
removed. If parsing returned nil, Syntax may be shorter than CompiledGoFiles.
TypeErrors contains the subset of errors produced during type checking.
Types provides type information for the package.
The NeedTypes LoadMode bit sets this field for packages matching the
patterns; type information for dependencies may be missing or incomplete,
unless NeedDeps and NeedImports are also set.
TypesInfo provides type information about the package's syntax trees.
It is set only when Syntax is set.
TypesSizes provides the effective size function for types in TypesInfo.
depsErrors is the DepsErrors field from the go list response, if any.
forTest is the package under test, if any.
MarshalJSON returns the Package in its JSON form.
For the most part, the structure fields are written out unmodified, and
the type and syntax fields are skipped.
The imports are written out as just a map of path to package id.
The errors are written using a custom type that tries to preserve the
structure of error types we know about.
This method exists to enable support for additional build systems. It is
not intended for use by clients of the API and we may change the format.
(*Package) String() string
UnmarshalJSON reads in a Package from its JSON format.
See MarshalJSON for details about the format accepted.
*Package : encoding/json.Marshaler
*Package : encoding/json.Unmarshaler
*Package : expvar.Var
*Package : fmt.Stringer
*Package : context.stringer
*Package : github.com/aws/smithy-go/middleware.stringer
*Package : runtime.stringer
func Load(cfg *Config, patterns ...string) ([]*Package, error)
func go.pact.im/x/goupdate.collectPackages(pkgs []*Package) []*Package
func go.pact.im/x/goupdate.loadPackages(workspaceDir string, patterns ...string) ([]*Package, error)
func go.pact.im/x/goupdate.packagesByImportPath(pkgs []*Package) map[string]*Package
func go.pact.im/x/goupdate.packagesByModule(pkgs []*Package) (map[string][]*Package, map[string]Module)
func go.pact.im/x/goupdate.packagesNotInSet(pkgs []*Package, pkgByImportPath map[string]*Package) []*Package
func go.pact.im/x/goupdate.splitBrokenPackages(pkgs []*Package) (good, broken []*Package)
func PrintErrors(pkgs []*Package) int
func Visit(pkgs []*Package, pre func(*Package) bool, post func(*Package))
func hasTestFiles(p *Package) bool
func maybeFixPackageName(newName string, isTestFile bool, pkgsOfDir []*Package)
func reclaimPackage(pkg *Package, id string, filename string, contents []byte) bool
func go.pact.im/x/goupdate.collectPackages(pkgs []*Package) []*Package
func go.pact.im/x/goupdate.intersectPackageSets(pkgByImportPath, otherPkgByImportPath map[string]*Package) []string
func go.pact.im/x/goupdate.packagesByImportPath(pkgs []*Package) map[string]*Package
func go.pact.im/x/goupdate.packagesByModule(pkgs []*Package) (map[string][]*Package, map[string]Module)
func go.pact.im/x/goupdate.packagesNotInSet(pkgs []*Package, pkgByImportPath map[string]*Package) []*Package
func go.pact.im/x/goupdate.packagesNotInSet(pkgs []*Package, pkgByImportPath map[string]*Package) []*Package
func go.pact.im/x/goupdate.splitBrokenPackages(pkgs []*Package) (good, broken []*Package)
func go.pact.im/x/goupdate.stateFromPacakges(pkgs []*Package) *main.state
driver is the type for functions that query the build system for the
packages named by the patterns.
func findExternalDriver(cfg *Config) driver
driverRequest is used to provide the portion of Load's Config that is needed by a driver.
BuildFlags are flags that should be passed to the underlying build system.
Env specifies the environment the underlying build system should be run in.
ModeLoadMode
Overlay maps file paths (relative to the driver's working directory) to the byte contents
of overlay files.
Tests specifies whether the patterns should also return test packages.
driverResponse contains the results for a driver query.
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.
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.
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).
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.
Sizes, if not nil, is the types.Sizes to use when type checking.
func defaultDriver(cfg *Config, patterns ...string) (*driverResponse, error)
func goListDriver(cfg *Config, patterns ...string) (*driverResponse, error)
cfg*Configctxcontext.ContextenvOncesync.OncegoEnvmap[string]stringgoEnvErrorerror
// The X in Go 1.X.
goVersionErrorerrorgoVersionOncesync.OncerootDirsmap[string]stringrootDirsErrorerrorrootsOncesync.Once
vendorDirs caches the (non)existence of vendor directories.
(*golistState) addNeededOverlayPackages(response *responseDeduper, pkgs []string) error
adhocPackage attempts to load or construct an ad-hoc package for a given
query, if the original call to the driver produced inadequate results.
cfgInvocation returns an Invocation that reflects cfg's settings.
createDriverResponse uses the "go list" command to expand the pattern
words and return a response for the specified packages.
determineRootDirs returns a mapping from absolute directories that could
contain code to their corresponding import path prefixes.
(*golistState) determineRootDirsGOPATH() (map[string]string, error)(*golistState) determineRootDirsModules() (map[string]string, error)
getEnv returns Go environment variables. Only specific variables are
populated -- computing all of them is slow.
getGoVersion returns the effective minor version of the go command.
getPkgPath finds the package path of a directory if it's relative to a root
directory.
invokeGo returns the stdout of a go command invocation.
mustGetEnv is a convenience function that can be used if getEnv has already succeeded.
processGolistOverlay provides rudimentary support for adding
files that don't exist on disk to an overlay. The results can be
sometimes incorrect.
TODO(matloob): Handle unsupported cases, including the following:
- determining the correct package to add given a new import path
resolveImport finds the ID of a package given its import path.
In particular, it will find the right vendored copy when in GOPATH mode.
(*golistState) runContainsQueries(response *responseDeduper, queries []string) error(*golistState) shouldAddFilenameFromError(p *jsonPackage) bool
writeOverlays writes out files for go list's -overlay flag, as described
above.
A goTooOldError reports that the go command
found by exec.LookPath is too old to use the new go list behavior.
errorerror( goTooOldError) Error() builtin.string
goTooOldError : error
An importFunc is an implementation of the single-method
types.Importer interface based on a function value.
( importerFunc) Import(path string) (*types.Package, error)
importerFunc : go/types.Importer
// the error itself
// shortest path from package named on command line to this one
// position of error (if present, file:line:col)
loader holds the working state of a single call to load.
ConfigConfig
BuildFlags is a list of command-line flags to be passed through to
the build system's query tool.
Context specifies the context for the load operation.
If the context is cancelled, the loader may stop early
and return an ErrCancelled error.
If Context is nil, the load cannot be cancelled.
Dir is the directory in which to run the build system's query tool
that provides information about the packages.
If Dir is empty, the tool is run in the current directory.
Env is the environment to use when invoking the build system's query tool.
If Env is nil, the current environment is used.
As in os/exec's Cmd, only the last value in the slice for
each environment key is used. To specify the setting of only
a few variables, append to the current environment, as in:
opt.Env = append(os.Environ(), "GOOS=plan9", "GOARCH=386")
Fset provides source position information for syntax trees and types.
If Fset is nil, Load will use a new fileset, but preserve Fset's value.
Logf is the logger for the config.
If the user provides a logger, debug logging is enabled.
If the GOPACKAGESDEBUG environment variable is set to true,
but the logger is nil, default to log.Printf.
Mode controls the level of information returned for each package.
Overlay provides a mapping of absolute file paths to file contents.
If the file with the given path already exists, the parser will use the
alternative file contents provided by the map.
Overlays provide incomplete support for when a given file doesn't
already exist on disk. See the package doc above for more details.
ParseFile is called to read and parse each file
when preparing a package's type-checked syntax tree.
It must be safe to call ParseFile simultaneously from multiple goroutines.
If ParseFile is nil, the loader will uses parser.ParseFile.
ParseFile should parse the source from src and use filename only for
recording position information.
An application may supply a custom implementation of ParseFile
to change the effective file contents or the behavior of the parser,
or to modify the syntax tree. For example, selectively eliminating
unwanted function bodies can significantly accelerate type checking.
If Tests is set, the loader includes not just the packages
matching a particular pattern but also any related test packages,
including test-only variants of the package and the test executable.
For example, when using the go command, loading "fmt" with Tests=true
returns four packages, with IDs "fmt" (the standard package),
"fmt [fmt.test]" (the package as compiled for the test),
"fmt_test" (the test functions from source files in package fmt_test),
and "fmt.test" (the test binary).
In build systems with explicit names for tests,
setting Tests may have no effect.
gocmdRunner guards go command calls from concurrency errors.
modFile will be used for -modfile in go command invocations.
modFlag will be used for -modfile in go command invocations.
// enforces mutual exclusion of exportdata operations
parseCachemap[string]*parseValueparseCacheMusync.Mutexpkgsmap[string]*loaderPackage
Config.Mode contains the implied mode (see impliedLoadMode).
Implied mode contains all the fields we need the data for.
In requestedMode there are the actually requested fields.
We'll zero them out before returning packages to the user.
This makes it easier for us to get the conditions where
we need certain modes right.
sizestypes.Sizes
loadFromExportData ensures that type information is present for the specified
package, loading it from an export data file on the first request.
On success it sets lpkg.Types to a new Package.
loadPackage loads the specified package.
It must be called only once per Package,
after immediate dependencies are loaded.
Precondition: ld.Mode & NeedTypes.
loadRecursive loads the specified package and its dependencies,
recursively, in parallel, in topological order.
It is atomic and idempotent.
Precondition: ld.Mode&NeedTypes.
(*loader) parseFile(filename string) (*ast.File, error)
parseFiles reads and parses the Go source files and returns the ASTs
of the ones that could be at least partially parsed, along with a
list of I/O and parse errors encountered.
Because files are scanned in parallel, the token.Pos
positions of the resulting ast.Files are not ordered.
refine connects the supplied packages into a graph and then adds type and
and syntax information as requested by the LoadMode.
func newLoader(cfg *Config) *loader
loaderPackage augments Package with state used during the loading phase
Package*Package
CompiledGoFiles lists the absolute file paths of the package's source
files that are suitable for type checking.
This may differ from GoFiles if files are processed before compilation.
EmbedFiles lists the absolute file paths of the package's files
embedded with go:embed.
EmbedPatterns lists the absolute file patterns of the package's
files embedded with go:embed.
Errors contains any errors encountered querying the metadata
of the package, or while parsing or type-checking its files.
ExportFile is the absolute path to a file containing type
information for the package as provided by the build system.
Fset provides position information for Types, TypesInfo, and Syntax.
It is set only when Types is set.
GoFiles lists the absolute file paths of the package's Go source files.
ID is a unique identifier for a package,
in a syntax provided by the underlying build system.
Because the syntax varies based on the build system,
clients should treat IDs as opaque and not attempt to
interpret them.
IgnoredFiles lists source files that are not part of the package
using the current build configuration but that might be part of
the package using other build configurations.
IllTyped indicates whether the package or any dependency contains errors.
It is set only when Types is set.
Imports maps import paths appearing in the package's Go source files
to corresponding loaded Packages.
module is the module information for the package if it exists.
Name is the package name as it appears in the package source code.
OtherFiles lists the absolute file paths of the package's non-Go source files,
including assembly, C, C++, Fortran, Objective-C, SWIG, and so on.
PkgPath is the package path as used by the go/types package.
Syntax is the package's syntax trees, for the files listed in CompiledGoFiles.
The NeedSyntax LoadMode bit populates this field for packages matching the patterns.
If NeedDeps and NeedImports are also set, this field will also be populated
for dependencies.
Syntax is kept in the same order as CompiledGoFiles, with the caveat that nils are
removed. If parsing returned nil, Syntax may be shorter than CompiledGoFiles.
TypeErrors contains the subset of errors produced during type checking.
Types provides type information for the package.
The NeedTypes LoadMode bit sets this field for packages matching the
patterns; type information for dependencies may be missing or incomplete,
unless NeedDeps and NeedImports are also set.
TypesInfo provides type information about the package's syntax trees.
It is set only when Syntax is set.
TypesSizes provides the effective size function for types in TypesInfo.
// for cycle detection
// minor version number of go command on PATH
// maps each bad import to its error
// package was matched by a pattern
loadOncesync.Once
// load from source (Mode >= LoadTypes)
// type information is either requested or depended on
depsErrors is the DepsErrors field from the go list response, if any.
forTest is the package under test, if any.
MarshalJSON returns the Package in its JSON form.
For the most part, the structure fields are written out unmodified, and
the type and syntax fields are skipped.
The imports are written out as just a map of path to package id.
The errors are written using a custom type that tries to preserve the
structure of error types we know about.
This method exists to enable support for additional build systems. It is
not intended for use by clients of the API and we may change the format.
( loaderPackage) String() string
UnmarshalJSON reads in a Package from its JSON format.
See MarshalJSON for details about the format accepted.
loaderPackage : encoding/json.Marshaler
loaderPackage : encoding/json.Unmarshaler
loaderPackage : expvar.Var
loaderPackage : fmt.Stringer
loaderPackage : context.stringer
loaderPackage : github.com/aws/smithy-go/middleware.stringer
loaderPackage : runtime.stringer
Package-Level Functions (total 26, in which 3 are exported)
Load loads and returns the Go packages named by the given patterns.
Config specifies loading options;
nil behaves the same as an empty Config.
Load returns an error if any of the patterns was invalid
as defined by the underlying build system.
It may return an empty list of packages without an error,
for instance for an empty expansion of a valid wildcard.
Errors associated with a particular package are recorded in the
corresponding Package's Errors list, and do not cause Load to
return an error. Clients may need to handle such errors before
proceeding with further analysis. The PrintErrors function is
provided for convenient display of all errors.
PrintErrors prints to os.Stderr the accumulated errors of all
packages in the import graph rooted at pkgs, dependencies first.
PrintErrors returns the number of errors printed.
Visit visits all the packages in the import graph whose roots are
pkgs, calling the optional pre function the first time each package
is encountered (preorder), and the optional post function after a
package's dependencies have been visited (postorder).
The boolean result of pre(pkg) determines whether
the imports of package pkg are visited.
absJoin absolutizes and flattens the lists of files.
defaultDriver is a driver that implements go/packages' fallback behavior.
It will try to request to an external driver, if one exists. If there's
no external driver, or the driver returns a response with NotHandled set,
defaultDriver will fall back to the go list driver.
findExternalDriver returns the file path of a tool that supplies
the build system package structure, or "" if not found."
If GOPACKAGESDRIVER is set in the environment findExternalTool returns its
value, otherwise it searches for a binary named gopackagesdriver on the PATH.
This function is copy-pasted from
https://github.com/golang/go/blob/9706f510a5e2754595d716bd64be8375997311fb/src/cmd/go/internal/search/search.go#L360.
It should be deleted when we remove support for overlays from go/packages.
NOTE: This does not handle any ./... or ./ style queries, as this function
doesn't know the working directory.
matchPattern(pattern)(name) reports whether
name matches pattern. Pattern is a limited glob
pattern in which '...' means 'any string' and there
is no other special syntax.
Unfortunately, there are two special cases. Quoting "go help packages":
First, /... at the end of the pattern can match an empty string,
so that net/... matches both net and packages in its subdirectories, like net/http.
Second, any slash-separated pattern element containing a wildcard never
participates in a match of the "vendor" element in the path of a vendored
package, so that ./... does not match packages in subdirectories of
./vendor or ./mycode/vendor, but ./vendor/... and ./mycode/vendor/... do.
Note, however, that a directory named vendor that itself contains code
is not a vendored package: cmd/vendor would be a command named vendor,
and the pattern cmd/... matches it.
It is possible that the files in the disk directory dir have a different package
name from newName, which is deduced from the overlays. If they all have a different
package name, and they all have the same package name, then that name becomes
the package name.
It returns true if it changes the package name, false otherwise.
reclaimPackage attempts to reuse a package that failed to load in an overlay.
If the package has errors and has no Name, GoFiles, or Imports,
then it's possible that it doesn't yet exist on disk.
replaceVendor returns the result of replacing
non-trailing vendor path elements in x with repl.
sameFile returns true if x and y have the same basename and denote
the same file.