Documentation ¶
Overview ¶
Package buildutil provides utilities related to the go/build package in the standard library.
All I/O is done via the build.Context file system interface, which must be concurrency-safe.
Index ¶
- Variables
- func AllPackages(ctxt *build.Context) []string
- func ExpandPatterns(ctxt *build.Context, patterns []string) map[string]bool
- func ForEachPackage(ctxt *build.Context, found func(importPath string, err error))
- func ImportPackage(w *PkgWalker, pkgPath string, conf *PkgConfig) (*types.Package, error)
- func IsSameObject(a, b types.Object) bool
- func IsSamePkg(a, b *types.Package) bool
- func ReadDir(ctxt *build.Context, path string) ([]os.FileInfo, error)
- type FileCursor
- type Importer
- type ObjKind
- type ObjList
- type PkgConfig
- type PkgWalker
- func (w *PkgWalker) CheckIsImport(cursor *FileCursor) *ast.ImportSpec
- func (w *PkgWalker) FindDeclForPos(p token.Pos) (*ast.File, ast.Decl)
- func (w *PkgWalker) FindImportEndPos(ast *ast.File) token.Pos
- func (w *PkgWalker) FindImportName(ast *ast.File, path string) string
- func (w *PkgWalker) Import(parentDir string, name string, conf *PkgConfig) (pkg *types.Package, err error)
- func (w *PkgWalker) LookupCursor(pkg *types.Package, conf *PkgConfig, cursor *FileCursor)
- func (w *PkgWalker) LookupIdentComment(value token.Pos) *ast.CommentGroup
- func (w *PkgWalker) LookupImport(pkg *types.Package, pkgInfo *types.Info, cursor *FileCursor, ...)
- func (w *PkgWalker) LookupMethodRecvObject(fn *types.Func) types.Object
- func (w *PkgWalker) LookupObjects(conf *PkgConfig, cursor *FileCursor)
- func (w *PkgWalker) LookupStructFromField(info *types.Info, cursorPkg *types.Package, cursorObj types.Object, ...) types.Object
- type Rename
Constants ¶
This section is empty.
Variables ¶
var ObjKindName = []string{"none", "package", "packagex", "import",
"type", "interface", "struct",
"const", "var", "field",
"func", "method",
"label", "builtin", "nil", "implicit", "unknown"}
Functions ¶
func AllPackages ¶
AllPackages returns the package path of each Go package in any source directory of the specified build context (e.g. $GOROOT or an element of $GOPATH). Errors are ignored. The results are sorted. All package paths are canonical, and thus may contain "/vendor/".
The result may include import paths for directories that contain no *.go files, such as "archive" (in $GOROOT/src).
All I/O is done via the build.Context file system interface, which must be concurrency-safe.
func ExpandPatterns ¶
ExpandPatterns returns the set of packages matched by patterns, which may have the following forms:
golang.org/x/tools/cmd/guru # a single package golang.org/x/tools/... # all packages beneath dir ... # the entire workspace.
Order is significant: a pattern preceded by '-' removes matching packages from the set. For example, these patterns match all encoding packages except encoding/xml:
encoding/... -encoding/xml
func ForEachPackage ¶
ForEachPackage calls the found function with the package path of each Go package it finds in any source directory of the specified build context (e.g. $GOROOT or an element of $GOPATH). All package paths are canonical, and thus may contain "/vendor/".
If the package directory exists but could not be read, the second argument to the found function provides the error.
All I/O is done via the build.Context file system interface, which must be concurrency-safe.
func ImportPackage ¶
func IsSameObject ¶
Types ¶
type FileCursor ¶
type FileCursor struct {
// contains filtered or unexported fields
}
type ObjList ¶
type ObjList struct { Kind ObjKind Ident *ast.Ident Obj types.Object List []int IsTestFunc bool IsAnonymous bool }
func LookupObjList ¶
type PkgConfig ¶
type PkgConfig struct { IgnoreFuncBodies bool AllowBinary bool WithTestFiles bool Cursor *FileCursor Pkg *types.Package XPkg *types.Package Info *types.Info XInfo *types.Info Files []*ast.File TestFiles []*ast.File XTestFiles []*ast.File Dir string }
func DefaultPkgConfig ¶
func DefaultPkgConfig() *PkgConfig
type PkgWalker ¶
type PkgWalker struct { FileSet *token.FileSet Context *build.Context // contains filtered or unexported fields }
func NewPkgWalker ¶
func (*PkgWalker) CheckIsImport ¶
func (w *PkgWalker) CheckIsImport(cursor *FileCursor) *ast.ImportSpec
func (*PkgWalker) FindDeclForPos ¶
func (*PkgWalker) FindImportName ¶
func (*PkgWalker) LookupCursor ¶
func (w *PkgWalker) LookupCursor(pkg *types.Package, conf *PkgConfig, cursor *FileCursor)
func (*PkgWalker) LookupIdentComment ¶
func (w *PkgWalker) LookupIdentComment(value token.Pos) *ast.CommentGroup
func (*PkgWalker) LookupImport ¶
func (w *PkgWalker) LookupImport(pkg *types.Package, pkgInfo *types.Info, cursor *FileCursor, is *ast.ImportSpec)
func (*PkgWalker) LookupMethodRecvObject ¶
func (*PkgWalker) LookupObjects ¶
func (w *PkgWalker) LookupObjects(conf *PkgConfig, cursor *FileCursor)