diff.bzlAPI docs @0.4.3

@diff.bzl@diff.bzl//diff:defs.bzl

Public diff.bzl API re-exports

Functions & Macros

cmp

Runs cmp (binary diff) between two files and returns the output.

Parameters
*name

The name of the rule

*file1

The first file to compare

*file2

The second file to compare

args

Additional arguments to pass to cmp

Default: []
out

The output file to write the output of cmp to. Defaults to ${name}.out.

Default: None
kwargs

Additional arguments to pass to the underlying rule.

diff

Runs a diff between two files and return a patch.

Parameters
*name

The name of the rule

*file1

The first file to compare

*file2

The second file to compare

args

Additional arguments to pass to diff

Default: ["--unified"]
patch

The output file to write the diff to. Defaults to ${name}.patch.

Default: None
kwargs

Additional arguments to pass to the underlying rule

@diff.bzl@diff.bzl//diff:extensions.bzl

Extensions for bzlmod

Module Extensions

diffutils

Module extension for installing a diffutils toolchain based on prebuilt GNU diffutils
binaries from https://github.com/kormide/diffutils-prebuilt.

Every module can define a toolchain version under the default name, "diffutils".
The latest of those versions will be selected (the rest discarded),
and will always be registered by diff.bzl.

Additionally, the root module can define arbitrarily many more toolchain versions under different
names (the latest version will be picked for each name) and can register them as it sees fit,
effectively overriding the default named toolchain due to toolchain resolution precedence.

Tag Classes
toolchain
AttributeTypeDescription
namename

Base name for generated repositories, allowing more than one diffutils toolchain to be registered.
Overriding the default is only permitted in the root module.

A host toolchain repo is set up using {name} so that hermetically fetched diffutils binaries
can be run with bazel run, e.g.,

bazel run @diffutils//:diff $FILE1 $FILE2
Default: "diffutils"
diffutils_versionstring

Explicit version of GNU prebuilt diffutils binaries.

Default: "3.12"

@diff.bzl//diff:defs.bzl

Public diff.bzl API re-exports

Functions & Macros

cmp

Runs cmp (binary diff) between two files and returns the output.

Parameters
*name

The name of the rule

*file1

The first file to compare

*file2

The second file to compare

args

Additional arguments to pass to cmp

Default: []
out

The output file to write the output of cmp to. Defaults to ${name}.out.

Default: None
kwargs

Additional arguments to pass to the underlying rule.

diff

Runs a diff between two files and return a patch.

Parameters
*name

The name of the rule

*file1

The first file to compare

*file2

The second file to compare

args

Additional arguments to pass to diff

Default: ["--unified"]
patch

The output file to write the diff to. Defaults to ${name}.patch.

Default: None
kwargs

Additional arguments to pass to the underlying rule

@diff.bzl//diff:extensions.bzl

Extensions for bzlmod

Module Extensions

diffutils

Module extension for installing a diffutils toolchain based on prebuilt GNU diffutils
binaries from https://github.com/kormide/diffutils-prebuilt.

Every module can define a toolchain version under the default name, "diffutils".
The latest of those versions will be selected (the rest discarded),
and will always be registered by diff.bzl.

Additionally, the root module can define arbitrarily many more toolchain versions under different
names (the latest version will be picked for each name) and can register them as it sees fit,
effectively overriding the default named toolchain due to toolchain resolution precedence.

Tag Classes
toolchain
AttributeTypeDescription
namename

Base name for generated repositories, allowing more than one diffutils toolchain to be registered.
Overriding the default is only permitted in the root module.

A host toolchain repo is set up using {name} so that hermetically fetched diffutils binaries
can be run with bazel run, e.g.,

bazel run @diffutils//:diff $FILE1 $FILE2
Default: "diffutils"
diffutils_versionstring

Explicit version of GNU prebuilt diffutils binaries.

Default: "3.12"

@diff.bzl//diff:repositories.bzl

Declare runtime dependencies

These are needed for local dev, and users must install them as well.
See https://docs.bazel.build/versions/main/skylark/deploying.html#dependencies

Functions & Macros

diffutils_register_toolchains

Convenience macro for users which does typical setup.

  • creates a repository for each built-in platform like "diff_linux_amd64"
  • creates a repository exposing toolchains for each platform in "diffutils_toolchains"
  • registers a toolchain pointing at each platform
    Users can avoid this macro and do these steps themselves, if they want more control.
Parameters
*name

base name for all created repos, like "diff1_14"

*diffutils_version

Version of diffutils prebuilt binaries to download

register

whether to call through to native.register_toolchains.
Should be True for WORKSPACE users, but false when used under bzlmod extension

Default: True
kwargs

passed to each diff_repositories call

Repository Rules

diffutils_repository

Fetch external tools needed for diffutils toolchain

AttributeTypeDescription
*namename

A unique name for this repository.

*diffutils_versionstring

Version of diffutils binaries to download

*platformstring

Platform to download binaries for

diffutils_host_alias_repo

Creates a diffutils repository with a shorter name meant for the host platform, which contains
a BUILD.bazel file that exports symlinks to the host platform's binaries.

AttributeTypeDescription
*namename

A unique name for this repository.

@diff.bzl//diff:toolchain.bzl

Implement the language-specific toolchain rule.

Rules

diffutils_toolchain
AttributeTypeDescription
*namename

A unique name for this target.

*cmp_binlabel

A hermetically downloaded cmp binary.

*diff_binlabel

A hermetically downloaded diff binary.

*diff3_binlabel

A hermetically downloaded diff3 binary.

*sdiff_binlabel

A hermetically downloaded sdiff binary.

Providers

DiffutilsInfo

Information about how to invoke the tool executable

Fields
cmp_bin

diffutils cmp binary

diff_bin

diffutils diff binary

diff3_bin

diffutils diff3 binary

sdiff_bin

diffutils sdiff binary