load

package
v0.0.0-...-9735fcf Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2017 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package load loads packages.

Index

Constants

View Source
const (
	// useVendor means that loadImport should do vendor expansion
	// (provided the vendoring experiment is enabled).
	// That is, useVendor means that the import path came from
	// a source file and has not been vendor-expanded yet.
	// Every import path should be loaded initially with useVendor,
	// and then the expanded version (with the /vendor/ in it) gets
	// recorded as the canonical import path. At that point, future loads
	// of that package must not pass useVendor, because
	// disallowVendor will reject direct use of paths containing /vendor/.
	UseVendor = 1 << iota

	// getTestDeps is for download (part of "go get") and indicates
	// that test dependencies should be fetched too.
	GetTestDeps
)

Mode flags for loadImport and download (in get.go).

View Source
const (
	ToRoot    targetDir = iota // to bin dir inside package root (default)
	ToTool                     // GOROOT/pkg/tool
	StalePath                  // the old import path; fail to build
)

Variables

View Source
var GoTools = map[string]targetDir{
	"cmd/addr2line":                        ToTool,
	"cmd/api":                              ToTool,
	"cmd/asm":                              ToTool,
	"cmd/compile":                          ToTool,
	"cmd/cgo":                              ToTool,
	"cmd/cover":                            ToTool,
	"cmd/dist":                             ToTool,
	"cmd/doc":                              ToTool,
	"cmd/fix":                              ToTool,
	"cmd/link":                             ToTool,
	"cmd/newlink":                          ToTool,
	"cmd/nm":                               ToTool,
	"cmd/objdump":                          ToTool,
	"cmd/pack":                             ToTool,
	"cmd/pprof":                            ToTool,
	"cmd/trace":                            ToTool,
	"cmd/vet":                              ToTool,
	"code.google.com/p/go.tools/cmd/cover": StalePath,
	"code.google.com/p/go.tools/cmd/godoc": StalePath,
	"code.google.com/p/go.tools/cmd/vet":   StalePath,
}

goTools is a map of Go program import path to install target directory.

View Source
var IgnoreImports bool // control whether we ignore imports in packages

Functions

func ClearCmdCache

func ClearCmdCache()

func ClearPackageCache

func ClearPackageCache()

func ClearPackageCachePartial

func ClearPackageCachePartial(args []string)

func ComputeStale

func ComputeStale(pkgs ...*Package)

computeStale computes the Stale flag in the package dag that starts at the named pkgs (command-line arguments).

func FindVendor

func FindVendor(path string) (index int, ok bool)

FindVendor looks for the last non-terminating "vendor" path element in the given import path. If there isn't one, FindVendor returns ok=false. Otherwise, FindVendor returns ok=true and the index of the "vendor".

Note that terminating "vendor" elements don't count: "x/vendor" is its own package, not the vendored copy of an import "" (the empty import path). This will allow people to have packages or commands named vendor. This may help reduce breakage, or it may just be confusing. We'll see.

func ImportPaths

func ImportPaths(args []string) []string

ImportPaths returns the import paths to use for the given command line.

func ImportPathsNoDotExpansion

func ImportPathsNoDotExpansion(args []string) []string

ImportPathsNoDotExpansion returns the import paths to use for the given command line, but it does no ... expansion.

func IsMetaPackage

func IsMetaPackage(name string) bool

IsMetaPackage checks if name is a reserved package name that expands to multiple packages.

func MatchPackages

func MatchPackages(pattern string) []string

MatchPackages returns a list of package paths matching pattern (see go help packages for pattern syntax).

func MatchPackagesInFS

func MatchPackagesInFS(pattern string) []string

MatchPackagesInFS returns a list of package paths matching pattern, which must begin with ./ or ../ (see go help packages for pattern syntax).

func PluginPath

func PluginPath(p *Package) string

PluginPath computes the package path for a plugin main package.

This is typically the import path of the main package p, unless the plugin is being built directly from source files. In that case we combine the package build ID with the contents of the main package source files. This allows us to identify two different plugins built from two source files with the same name.

func VendoredImportPath

func VendoredImportPath(parent *Package, path string) (found string)

VendoredImportPath returns the expansion of path when it appears in parent. If parent is x/y/z, then path might expand to x/y/z/vendor/path, x/y/vendor/path, x/vendor/path, vendor/path, or else stay path if none of those exist. VendoredImportPath returns the expanded path or, if no expansion is found, the original.

Types

type CoverVar

type CoverVar struct {
	File string // local file name
	Var  string // name of count struct
}

CoverVar holds the name of the generated coverage variables targeting the named file.

type ImportStack

type ImportStack []string

An ImportStack is a stack of import paths.

func (*ImportStack) Copy

func (s *ImportStack) Copy() []string

func (*ImportStack) Pop

func (s *ImportStack) Pop()

func (*ImportStack) Push

func (s *ImportStack) Push(p string)

type NoGoError

type NoGoError struct {
	Package *Package
}

func (*NoGoError) Error

func (e *NoGoError) Error() string

type Package

type Package struct {
	PackagePublic                 // visible in 'go list'
	Internal      PackageInternal // for use inside go command only
}

A Package describes a single package found in a directory.

func GoFilesPackage

func GoFilesPackage(gofiles []string) *Package

GoFilesPackage creates a package for building a collection of Go files (typically named on the command line). The target is named p.a for package p or named after the first Go file for package main.

func LoadImport

func LoadImport(path, srcDir string, parent *Package, stk *ImportStack, importPos []token.Position, mode int) *Package

loadImport scans the directory named by path, which must be an import path, but possibly a local import path (an absolute file system path or one beginning with ./ or ../). A local relative path is interpreted relative to srcDir. It returns a *Package describing the package found in that directory.

func LoadPackage

func LoadPackage(arg string, stk *ImportStack) *Package

loadPackage is like loadImport but is used for command-line arguments, not for paths found in import statements. In addition to ordinary import paths, loadPackage accepts pseudo-paths beginning with cmd/ to denote commands in the Go command directory, as well as paths to those directories.

func PackageList

func PackageList(roots []*Package) []*Package

packageList returns the list of packages in the dag rooted at roots as visited in a depth-first post-order traversal.

func Packages

func Packages(args []string) []*Package

packages returns the packages named by the command line arguments 'args'. If a named package cannot be loaded at all (for example, if the directory does not exist), then packages prints an error and does not include that package in the results. However, if errors occur trying to load dependencies of a named package, the named package is still returned, with p.Incomplete = true and details in p.DepsErrors.

func PackagesAndErrors

func PackagesAndErrors(args []string) []*Package

packagesAndErrors is like 'packages' but returns a *Package for every argument, even the ones that cannot be loaded at all. The packages that fail to load will have p.Error != nil.

func PackagesForBuild

func PackagesForBuild(args []string) []*Package

packagesForBuild is like 'packages' but fails if any of the packages or their dependencies have errors (cannot be built).

func ReloadPackage

func ReloadPackage(arg string, stk *ImportStack) *Package

reloadPackage is like loadPackage but makes sure not to use the package cache.

func (*Package) InternalDeps

func (p *Package) InternalDeps() []*Package

InternalDeps returns the full dependency list for p, built by traversing p.Internal.Imports, their .Internal.Imports, and so on. It guarantees that the returned list has only one package per ImportPath and that "test" copies of a package are returned in preference to "real" ones.

func (*Package) UsesCgo

func (p *Package) UsesCgo() bool

usesCgo reports whether the package needs to run cgo

func (*Package) UsesSwig

func (p *Package) UsesSwig() bool

usesSwig reports whether the package needs to run SWIG.

func (*Package) Vendored

func (p *Package) Vendored(imports []string) []string

Vendored returns the vendor-resolved version of imports, which should be p.TestImports or p.XTestImports, NOT p.Imports. The imports in p.TestImports and p.XTestImports are not recursively loaded during the initial load of p, so they list the imports found in the source file, but most processing should be over the vendor-resolved import paths. We do this resolution lazily both to avoid file system work and because the eventual real load of the test imports (during 'go test') can produce better error messages if it starts with the original paths. The initial load of p loads all the non-test imports and rewrites the vendored paths, so nothing should ever call p.vendored(p.Imports).

type PackageError

type PackageError struct {
	ImportStack   []string // shortest path from package named on command line to this one
	Pos           string   // position of error
	Err           string   // the error itself
	IsImportCycle bool     `json:"-"` // the error is an import cycle
	Hard          bool     `json:"-"` // whether the error is soft or hard; soft errors are ignored in some places
}

A PackageError describes an error loading information about a package.

func (*PackageError) Error

func (p *PackageError) Error() string

type PackageInternal

type PackageInternal struct {
	// Unexported fields are not part of the public API.
	Build        *build.Package
	Pkgdir       string     // overrides build.PkgDir
	Imports      []*Package // this package's direct imports
	GoFiles      []string   // GoFiles+CgoFiles+TestGoFiles+XTestGoFiles files, absolute paths
	SFiles       []string
	AllGoFiles   []string             // gofiles + IgnoredGoFiles, absolute paths
	Target       string               // installed file for this package (may be executable)
	Pkgfile      string               // where package will be (or is already) built or installed
	Fake         bool                 // synthesized package
	External     bool                 // synthesized external test package
	ForceLibrary bool                 // this package is a library (even if named "main")
	Cmdline      bool                 // defined by files listed on command line
	Local        bool                 // imported via local path (./ or ../)
	LocalPrefix  string               // interpret ./ and ../ imports relative to this prefix
	ExeName      string               // desired name for temporary executable
	CoverMode    string               // preprocess Go source files with the coverage tool in this mode
	CoverVars    map[string]*CoverVar // variables created by coverage analysis
	OmitDebug    bool                 // tell linker not to write debug information
	BuildID      string               // expected build ID for generated package
	GobinSubdir  bool                 // install target would be subdir of GOBIN
}

type PackagePublic

type PackagePublic struct {
	// Note: These fields are part of the go command's public API.
	// See list.go. It is okay to add fields, but not to change or
	// remove existing ones. Keep in sync with list.go
	Dir           string `json:",omitempty"` // directory containing package sources
	ImportPath    string `json:",omitempty"` // import path of package in dir
	ImportComment string `json:",omitempty"` // path in import comment on package statement
	Name          string `json:",omitempty"` // package name
	Doc           string `json:",omitempty"` // package documentation string
	Target        string `json:",omitempty"` // install path
	Shlib         string `json:",omitempty"` // the shared library that contains this package (only set when -linkshared)
	Goroot        bool   `json:",omitempty"` // is this package found in the Go root?
	Standard      bool   `json:",omitempty"` // is this package part of the standard Go library?
	Stale         bool   `json:",omitempty"` // would 'go install' do anything for this package?
	StaleReason   string `json:",omitempty"` // why is Stale true?
	Root          string `json:",omitempty"` // Go root or Go path dir containing this package
	ConflictDir   string `json:",omitempty"` // Dir is hidden by this other directory
	BinaryOnly    bool   `json:",omitempty"` // package cannot be recompiled

	// Source files
	GoFiles        []string `json:",omitempty"` // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
	CgoFiles       []string `json:",omitempty"` // .go sources files that import "C"
	IgnoredGoFiles []string `json:",omitempty"` // .go sources ignored due to build constraints
	CFiles         []string `json:",omitempty"` // .c source files
	CXXFiles       []string `json:",omitempty"` // .cc, .cpp and .cxx source files
	MFiles         []string `json:",omitempty"` // .m source files
	HFiles         []string `json:",omitempty"` // .h, .hh, .hpp and .hxx source files
	FFiles         []string `json:",omitempty"` // .f, .F, .for and .f90 Fortran source files
	SFiles         []string `json:",omitempty"` // .s source files
	SwigFiles      []string `json:",omitempty"` // .swig files
	SwigCXXFiles   []string `json:",omitempty"` // .swigcxx files
	SysoFiles      []string `json:",omitempty"` // .syso system object files added to package

	// Cgo directives
	CgoCFLAGS    []string `json:",omitempty"` // cgo: flags for C compiler
	CgoCPPFLAGS  []string `json:",omitempty"` // cgo: flags for C preprocessor
	CgoCXXFLAGS  []string `json:",omitempty"` // cgo: flags for C++ compiler
	CgoFFLAGS    []string `json:",omitempty"` // cgo: flags for Fortran compiler
	CgoLDFLAGS   []string `json:",omitempty"` // cgo: flags for linker
	CgoPkgConfig []string `json:",omitempty"` // cgo: pkg-config names

	// Dependency information
	Imports []string `json:",omitempty"` // import paths used by this package
	Deps    []string `json:",omitempty"` // all (recursively) imported dependencies

	// Error information
	Incomplete bool            `json:",omitempty"` // was there an error loading this package or dependencies?
	Error      *PackageError   `json:",omitempty"` // error loading this package (not dependencies)
	DepsErrors []*PackageError `json:",omitempty"` // errors loading dependencies

	// Test information
	TestGoFiles  []string `json:",omitempty"` // _test.go files in package
	TestImports  []string `json:",omitempty"` // imports from TestGoFiles
	XTestGoFiles []string `json:",omitempty"` // _test.go files outside package
	XTestImports []string `json:",omitempty"` // imports from XTestGoFiles
}

Jump to

Keyboard shortcuts

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