config

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2018 License: Apache-2.0 Imports: 7 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"

	// 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 DefaultValidBuildFileNames = []string{"BUILD.bazel", "BUILD"}

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 CommonConfigurer added in v0.13.0

type CommonConfigurer struct {
	// contains filtered or unexported fields
}

CommonConfigurer handles language-agnostic command-line flags and directives, i.e., those that apply to Config itself and not to Config.Exts.

func (*CommonConfigurer) CheckFlags added in v0.13.0

func (cc *CommonConfigurer) CheckFlags(fs *flag.FlagSet, c *Config) error

func (*CommonConfigurer) Configure added in v0.13.0

func (cc *CommonConfigurer) Configure(c *Config, rel string, f *rule.File)

func (*CommonConfigurer) KnownDirectives added in v0.13.0

func (cc *CommonConfigurer) KnownDirectives() []string

func (*CommonConfigurer) RegisterFlags added in v0.13.0

func (cc *CommonConfigurer) RegisterFlags(fs *flag.FlagSet, cmd string, c *Config)

type Config

type Config struct {
	// RepoRoot is the absolute, canonical path to the root directory of the
	// repository with all symlinks resolved.
	RepoRoot string

	// RepoName is the name of the repository.
	RepoName string

	// ReadBuildFilesDir is the absolute path to a directory where
	// build files should be read from instead of RepoRoot.
	ReadBuildFilesDir string

	// WriteBuildFilesDir is the absolute path to a directory where
	// build files should be written to instead of RepoRoot.
	WriteBuildFilesDir 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

	// ShouldFix determines whether Gazelle attempts to remove and replace
	// usage of deprecated rules.
	ShouldFix bool

	// Exts is a set of configurable extensions. Generally, each language
	// has its own set of extensions, but other modules may provide their own
	// extensions as well. Values in here may be populated by command line
	// arguments, directives in build files, or other mechanisms.
	Exts map[string]interface{}
}

Config holds information about how Gazelle should run. This is based on command line arguments, directives, other hints in build files.

A Config applies to a single directory. A Config is created for the repository root directory, then copied and modified for each subdirectory.

Config itself contains only general information. Most configuration information is language-specific and is stored in Exts. This information is modified by extensions that implement Configurer.

func New added in v0.13.0

func New() *Config

func (*Config) Clone added in v0.13.0

func (c *Config) Clone() *Config

Clone creates a copy of the configuration for use in a subdirectory. Note that the Exts map is copied, but its contents are not. Configurer.Configure should do this, if needed.

func (*Config) DefaultBuildFileName

func (c *Config) DefaultBuildFileName() string

func (*Config) IsValidBuildFileName

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

type Configurer added in v0.13.0

type Configurer interface {
	// RegisterFlags registers command-line flags used by the extension. This
	// method is called once with the root configuration when Gazelle
	// starts. RegisterFlags may set an initial values in Config.Exts. When flags
	// are set, they should modify these values.
	RegisterFlags(fs *flag.FlagSet, cmd string, c *Config)

	// CheckFlags validates the configuration after command line flags are parsed.
	// This is called once with the root configuration when Gazelle starts.
	// CheckFlags may set default values in flags or make implied changes.
	CheckFlags(fs *flag.FlagSet, c *Config) error

	// KnownDirectives returns a list of directive keys that this Configurer can
	// interpret. Gazelle prints errors for directives that are not recoginized by
	// any Configurer.
	KnownDirectives() []string

	// Configure modifies the configuration using directives and other information
	// extracted from a build file. Configure is called in each directory.
	//
	// c is the configuration for the current directory. It starts out as a copy
	// of the configuration for the parent directory.
	//
	// rel is the slash-separated relative path from the repository root to
	// the current directory. It is "" for the root directory itself.
	//
	// f is the build file for the current directory or nil if there is no
	// existing build file.
	Configure(c *Config, rel string, f *rule.File)
}

Configurer is the interface for language or library-specific configuration extensions. Most (ideally all) modifications to Config should happen via this interface.

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