config

package
v0.0.0-...-c02bc0f Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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"

	// GrpcCompilerLabel is the label for the gRPC compiler plugin, used in the
	// "compilers" attribute of go_proto_library rules.
	GrpcCompilerLabel = "@io_bazel_rules_go//proto:go_grpc"

	// 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

View Source
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

	// KnownOSArchs is a map from OS to the archictures they run on.
	KnownOSArchs map[string][]string

	// KnownArchOSs is a map from architectures to that OSs that run on them.
	KnownArchOSs map[string][]string
)
View Source
var DefaultValidBuildFileNames = []string{"BUILD.bazel", "BUILD"}
View Source
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

func CheckPrefix(prefix string) error

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 BuildTags

type BuildTags map[string]bool

BuildTags is a set of build constraints.

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

	// ProtoMode determines how rules are generated for protos.
	ProtoMode ProtoMode

	// ProtoModeExplicit indicates whether the proto mode was set explicitly.
	ProtoModeExplicit bool
}

Config holds information about how Gazelle should run. This is mostly based on command-line arguments.

func ApplyDirectives

func ApplyDirectives(c *Config, directives []Directive, rel string) *Config

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

func InferProtoMode(c *Config, rel string, f *bf.File, directives []Directive) *Config

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 (c *Config) DefaultBuildFileName() string

func (*Config) IsValidBuildFileName

func (c *Config) IsValidBuildFileName(name string) bool

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

func (c *Config) SetBuildTags(tags string) error

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

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

func ParseDirectives(f *bf.File) []Directive

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

type Language int

Language is the name of a programming langauge that Gazelle knows about. This is used to specify import paths.

const (
	// GoLang marks Go targets.
	GoLang Language = iota

	// ProtoLang marks protocol buffer targets.
	ProtoLang
)

func (Language) String

func (l Language) String() string

type Platform

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.

func (Platform) String

func (p Platform) String() string

String returns OS, Arch, or "OS_Arch" if both are set. This must match the names of config_setting rules in @io_bazel_rules_go//go/platform.

type ProtoMode

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
)

func ProtoModeFromString

func ProtoModeFromString(s string) (ProtoMode, error)

Jump to

Keyboard shortcuts

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