Documentation
¶
Overview ¶
Package packages provides Go package traversal in a Bazel repository.
Index ¶
- func JoinOptions(opts []string) []string
- func Walk(c *config.Config, dir string, f WalkFunc)
- type Package
- type PlatformStrings
- func (ps *PlatformStrings) Clean()
- func (ts *PlatformStrings) HasGo() bool
- func (ts *PlatformStrings) IsEmpty() bool
- func (ps *PlatformStrings) Map(f func(string) (string, error)) (PlatformStrings, []error)
- func (ps *PlatformStrings) MapSlice(f func([]string) ([]string, error)) (PlatformStrings, []error)
- type Target
- type WalkFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JoinOptions ¶ added in v0.5.4
JoinOptions combines shell options grouped by a special separator token and returns a string for each group. The group strings will be escaped such that the original options can be recovered after Bourne shell tokenization.
func Walk ¶
Walk walks through directories under "root". It calls back "f" for each package. If an existing BUILD file is present in the directory, it will be parsed and passed to "f" as well.
Walk is similar to "golang.org/x/tools/go/buildutil".ForEachPackage, but it does not assume the standard Go tree because Bazel rules_go uses go_prefix instead of the standard tree.
If a directory contains no buildable Go code, "f" is not called. If a directory contains one package with any name, "f" will be called with that package. If a directory contains multiple packages and one of the package names matches the directory name, "f" will be called on that package and the other packages will be silently ignored. If none of the package names match the directory name, or if some other error occurs, an error will be logged, and "f" will not be called.
Types ¶
type Package ¶ added in v0.5.0
type Package struct { // Name is the symbol found in package declarations of the .go files in // the package. It does not include the "_test" suffix from external tests. Name string // Dir is an absolute path to the directory that contains the package. Dir string // Rel is the relative path to the package directory from the repository // root. If the directory is the repository root itself, Rel is empty. // Components in Rel are separated with slashes. Rel string Library, Binary, Test, XTest Target Protos []string HasPbGo bool HasTestdata bool }
Package contains metadata about a Go package extracted from a directory. It fills a similar role to go/build.Package, but it separates files by target instead of by type, and it supports multiple platforms.
func (*Package) HasGo ¶ added in v0.5.0
HasGo returns true if at least one target in the package contains a .go source file. If a package does not contain Go code, Gazelle will not generate rules for it.
func (*Package) ImportPath ¶ added in v0.5.4
ImportPath returns the inferred Go import path for this package. This is determined as follows:
- If there is no library target or if Name is "main", "" is returned. This indicates the library cannot be imported.
- If "vendor" is a component in p.Rel, everything after the last "vendor" component is returned.
- Otherwise, prefix joined with Rel is returned.
TODO(jayconrod): extract canonical import paths from comments on package statements.
type PlatformStrings ¶ added in v0.5.0
type PlatformStrings struct { // Generic is a list of strings not specific to any platform. Generic []string // Platform is a map of lists of platform-specific strings. The map is keyed // by the name of the platform. Platform map[string][]string }
PlatformStrings contains a set of strings associated with a buildable Go target in a package. This is used to store source file names, import paths, and flags.
func (*PlatformStrings) Clean ¶ added in v0.5.0
func (ps *PlatformStrings) Clean()
Clean sorts and de-duplicates PlatformStrings. It also removes any strings from platform-specific lists that also appear in the generic list. This is useful for imports.
func (*PlatformStrings) HasGo ¶ added in v0.5.0
func (ts *PlatformStrings) HasGo() bool
func (*PlatformStrings) IsEmpty ¶ added in v0.5.0
func (ts *PlatformStrings) IsEmpty() bool
func (*PlatformStrings) Map ¶ added in v0.5.0
func (ps *PlatformStrings) Map(f func(string) (string, error)) (PlatformStrings, []error)
Map applies a function that processes individual strings to the strings in "ps" and returns a new PlatformStrings with the results.
func (*PlatformStrings) MapSlice ¶ added in v0.5.4
func (ps *PlatformStrings) MapSlice(f func([]string) ([]string, error)) (PlatformStrings, []error)
MapSlice applies a function that processes slices of strings to the strings in "ps" and returns a new PlatformStrings with the results.
type Target ¶ added in v0.5.0
type Target struct {
Sources, Imports PlatformStrings
COpts, CLinkOpts PlatformStrings
Cgo bool
}
Target contains metadata about a buildable Go target in a package.