Documentation
¶
Index ¶
- func AbsolutePath(target *build.Target) string
- func AttributeForSerialization(rawAttr *build.Attribute) *build.Attribute
- func BazelOutputBase(bazelPath string, workspacePath string) (string, error)
- func BazelRelease(bazelPath string, workspacePath string) (string, error)
- func CompareLabels(a, b label.Label) bool
- func DiffSingleLabel(beforeMetadata, afterMetadata *QueryResults, includeDifferences bool, ...) error
- func EnsureGitRepositoryClean(workingDirectory string, ignoredFiles []common.RelPath) (bool, error)
- func FullyProcess(context *Context, revBefore LabelledGitRev, pattern label.Pattern) (*QueryResults, *QueryResults, error)
- func GitRevParse(workingDirectory string, rev string, isAbbrevRef bool) (string, error)
- func ParseCqueryResult(result *analysis.CqueryResult) (map[label.Label]map[Configuration]*analysis.ConfiguredTarget, error)
- func WalkAffectedTargets(context *Context, revBefore LabelledGitRev, pattern label.Pattern, ...) error
- type Configuration
- type Context
- type Difference
- type GitFileStatus
- type LabelAndConfiguration
- type LabelAndConfigurations
- type LabelledGitRev
- type MatchingTargets
- type QueryResults
- type TargetHashCache
- type WalkCallback
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbsolutePath ¶
AbsolutePath returns the absolute path to the source file Target. It assumes the passed Target is of type Source File.
func AttributeForSerialization ¶
AttributeForSerialization redacts details about an attribute which don't affect the output of building them, and returns equivalent canonical attribute metadata. In particular it redacts:
- Whether an attribute was explicitly specified (because the effective value is all that matters).
- Any attribute named `generator_location`, because these point to absolute paths for built-in `cc_toolchain_suite` targets such as `@local_config_cc//:toolchain`.
func BazelRelease ¶ added in v0.3.0
func CompareLabels ¶
func DiffSingleLabel ¶
func DiffSingleLabel(beforeMetadata, afterMetadata *QueryResults, includeDifferences bool, label label.Label, callback WalkCallback) error
func FullyProcess ¶
func FullyProcess(context *Context, revBefore LabelledGitRev, pattern label.Pattern) (*QueryResults, *QueryResults, error)
FullyProcess returns the before and after metadata maps, with fully filled caches.
func GitRevParse ¶
func ParseCqueryResult ¶
func ParseCqueryResult(result *analysis.CqueryResult) (map[label.Label]map[Configuration]*analysis.ConfiguredTarget, error)
func WalkAffectedTargets ¶
func WalkAffectedTargets(context *Context, revBefore LabelledGitRev, pattern label.Pattern, includeDifferences bool, callback WalkCallback) error
WalkAffectedTargets computes which targets have changed between two commits, and calls callback once for each target which has changed. Explanation of the differences may be expensive in both time and memory to compute, so if includeDifferences is set to false, the []Difference parameter to the callback will always be nil.
Types ¶
type Configuration ¶
type Configuration string
type Context ¶
type Context struct {
// WorkspacePath is the absolute path to the root of the project's Bazel Workspace directory (which is
// assumed to be in a git repository, but is not assumed to be the root of a git repository).
WorkspacePath string
// OriginalRevision is the git revision the repo was in when initializing the context.
OriginalRevision LabelledGitRev
// BazelPath is the path (or basename to be looked up in $PATH) of the Bazel to invoke.
BazelPath string
// BazelOutputBase is the path of the Bazel output base directory of the original workspace.
BazelOutputBase string
// DeleteCachedWorktree represents whether we should keep worktrees around for reuse in future invocations.
DeleteCachedWorktree bool
// IgnoredFiles represents files that should be ignored for git operations.
IgnoredFiles []common.RelPath
}
type Difference ¶
type Difference struct {
// Category is the kind of change, e.g. that the target is new, that a file changed, etc.
Category string
// Key is the thing which changed, e.g. the name of an attribute, or the name of the input file.
Key string
// Before is the value of Key before the change.
Before string
// After is the value of Key after the change.
After string
}
Difference represents a difference of a target between two commits. All fields except Category are optional.
func WalkDiffs ¶
func WalkDiffs(before *TargetHashCache, after *TargetHashCache, labelAndConfiguration LabelAndConfiguration) ([]Difference, error)
WalkDiffs accumulates the differences of a LabelAndConfiguration before and after a change.
func (Difference) String ¶
func (d Difference) String() string
type GitFileStatus ¶
type GitFileStatus struct {
// Status contains the shorthand notation of the status of the file. See `man git-status` for a mapping.
Status string
// FilePath represents the path of the file relative to the git repository.
FilePath common.RelPath
}
func (GitFileStatus) String ¶
func (s GitFileStatus) String() string
type LabelAndConfiguration ¶
type LabelAndConfiguration struct {
Label label.Label
Configuration Configuration
}
type LabelAndConfigurations ¶
type LabelAndConfigurations struct {
Label label.Label
Configurations []Configuration
}
type LabelledGitRev ¶
type LabelledGitRev struct {
// Revision represents the git sha or ref. These values must be absolute.
// A value such as "HEAD^" first needs to be resolved to the relevant commit.
Revision string
// Label is a description of what the git sha represents which may be useful to humans.
Label string
// Sha is the resolved sha256 of the Revision.
Sha string
}
var NoLabelledGitRev LabelledGitRev
NoLabelledGitRev represents a null value for LabelledGitRev.
func NewLabelledGitRev ¶
func NewLabelledGitRev(workspacePath string, revision string, label string) (LabelledGitRev, error)
NewLabelledGitRev ensures that the git sha is resolved as soon as the object is created, otherwise we might encounter undesirable behaviors when switching to other revisions e.g. if using "HEAD".
func (LabelledGitRev) String ¶
func (l LabelledGitRev) String() string
type MatchingTargets ¶
type MatchingTargets struct {
// contains filtered or unexported fields
}
MatchingTargets stores the top-level targets within a repository, i.e. those matching the Bazel pattern `...`.
func (*MatchingTargets) ConfigurationsFor ¶
func (mt *MatchingTargets) ConfigurationsFor(label label.Label) []Configuration
func (*MatchingTargets) ContainsLabelAndConfiguration ¶
func (mt *MatchingTargets) ContainsLabelAndConfiguration(label label.Label, configuration Configuration) bool
func (*MatchingTargets) Labels ¶
func (mt *MatchingTargets) Labels() []label.Label
type QueryResults ¶
type QueryResults struct {
MatchingTargets *MatchingTargets
TransitiveConfiguredTargets map[label.Label]map[Configuration]*analysis.ConfiguredTarget
TargetHashCache *TargetHashCache
BazelRelease string
}
func LoadIncompleteMetadata ¶
func LoadIncompleteMetadata(context *Context, rev LabelledGitRev, pattern label.Pattern) (*QueryResults, func(), error)
LoadIncompleteMetadata loads the metadata about, but not hashes of, targets into a QueryResults. The (transitive) dependencies of the passed pattern will be loaded. For all targets, pass the pattern `//...`.
It may change the git revision of the workspace to rev, in which case it is the caller's responsibility to check out the original commit.
It returns a non-nil callback to clean up the worktree if it was created.
func (*QueryResults) PrefillCache ¶
func (queryInfo *QueryResults) PrefillCache() error
type TargetHashCache ¶
type TargetHashCache struct {
// contains filtered or unexported fields
}
TargetHashCache caches hash computations for targets and files, so that transitive hashes can be cheaply computed via dynamic programming. Note that a TargetHashCache doesn't eagerly read files, it lazily reads them when they're needed for hash computation, so if you're going to mutate filesystem state after creating a TargetHashCache (e.g. because you're going to check out a different commit), you should pre-compute any hashes you're interested in before mutating the filesystem. In the future we may pre-cache file hashes to avoid this hazard (and to allow more efficient use of threadpools when hashing files).
func NewTargetHashCache ¶
func NewTargetHashCache(context map[gazelle_label.Label]map[Configuration]*analysis.ConfiguredTarget, bazelRelease string) *TargetHashCache
NewTargetHashCache creates a TargetHashCache which uses context for metadata lookups.
func (*TargetHashCache) Freeze ¶
func (thc *TargetHashCache) Freeze()
Freeze should be called before the filesystem is mutated to signify to the TargetHashCache that any future Hash calls which need to read files should fail, because the files may no longer be accurate from when the TargetHashCache was created.
func (*TargetHashCache) Hash ¶
func (thc *TargetHashCache) Hash(labelAndConfiguration LabelAndConfiguration) ([]byte, error)
Hash hashes a given LabelAndConfiguration, returning a sha256 which will change if any of the following change:
- Values of attributes of the label (if it's a rule)
- Contents of source files which are direct inputs to the rule (if it's a rule).
- The name of the rule class (e.g. `java_binary`) of the rule (if it's a rule).
- The rule definition, if it's a rule which was implemented in starlark. Note that this is known to over-estimate - it currently factors in the whole contents of any .bzl files loaded to define the rule, where some of this contents may not be relevant.
- The configuration the label is configured in. Note that this is known to over-estimate - per-language fragments are not filtered from this configuration, which means C++-affecting options are considered to affect Java.
- The above recursively for all rules and files which are depended on by the given LabelAndConfiguration. Note that this is known to over-estimate - the configuration of dependencies isn't easily surfaced by Bazel, so if a dependency exists in multiple configurations, all of them will be mixed into the hash, even if only one of the configurations is actually relevant. See https://github.com/bazelbuild/bazel/issues/14610
func (*TargetHashCache) KnownConfigurations ¶
func (thc *TargetHashCache) KnownConfigurations(label gazelle_label.Label) *ss.SortedSet[Configuration]
KnownConfigurations returns the configurations in which a Label is known to be configured.
type WalkCallback ¶
type WalkCallback func(label.Label, []Difference, *analysis.ConfiguredTarget)