xref: /aosp_15_r20/build/bazel/rules/partitions/diff/partition_diff.bzl (revision 7594170e27e0732bc44b93d1440d87a54b6ffe7c)
1# Copyright (C) 2023 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
16
17def partition_diff_test(
18        *,
19        name,
20        partition1,
21        partition2):
22    """A test that compares the contents of two paritions."""
23
24    native.genrule(
25        name = name + "_1_genrule",
26        tools = [
27            "//build/bazel/rules/partitions/diff:partition_inspector",
28            "//external/e2fsprogs/debugfs:debugfs",
29        ],
30        srcs = [partition1],
31        outs = [name + "_1.txt"],
32        cmd = "$(location //build/bazel/rules/partitions/diff:partition_inspector) --debugfs-path=$(location //external/e2fsprogs/debugfs:debugfs) $< > $@",
33    )
34
35    native.genrule(
36        name = name + "_2_genrule",
37        tools = [
38            "//build/bazel/rules/partitions/diff:partition_inspector",
39            "//external/e2fsprogs/debugfs:debugfs",
40        ],
41        srcs = [partition2],
42        outs = [name + "_2.txt"],
43        cmd = "$(location //build/bazel/rules/partitions/diff:partition_inspector) --debugfs-path=$(location //external/e2fsprogs/debugfs:debugfs) $< > $@",
44    )
45
46    diff_test(
47        name = name,
48        file1 = name + "_1.txt",
49        file2 = name + "_2.txt",
50    )
51