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