Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultMissingPackageHandler ¶
DefaultMissingPackageHandler is the default handler for missing packages.
When asked to handle a missing package, it will report the miss as a warning, and then store the package in the Missing slice for later access.
type MissingPackageHandler ¶
type MissingPackageHandler interface { // NotFound is called when the Resolver fails to find a package with the given name. // // NotFound returns true when the resolver should attempt to re-resole the // dependency (e.g. when NotFound has gone and fetched the missing package). // // When NotFound returns false, the Resolver does not try to do any additional // work on the missing package. // // NotFound only returns errors when it fails to perform its internal goals. // When it returns false with no error, this indicates that the handler did // its job, but the resolver should not do any additional work on the // package. NotFound(pkg string) (bool, error) // OnGopath is called when the Resolver finds a dependency, but it's only on GOPATH. // // OnGopath provides an opportunity to copy, move, warn, or ignore cases like this. // // OnGopath returns true when the resolver should attempt to re-resolve the // dependency (e.g. when the dependency is copied to a new location). // // When OnGopath returns false, the Resolver does not try to do any additional // work on the package. // // An error indicates that OnGopath cannot complete its intended operation. // Not all false results are errors. OnGopath(pkg string) (bool, error) }
MissingPackageHandler handles the case where a package is missing during scanning.
It returns true if the package can be passed to the resolver, false otherwise. False may be returned even if error is nil.
type PkgLoc ¶
type PkgLoc uint8
PkgLoc describes the location of the package.
const ( // LocUnknown indicates the package location is unknown (probably not present) LocUnknown PkgLoc = iota // LocLocal inidcates that the package is in a local dir, not GOPATH or GOROOT. LocLocal // LocVendor indicates that the package is in a vendor/ dir LocVendor // LocGopath inidcates that the package is in GOPATH LocGopath // LocGoroot indicates that the package is in GOROOT LocGoroot // LocCgo indicates that the package is a a CGO package LocCgo )
type Resolver ¶
type Resolver struct { Handler MissingPackageHandler VendorDir string BuildContext *util.BuildCtxt // contains filtered or unexported fields }
Resolver resolves a dependency tree.
It operates in two modes:
- local resolution (ResolveLocal) determines the dependencies of the local project.
- vendor resolving (Resolve, ResolveAll) determines the dependencies of vendored projects.
Local resolution is for guessing initial dependencies. Vendor resolution is for determining vendored dependencies.
func NewResolver ¶
NewResolver returns a new Resolver initialized with the DefaultMissingPackageHandler.
This will return an error if the given path does not meet the basic criteria for a Go source project. For example, basedir must have a vendor subdirectory.
The BuildContext uses the "go/build".Default to resolve dependencies.
func (*Resolver) FindPkg ¶
FindPkg takes a package name and attempts to find it on the filesystem
The resulting PkgInfo will indicate where it was found.
func (*Resolver) Resolve ¶
Resolve takes a package name and returns all of the imported package names.
If a package is not found, this calls the Fetcher. If the Fetcher returns true, it will re-try traversing that package for dependencies. Otherwise it will add that package to the deps array and continue on without trying it. And if the Fetcher returns an error, this will stop resolution and return the error.
If basepath is set to $GOPATH, this will start from that package's root there. If basepath is set to a project's vendor path, the scanning will begin from there.
func (*Resolver) ResolveAll ¶
func (r *Resolver) ResolveAll(deps []*cfg.Dependency) ([]string, error)
ResolveAll takes a list of packages and returns an inclusive list of all vendored dependencies.
While this will scan all of the source code it can find, it will only return packages that were either explicitly passed in as deps, or were explicitly imported by the code.
Packages that are either CGO or on GOROOT are ignored. Packages that are on GOPATH, but not vendored currently generate a warning.
If one of the passed in packages does not exist in the vendor directory, an error is returned.
func (*Resolver) ResolveLocal ¶
ResolveLocal resolves dependencies for the current project.
This begins with the project, builds up a list of external dependencies.
If the deep flag is set to true, this will then resolve all of the dependencies of the dependencies it has found. If not, it will return just the packages that the base project relies upon.