Documentation ¶
Index ¶
Constants ¶
const ( // RulesGoRepoName is the canonical name of the rules_go repository. It must // match the workspace name in WORKSPACE. RulesGoRepoName = "io_bazel_rules_go" // DefaultLibName is the name of the default go_library rule in a Go // package directory. It must be consistent to DEFAULT_LIB in go/private/common.bf. DefaultLibName = "go_default_library" // DefaultTestName is a name of an internal test corresponding to // DefaultLibName. It does not need to be consistent to something but it // just needs to be unique in the Bazel package DefaultTestName = "go_default_test" // DefaultXTestName is a name of an external test corresponding to // DefaultLibName. DefaultXTestName = "go_default_xtest" // DefaultProtosName is the name of a filegroup created // whenever the library contains .pb.go files DefaultProtosName = "go_default_library_protos" // DefaultCgoLibName is the name of the default cgo_library rule in a Go package directory. DefaultCgoLibName = "cgo_default_library" // WellKnownTypesProtoRepo is the repository containing proto_library rules // for the Well Known Types. WellKnownTypesProtoRepo = "com_google_protobuf" // WellKnownTypesGoProtoRepo is the repository containing go_library rules // for the Well Known Types. WellKnownTypesGoProtoRepo = "com_github_golang_protobuf" // WellKnownTypesGoPrefix is the import path for the Go repository containing // pre-generated code for the Well Known Types. WellKnownTypesGoPrefix = "github.com/golang/protobuf" // GazelleImportsKey is an internal attribute that lists imported packages // on generated rules. It is replaced with "deps" during import resolution. GazelleImportsKey = "_gazelle_imports" )
Variables ¶
var ( // KnownOSs is the sorted list of operating systems that Go supports. KnownOSs []string // KnownOSSet is the set of operating systems that Go supports. KnownOSSet map[string]bool // KnownArchs is the sorted list of architectures that Go supports. KnownArchs []string // KnownArchSet is the set of architectures that Go supports. KnownArchSet map[string]bool )
var DefaultValidBuildFileNames = []string{"BUILD.bazel", "BUILD"}
var KnownPlatforms = []Platform{
{"android", "386"},
{"android", "amd64"},
{"android", "arm"},
{"android", "arm64"},
{"darwin", "386"},
{"darwin", "amd64"},
{"darwin", "arm"},
{"darwin", "arm64"},
{"dragonfly", "amd64"},
{"freebsd", "386"},
{"freebsd", "amd64"},
{"freebsd", "arm"},
{"linux", "386"},
{"linux", "amd64"},
{"linux", "arm"},
{"linux", "arm64"},
{"linux", "mips"},
{"linux", "mips64"},
{"linux", "mips64le"},
{"linux", "mipsle"},
{"linux", "ppc64"},
{"linux", "ppc64le"},
{"linux", "s390x"},
{"nacl", "386"},
{"nacl", "amd64p32"},
{"nacl", "arm"},
{"netbsd", "386"},
{"netbsd", "amd64"},
{"netbsd", "arm"},
{"openbsd", "386"},
{"openbsd", "amd64"},
{"openbsd", "arm"},
{"plan9", "386"},
{"plan9", "amd64"},
{"plan9", "arm"},
{"solaris", "amd64"},
{"windows", "386"},
{"windows", "amd64"},
}
KnownPlatforms is the set of target platforms that Go supports. Gazelle will generate multi-platform build files using these tags. rules_go and Bazel may not actually support all of these.
Functions ¶
func CheckPrefix ¶ added in v0.8.1
CheckPrefix checks that a string may be used as a prefix. We forbid local (relative) imports and those beginning with "/". We allow the empty string, but generated rules must not have an empty importpath.
Types ¶
type Config ¶
type Config struct { // Dirs is a list of absolute paths to directories where Gazelle should run. Dirs []string // RepoRoot is the absolute path to the root directory of the repository. RepoRoot string // ValidBuildFileNames is a list of base names that are considered valid // build files. Some repositories may have files named "BUILD" that are not // used by Bazel and should be ignored. Must contain at least one string. ValidBuildFileNames []string // GenericTags is a set of build constraints that are true on all platforms. // It should not be nil. GenericTags BuildTags // GoPrefix is the portion of the import path for the root of this repository. // This is used to map imports to labels within the repository. GoPrefix string // GoPrefixRel is the slash-separated path to the directory where GoPrefix // was set, relative to the repository root. "" for the repository root. GoPrefixRel string // ShouldFix determines whether Gazelle attempts to remove and replace // usage of deprecated rules. ShouldFix bool // DepMode determines how imports outside of GoPrefix are resolved. DepMode DependencyMode // KnownImports is a list of imports to add to the external resolver cache. KnownImports []string // ProtoMode determines how rules are generated for protos. ProtoMode ProtoMode }
Config holds information about how Gazelle should run. This is mostly based on command-line arguments.
func ApplyDirectives ¶ added in v0.6.0
ApplyDirectives applies directives that modify the configuration to a copy of c, which is returned. If there are no configuration directives, c is returned unmodified.
func InferProtoMode ¶ added in v0.6.0
InferProtoMode sets Config.ProtoMode, based on the contents of f. If the proto mode is already set to something other than the default, or if the mode is set explicitly in directives, this function does not change it. If the legacy go_proto_library.bzl is loaded, or if this is the Well Known Types repository, legacy mode is used. If go_proto_library is loaded from another file, proto rule generation is disabled.
func (*Config) DefaultBuildFileName ¶
func (*Config) IsValidBuildFileName ¶
func (*Config) PreprocessTags ¶
func (c *Config) PreprocessTags()
PreprocessTags adds some tags which are on by default before they are used to match files.
func (*Config) SetBuildTags ¶ added in v0.6.0
SetBuildTags sets GenericTags by parsing as a comma separated list. An error will be returned for tags that wouldn't be recognized by "go build". PreprocessTags should be called after this.
type DependencyMode ¶
type DependencyMode int
DependencyMode determines how imports of packages outside of the prefix are resolved.
const ( // ExternalMode indicates imports should be resolved to external dependencies // (declared in WORKSPACE). ExternalMode DependencyMode = iota // VendorMode indicates imports should be resolved to libraries in the // vendor directory. VendorMode )
func DependencyModeFromString ¶
func DependencyModeFromString(s string) (DependencyMode, error)
DependencyModeFromString converts a string from the command line to a DependencyMode. Valid strings are "external", "vendor". An error will be returned for an invalid string.
type Directive ¶ added in v0.6.0
type Directive struct {
Key, Value string
}
Directive is a key-value pair extracted from a top-level comment in a build file. Directives have the following format:
# gazelle:key value
Keys may not contain spaces. Values may be empty and may contain spaces, but surrounding space is trimmed.
func ParseDirectives ¶ added in v0.6.0
ParseDirectives scans f for Gazelle directives. The full list of directives is returned. Errors are reported for unrecognized directives and directives out of place (after the first statement).
type Language ¶ added in v0.7.1
type Language int
Language is the name of a programming langauge that Gazelle knows about. This is used to specify import paths.
type Platform ¶ added in v0.7.0
type Platform struct {
OS, Arch string
}
Platform represents a GOOS/GOARCH pair. When Platform is used to describe sources, dependencies, or flags, either OS or Arch may be empty.
type ProtoMode ¶ added in v0.6.0
type ProtoMode int
ProtoMode determines how proto rules are generated.
const ( // DefaultProtoMode generates proto_library and new grpc_proto_library rules. // .pb.go files are excluded when there is a .proto file with a similar name. DefaultProtoMode ProtoMode = iota // DisableProtoMode ignores .proto files. .pb.go files are treated // as normal sources. DisableProtoMode // LegacyProtoMode generates filegroups for .proto files if .pb.go files // are present in the same directory. LegacyProtoMode )