Documentation
¶
Overview ¶
Package resolve finds the tool a name stands for and asks go whether it can run.
A Resolver maps a tool name, as the user gave it (possibly an alias), to the modfile that serves it and the package and binary behind it. A Prober launches the tool through `go tool` to see whether it runs. Both take their seams as fields (the modfile parser, the manifest lookup, the go runner), so a test supplies fakes and no go process runs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MissingError ¶
type MissingError struct {
Path string // relative to the project root
}
MissingError reports that the modfile serving a tool does not exist. The Ref returned with it is still filled in, so a caller can say where it looked.
func (*MissingError) Error ¶
func (e *MissingError) Error() string
func (*MissingError) Unwrap ¶
func (e *MissingError) Unwrap() error
Unwrap lets errors.Is(err, fs.ErrNotExist) match.
type Prober ¶
type Prober struct {
Resolver *Resolver
Go gocmd.Runner
Offline bool // GOPROXY=off, so a missing module fails fast
}
Prober asks go whether tools run. It never runs a tool for `install`: the install verify is `go tool -n`, which builds without running.
func (*Prober) Probe ¶
Probe says whether `go tool` can launch name under the project's strategy: "" when it can, else a one-line reason.
Read-only: stdin is empty, GOTOOLCHAIN=local so a toolchain is never downloaded, and GOPROXY=off when offline.
type Ref ¶
type Ref struct {
Name string // name as given (manifest name, possibly an alias)
Package string // tool directive serving Name; "" when none is declared
Binary string // name passed to `go tool`
ModFile string // absolute modfile path
ModFileRel string // modfile path relative to the project root, slash-separated
}
Ref is a tool name resolved against the tools directory.
type Resolver ¶
type Resolver struct {
Root string
Layout strategy.Layout
ModFiles modparser.Parser
Manifest Manifest // may be nil
}
Resolver resolves tool names for one project.
func (*Resolver) Call ¶
Call is the `go tool` invocation for ref, the single definition shared by the probes and exec:
unified go tool <bin> in <dir> split go tool -modfile=<abs> <bin> in the project root module go tool <bin> in <dir>/<name>
args are appended after the binary.
func (*Resolver) Resolve ¶
Resolve finds the modfile, package and binary serving name.
split and module: the tool's own modfile holds one directive, which serves it.
unified: the shared go.mod holds many directives. The manifest entry's package is used when it is declared there; without a manifest entry, the directive whose inferred binary name equals name. Taking the first directive would run the wrong tool whenever the project has two.