• Stars
    star
    131
  • Rank 275,867 (Top 6 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Determines which Bazel targets were affected between two git commits.

Target Determinator

Target determinator is a binary (and Go API) used to determine which Bazel targets changed between two git commits.

target-determinator binary

For simple listing, the target-determinator binary is supplied:

Usage of target-determinator:
target-determinator <before-revision>
Where <before-revision> may be any commit revision - full commit hashes, short commit hashes, tags, branches, etc.
  -bazel string
    	Bazel binary (basename on $PATH, or absolute or relative path) to run (default "bazel")
  -ignore-file value
    	Files to ignore for git operations, relative to the working-directory. These files shan't affect the Bazel graph.
  -targets bazel query
      Targets to consider. Accepts any valid bazel query expression (see https://bazel.build/reference/query). (default "//...")
  -verbose
    	Whether to explain (messily) why each target is getting run
  -working-directory string
    	Working directory to query (default ".")

This binary lists targets to stdout, one-per-line, which were affected between and the currently checked-out revision.

driver binary

driver is a binary which implements a simple CI pipeline; it runs the same logic as target-determinator, then tests all identified targets.

Usage of driver:
  driver <before-revision>
Where <before-revision> may be any commit-like strings - full commit hashes, short commit hashes, tags, branches, etc.
Optional flags:
  -bazel string
    	Bazel binary (basename on $PATH, or absolute or relative path) to run (default "bazel")
  -ignore-file value
    	Files to ignore for git operations, relative to the working-directory. These files shan't affect the Bazel graph.
  -manual-test-mode string
    	How to handle affected tests tagged manual. Possible values: run|skip (default "skip")
  -targets bazel query
      Targets to consider. Accepts any valid bazel query expression (see https://bazel.build/reference/query). (default "//...")
  -working-directory string
    	Working directory to query (default ".")

WalkAffectedTargets API

Both of the above binaries are thin wrappers around a Go function called WalkAffectedTargets which calls a user-supplied callback for each affected target between two commits:

// 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.
func WalkAffectedTargets(context *Context, commitishBefore, commitishAfter LabelledGitRev, pattern label.Pattern, includeDifferences bool, callback WalkCallback) error { ... }

type WalkCallback func(label.Label, []Difference, *analysis.ConfiguredTarget)

This can be used to flexibly build your own logic handling the affected targets to drive whatever analysis you want.

Contributing

Contributions are very welcome!

We have an extensive integration testing suite in the tests/integration directory which has its own README. The test suite also runs against several other target determinator implementations which are pulled in as http_archives, to test compatibility. Please make sure any contributions are covered by a test.

When adding new dependencies to the Go code, please run scripts/update-dependencies.

In general, BUILD files in this repo are maintained by gazelle; to regenerate tem, please run bazel run //:gazelle.

Alongside each go_proto_library, there is a runnable copy_proto_output rule which can be used to generate the Go source for a protobuf, in case it's useful to inspect.

Supported Bazel versions

Target Determinator currently supports Bazel 4.0.0 up to and including the latest LTS release.

We are happy to support newer Bazel versions (as long as this doesn't break support for the current LTS), but only exhaustively test against the latest LTS release.

We have a small number of smoke tests which verify basic functionality on the oldest supported release, but do not regularly test against it.

More Repositories

1

rules_nodejs

NodeJS toolchain for Bazel.
Starlark
727
star
2

rules_foreign_cc

Build rules for interfacing with "foreign" (non-Bazel) build systems (CMake, configure-make, GNU Make, boost, ninja, Meson)
Starlark
662
star
3

rules_jvm_external

Bazel rules to resolve, fetch and export Maven artifacts
Starlark
324
star
4

toolchains_llvm

LLVM toolchain for bazel
Starlark
294
star
5

rules_oci

Bazel rules for building OCI containers
Starlark
265
star
6

vscode-bazel

Bazel support for Visual Studio Code
TypeScript
241
star
7

rules_dotnet

.NET rules for Bazel
Starlark
190
star
8

bazel-lib

Common useful functions for writing BUILD files and Starlark macros/rules
Starlark
137
star
9

bazel-mypy-integration

🐍🌿💚 Integrate MyPy type-checking into your Python Bazel builds
Starlark
119
star
10

rules_fuzzing

Bazel Starlark extensions for defining fuzz tests in Bazel projects
Starlark
87
star
11

rules_cuda

Starlark implementation of bazel rules for CUDA.
Starlark
83
star
12

rules_jsonnet

Jsonnet rules for Bazel
Starlark
69
star
13

rules_jvm

Contributed Bazel rules that make working with java projects more pleasant
Java
46
star
14

rules-template

A template for creating a new Bazel ruleset
Starlark
45
star
15

rules_bazel_integration_test

Rules and macros for executing integration tests that use Bazel. Supports running integration tests with multiple versions of Bazel.
Starlark
40
star
16

rules_debian_packages

Rules for installing debian-packages into Docker-Images with bazel
Starlark
23
star
17

SIG-rules-authors

Governance and admin for the rules authors Special Interest Group
Shell
22
star
18

publish-to-bcr

A GitHub app that mirrors releases of your Bazel ruleset to the Central Registry
TypeScript
21
star
19

Bazel-learning-paths

Bazel training materials and codelabs focused on beginner, advanced and contributor learning paths
Java
19
star
20

bazel_features

Support Bazel "feature detection" from starlark
Starlark
17
star
21

musl-toolchain

Python
14
star
22

unused-jvm-deps

Tool to remove unused deps entries for Java
Java
14
star
23

bcr-ui

Website for the Bazel Central Registry
TypeScript
10
star
24

bazel-catalog

Catalog of Bazel rules. http://awesomebazel.com meets https://bazel.build/rules plus live stats.
Shell
3
star
25

target-determinator-testdata

Sample commits used to test implementations of target determinators.
1
star
26

.github

GitHub metadata for the org
1
star