Documentation
¶
Overview ¶
Package findpkg finds packages from user-input strings that are either file paths or Go package paths.
findpkg supports globs and exclusions in addition to the normal `go list` syntax, as described in the [NewPackage] documentation.
Index ¶
- func GlobPaths(l ulog.Logger, env Env, patterns ...string) []string
- func Modules(paths []string) (map[string][]string, []string)
- func NewPackages(l ulog.Logger, genv *golang.Environ, env Env, names ...string) ([]*bbinternal.Package, error)
- func ResolveGlobs(l ulog.Logger, genv *golang.Environ, env Env, patterns []string) ([]string, error)
- type Env
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Modules ¶
Modules returns a list of module directories => directories of packages inside that module as well as packages that have no discernible module.
The module for a package is determined by the **first** parent directory that contains a go.mod.
func NewPackages ¶
func NewPackages(l ulog.Logger, genv *golang.Environ, env Env, names ...string) ([]*bbinternal.Package, error)
NewPackages collects package metadata about all named packages.
names can either be directory paths or Go import paths, with globs.
It skips directories that do not have Go files subject to the build constraints in env and logs a "Skipping package {}" statement about such directories/packages.
All given names have to be resolvable by GOPATH or by Go modules. Generally, if `go list <name>` works, it should work here. (Except go list does not support globs or exclusions.)
Allowed formats for names:
relative and absolute paths including globs following Go's filepath.Match format.
Go package paths; e.g. github.com/u-root/u-root/cmds/core/ls
Globs of Go package paths, e.g github.com/u-root/u-root/cmds/i* (using path.Match format).
Go package path expansions with ..., e.g. github.com/u-root/u-root/cmds/core/...
file system paths (with globs in filepath.Match format) relative to GBB_PATH, e.g. cmds/core/ls if GBB_PATH contains $HOME/u-root.
backwards compatibility: UROOT_SOURCE is a GBB_PATH, and patterns that begin with github.com/u-root/u-root/ will attempt to use UROOT_SOURCE first to find Go commands within.
If a pattern starts with "-", it excludes the matching package(s).
Globs of Go package paths must be within module boundaries to give accurate results, i.e. a glob that spans 2 Go modules may give unpredictable results.
Examples of valid inputs:
./foobar
./foobar/glob*
github.com/u-root/u-root/cmds/core/...
github.com/u-root/u-root/cmds/core/ip
github.com/u-root/u-root/cmds/core/g*lob
GBB_PATH=$HOME/u-root:$HOME/yourproject cmds/core/* cmd/foobar
UROOT_SOURCE=$HOME/u-root github.com/u-root/u-root/cmds/core/ip
func ResolveGlobs ¶
func ResolveGlobs(l ulog.Logger, genv *golang.Environ, env Env, patterns []string) ([]string, error)
ResolveGlobs takes a list of Go paths and directories that may include globs and returns a valid list of Go commands (either addressed by Go package path or directory path).
It returns only packages that have Go files subject to the build constraints in env and logs a "Skipping package {}" statement about packages that are excluded due to build constraints.
ResolveGlobs always returns normalized Go package paths.
ResolveGlobs should work in all cases that `go list` works.
See NewPackages for allowed formats.
Types ¶
type Env ¶
type Env struct { // GBBPath provides directories in which to look for Go commands. // // The default is to use a colon-separated list from the env var // GBB_PATH. GBBPath []string // URootSource is a special GBBPath. It's a directory that will be used // to look for u-root commands. If a u-root command is given as a // pattern with the "github.com/u-root/u-root/" Go package path prefix, // URootSource will be used to find the command source. // // The default is to use UROOT_SOURCE env var. URootSource string }
Env is configuration for package lookups.
func DefaultEnv ¶
func DefaultEnv() Env
DefaultEnv is the default environment derived from environment variables and the current working directory.