packages

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2017 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package packages provides Go package traversal in a Bazel repository.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PreprocessTags added in v0.5.0

func PreprocessTags(genericTags map[string]bool, platforms PlatformConstraints)

PreprocessTags performs some automatic processing on generic and platform-specific tags before they are used to match files.

func Walk

func Walk(buildTags map[string]bool, platforms PlatformConstraints, repoRoot, goPrefix, dir string, f WalkFunc) error

Walk walks through directories under "root". It calls back "f" for each package.

It 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, a *build.MultiplePackageError error is returned.

Types

type Package added in v0.5.0

type Package struct {
	Dir  string
	Name string

	Library, CgoLibrary, Binary, Test, XTest Target

	Protos  []string
	HasPbGo 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 FindPackage added in v0.5.0

func FindPackage(dir string, buildTags map[string]bool, platforms PlatformConstraints, repoRoot, goPrefix string) (*Package, error)

FindPackage reads source files in a given directory and returns a Package containing information about those files and how to build them.

If no buildable .go files are found in the directory, *build.NoGoError will be returned. If buildable .go files from multiple packages are found in a directory, *build.MultiplePackageError will be returned. Various I/O and parse errors are also possible.

func (*Package) HasGo added in v0.5.0

func (p *Package) HasGo() bool

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) IsCommand added in v0.5.0

func (p *Package) IsCommand() bool

IsCommand returns true if the package name is "main".

type PlatformConstraints added in v0.5.0

type PlatformConstraints map[string]map[string]bool

PlatformConstraints is a map from config_setting labels (for example, "@io_bazel_rules_go//go/platform:linux_amd64") to a sets of build tags that are true on each platform (for example, "linux,amd64").

var DefaultPlatformConstraints PlatformConstraints

DefaultPlatformConstraints is the default set of platforms that Gazelle will generate files for. These are the platforms that both Go and Bazel support.

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 to the strings in "ps" and returns a new PlatformStrings with the results. This is useful for converting import paths to labels.

type Target added in v0.5.0

type Target struct {
	Sources, Imports PlatformStrings
	COpts, CLinkOpts PlatformStrings
}

Target contains metadata about a buildable Go target in a package.

func (*Target) HasGo added in v0.5.0

func (t *Target) HasGo() bool

type WalkFunc

type WalkFunc func(pkg *Package) error

A WalkFunc is a callback called by Walk for each package.

Jump to

Keyboard shortcuts

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