Skip to content

Commit 1a567fc

Browse files
authored
docs: update readme and rule examples (#41)
1 parent 34c3277 commit 1a567fc

3 files changed

Lines changed: 90 additions & 2 deletions

File tree

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,22 @@ diff(
3030
)
3131
```
3232

33+
### Compare binary files
34+
35+
```starlark
36+
load("@diff.bzl//diff:defs.bzl", "cmp")
37+
38+
cmp(
39+
name = "compare_bins",
40+
args = ["--bytes", "4", "--verbose"],
41+
srcs = ["bin_a", "bin_b"],
42+
out = "cmp_output"
43+
)
44+
```
45+
3346
### Keep generated sources up to date
3447

35-
Pass `validate = 1` to `diff` to create a build validation error when a generated source input diverges from the output tree file.
48+
Pass `validate = 1` to `cmp` or `diff` to create a build validation error when a generated source input diverges from the output tree file.
3649

3750
```starlark
3851
load("@diff.bzl//diff:defs.bzl", "diff")
@@ -47,7 +60,7 @@ diff(
4760
)
4861
```
4962

50-
A build error message with command to run to patch the file will be output.
63+
An error message with command to run to patch the file will be output.
5164

5265
```
5366
ERROR: diff command exited with non-zero status.

diff/defs.bzl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ load("//diff/private:diff.bzl", "diff_rule")
77
def cmp(name, srcs, args = [], out = None, **kwargs):
88
"""Runs cmp (binary diff) between two files and returns the output.
99
10+
Examples:
11+
12+
Compare two binaries.
13+
14+
```starlark
15+
cmp(
16+
name = "compare_bins",
17+
args = ["--bytes", "4", "--verbose"],
18+
srcs = ["bin_a", "bin_b"],
19+
out = "cmp_output"
20+
)
21+
```
22+
23+
Run cmp in a genrule.
24+
25+
```starlark
26+
genrule(
27+
name = "run_cmp",
28+
srcs = ["bin_a", "bin_b"],
29+
outs = ["cmp_output"],
30+
cmd = "$(CMP_BIN) --verbose $(execpath bin_a) $(execpath bin_b) > $@",
31+
toolchains = ["@diff.bzl//diff/toolchain:execution_type"],
32+
)
33+
```
34+
1035
Args:
1136
name: The name of the rule
1237
srcs: The files to compare.
@@ -54,6 +79,18 @@ def diff(name, srcs, args = ["--unified"], patch = None, **kwargs):
5479
)
5580
```
5681
82+
Run diff in a genrule.
83+
84+
```starlark
85+
genrule(
86+
name = "run_diff",
87+
srcs = ["a.txt", "b.txt"],
88+
outs = ["a.patch"],
89+
cmd = "$(DIFF_BIN) --unified $(execpath a.txt) $(execpath b.txt) > $@",
90+
toolchains = ["@diff.bzl//diff/toolchain:execution_type"],
91+
)
92+
```
93+
5794
_By default, diff creates a unified format patch by passing `["--unified"]`
5895
to `args`. If overriding arguments, --unified must be added explicitly._
5996

docs/rules.md

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)