dependency

package
v0.0.0-...-f8f0647 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2015 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultMissingPackageHandler

type DefaultMissingPackageHandler struct {
	Missing []string
	Gopath  []string
}

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) NotFound

func (d *DefaultMissingPackageHandler) NotFound(pkg string) (bool, error)

NotFound prints a warning and then stores the package name in Missing.

It never returns an error, and it always returns false.

func (*DefaultMissingPackageHandler) OnGopath

func (d *DefaultMissingPackageHandler) OnGopath(pkg string) (bool, error)

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 PkgInfo

type PkgInfo struct {
	Name, Path string
	Vendored   bool
	Loc        PkgLoc
}

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

func NewResolver(basedir string) (*Resolver, error)

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

func (r *Resolver) FindPkg(name string) *PkgInfo

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

func (r *Resolver) Resolve(pkg, basepath string) ([]string, error)

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

func (r *Resolver) ResolveLocal(deep bool) ([]string, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL