• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
2
3def apex_diff_test(name, apex1, apex2, expected_diff=None, **kwargs):
4    """A test that compares the content list of two APEXes, determined by `deapexer`."""
5
6    native.genrule(
7        name = name + "_apex1_deapex",
8        tools = [
9            "@make_injection//:host/linux-x86/bin/deapexer",
10            "//external/e2fsprogs/debugfs:debugfs",
11        ],
12        srcs = [apex1],
13        outs = [name + ".apex1.txt"],
14        cmd = "$(location @make_injection//:host/linux-x86/bin/deapexer) --debugfs_path=$(location //external/e2fsprogs/debugfs:debugfs) list $< > $@",
15    )
16
17    native.genrule(
18        name = name + "_apex2_deapex",
19        tools = [
20            "@make_injection//:host/linux-x86/bin/deapexer",
21            "//external/e2fsprogs/debugfs:debugfs",
22        ],
23        srcs = [apex2],
24        outs = [name + ".apex2.txt"],
25        cmd = "$(location @make_injection//:host/linux-x86/bin/deapexer) --debugfs_path=$(location //external/e2fsprogs/debugfs:debugfs) list $< > $@",
26    )
27
28    if expected_diff == None:
29        diff_test(
30            name = name + "_content_diff_test",
31            file1 = name + ".apex1.txt",
32            file2 = name + ".apex2.txt",
33        )
34    else:
35        # Make our own diff to compare against the expected one
36        native.genrule(
37            name = name + "_apex1_apex2_diff",
38            srcs = [
39                name + ".apex1.txt",
40                name + ".apex2.txt",
41            ],
42            outs = [name + ".apex1.apex2.diff.txt"],
43            # Expected to generate a diff (and return a failing exit status)
44            cmd_bash = "diff $(SRCS) > $@ || true",
45        )
46        diff_test(
47            name = name + "_content_diff_test",
48            file1 = name + ".apex1.apex2.diff.txt",
49            file2 = expected_diff,
50        )
51