Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindRuleWithOverride ¶
FindRuleWithOverride searches the current configuration for user-specified dependency resolution overrides. Overrides specified later (in configuration files in deeper directories, or closer to the end of the file) are returned first. If no override is found, label.NoLabel is returned.
Types ¶
type Configurer ¶
type Configurer struct{}
func (*Configurer) CheckFlags ¶
func (*Configurer) KnownDirectives ¶
func (*Configurer) KnownDirectives() []string
func (*Configurer) RegisterFlags ¶
type CrossResolver ¶ added in v0.22.0
type CrossResolver interface { // CrossResolve attempts to resolve an import string to a rule for languages // other than the implementing extension. lang is the langauge of the rule // with the dependency. CrossResolve(c *config.Config, ix *RuleIndex, imp ImportSpec, lang string) []FindResult }
CrossResolver is an interface that language extensions can implement to provide custom dependency resolution logic for other languages.
type FindResult ¶
type FindResult struct { // Label is the absolute label (including repository and package name) for // a matched rule. Label label.Label // Embeds is the transitive closure of labels for rules that the matched // rule embeds. It may contains duplicates and does not include the label // for the rule itself. Embeds []label.Label }
func (FindResult) IsSelfImport ¶
func (r FindResult) IsSelfImport(from label.Label) bool
IsSelfImport returns true if the result's label matches the given label or the result's rule transitively embeds the rule with the given label. Self imports cause cyclic dependencies, so the caller may want to omit the dependency or report an error.
type ImportSpec ¶
type ImportSpec struct {
Lang, Imp string
}
ImportSpec describes a library to be imported. Imp is an import string for the library. Lang is the language in which the import string appears (this should match Resolver.Name).
type Resolver ¶
type Resolver interface { // Name returns the name of the language. This should be a prefix of the // kinds of rules generated by the language, e.g., "go" for the Go extension // since it generates "go_library" rules. Name() string // Imports returns a list of ImportSpecs that can be used to import the rule // r. This is used to populate RuleIndex. // // If nil is returned, the rule will not be indexed. If any non-nil slice is // returned, including an empty slice, the rule will be indexed. Imports(c *config.Config, r *rule.Rule, f *rule.File) []ImportSpec // Embeds returns a list of labels of rules that the given rule embeds. If // a rule is embedded by another importable rule of the same language, only // the embedding rule will be indexed. The embedding rule will inherit // the imports of the embedded rule. Embeds(r *rule.Rule, from label.Label) []label.Label // Resolve translates imported libraries for a given rule into Bazel // dependencies. Information about imported libraries is returned for each // rule generated by language.GenerateRules in // language.GenerateResult.Imports. Resolve generates a "deps" attribute (or // the appropriate language-specific equivalent) for each import according to // language-specific rules and heuristics. Resolve(c *config.Config, ix *RuleIndex, rc *repo.RemoteCache, r *rule.Rule, imports interface{}, from label.Label) }
Resolver is an interface that language extensions can implement to resolve dependencies in rules they generate.
type RuleIndex ¶
type RuleIndex struct {
// contains filtered or unexported fields
}
RuleIndex is a table of rules in a workspace, indexed by label and by import path. Used by Resolver to map import paths to labels.
func NewRuleIndex ¶
NewRuleIndex creates a new index.
kindToResolver is a map from rule kinds (for example, "go_library") to Resolvers that support those kinds.
func (*RuleIndex) AddRule ¶
AddRule adds a rule r to the index. The rule will only be indexed if there is a known resolver for the rule's kind and Resolver.Imports returns a non-nil slice.
AddRule may only be called before Finish.
func (*RuleIndex) FindRulesByImport ¶
func (ix *RuleIndex) FindRulesByImport(imp ImportSpec, lang string) []FindResult
FindRulesByImport attempts to resolve an import string to a rule record. imp is the import to resolve (which includes the target language). lang is the language of the rule with the dependency (for example, in go_proto_library, imp will have ProtoLang and lang will be GoLang). from is the rule which is doing the dependency. This is used to check vendoring visibility and to check for self-imports.
FindRulesByImport returns a list of rules, since any number of rules may provide the same import. Callers may need to resolve ambiguities using language-specific heuristics.
DEPRECATED: use FindRulesByImportWithConfig instead
func (*RuleIndex) FindRulesByImportWithConfig ¶ added in v0.22.0
func (ix *RuleIndex) FindRulesByImportWithConfig(c *config.Config, imp ImportSpec, lang string) []FindResult
FindRulesByImportWithConfig attempts to resolve an import to a rule first by checking the rule index, then if no matches are found any registered CrossResolve implementations are called.
func (*RuleIndex) Finish ¶
func (ix *RuleIndex) Finish()
Finish constructs the import index and performs any other necessary indexing actions after all rules have been added. This step is necessary because a rule may be indexed differently based on what rules are added later.
Finish must be called after all AddRule calls and before any FindRulesByImport calls.