Warning
This ruleset is under active development. The API is subject to breaking changes before a v1 release.
GNU diffutils provides diff, cmp, diff3, and sdiff.
This project provides rules that run these programs as Bazel actions.
By default, the project registers toolchains for prebuilt binaries as diffutils only does source releases. You may alternatively register your own toolchain based on a source build of the diffutils BCR entry (see example).
To install, follow instructions from the release you wish to use.
See the docs folder for rule documentation and examples.
load("@diff.bzl//diff:defs.bzl", "diff")
diff(
name = "patch"
args = ["--unified"],
srcs = ["a.txt", "b.txt"],
patch = "a.patch"
)Pass validate = 1 to diff to create a build validation error when a generated source input diverges from the output tree file.
load("@diff.bzl//diff:defs.bzl", "diff")
diff(
name = "foo",
srcs = [
"foo.pb.go",
":foo_generated",
],
validate = 1
)A build error message with command to run to patch the file will be output.
ERROR: diff command exited with non-zero status.
To accept the diff, run:
(cd $(bazel info workspace); patch -p0 < bazel-out/k8-fastbuild/bin/foo.patch)
This also works for directories.
To validate all diff, cmp, etc. actions by default, set common --@diff.bzl//diff:validate=true in your bazelrc.
This ruleset outputs patches into a distinct diff_bzl__patch output group making it easier for patches to be collected and then applied using automation. See the build & patch example script.