Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteUnused ¶
DeleteUnused removes packages from vendor/ that are no longer used.
TODO: This should work off of a Lock file, not glide.yaml.
func IsSrcDir ¶
IsSrcDir returns true if this is a directory that could have source code, false otherwise.
Directories with _ or . prefixes are skipped, as are testdata and vendor.
func IterativeScan ¶
IterativeScan attempts to obtain a list of imported dependencies from a package. This scanning is different from ImportDir as part of the go/build package. It looks over different permutations of the supported OS/Arch to try and find all imports. This is different from setting UseAllFiles to true on the build Context. It scopes down to just the supported OS/Arch.
Note, there are cases where multiple packages are in the same directory. This usually happens with an example that has a main package and a +build tag of ignore. This is a bit of a hack. It causes UseAllFiles to have errors.
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.
func (*DefaultMissingPackageHandler) InVendor ¶
func (d *DefaultMissingPackageHandler) InVendor(pkg string) error
InVendor is run when a package is found in the vendor/ folder
type DefaultVersionHandler ¶
type DefaultVersionHandler struct{}
DefaultVersionHandler is the default handler for setting the version.
The default handler leaves the current version and skips setting a version. For a handler that alters the version see the handler included in the repo package as part of the installer.
func (*DefaultVersionHandler) Process ¶
func (d *DefaultVersionHandler) Process(pkg string) error
Process a package to aide in version setting.
func (*DefaultVersionHandler) SetVersion ¶
func (d *DefaultVersionHandler) SetVersion(pkg string) error
SetVersion here sends a message when a package is found noting that it did not set the version.
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) // InVendor is called when the Resolver finds a dependency in the vendor/ directory. // // This can be used update a project found in the vendor/ folder. InVendor(pkg string) 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 // LocAppengine indicates the package is part of the appengine SDK. It's a // special build mode. https://blog.golang.org/the-app-engine-sdk-and-workspaces-gopath // Why does a Google product get a special case build mode with a local // package? LocAppengine )
type Resolver ¶
type Resolver struct { Handler MissingPackageHandler VersionHandler VersionHandler VendorDir string BuildContext *util.BuildCtxt Config *cfg.Config // ResolveAllFiles toggles deep scanning. // If this is true, resolve by scanning all files, not by walking the // import tree. ResolveAllFiles bool // 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.
type VersionHandler ¶
type VersionHandler interface { // Process provides an opportunity to process the codebase for version setting. Process(pkg string) error // SetVersion sets the version for a package. An error is returned if there // was a problem setting the version. SetVersion(pkg string) error }
VersionHandler sets the version for a package when found while scanning.
When a package if found it needs to be on the correct version before scanning its contents to be sure to pick up the right elements for that version.