1"""A test rule that compares two C++ toolchain configuration rules in proto format.""" 2 3def _impl(ctx): 4 first_toolchain_config_proto = ctx.actions.declare_file( 5 ctx.label.name + "_first_toolchain_config.proto", 6 ) 7 ctx.actions.write( 8 first_toolchain_config_proto, 9 ctx.attr.first[CcToolchainConfigInfo].proto, 10 ) 11 12 second_toolchain_config_proto = ctx.actions.declare_file( 13 ctx.label.name + "_second_toolchain_config.proto", 14 ) 15 ctx.actions.write( 16 second_toolchain_config_proto, 17 ctx.attr.second[CcToolchainConfigInfo].proto, 18 ) 19 20 script = ("%s --before='%s' --after='%s'" % ( 21 ctx.executable._comparator.short_path, 22 first_toolchain_config_proto.short_path, 23 second_toolchain_config_proto.short_path, 24 )) 25 test_executable = ctx.actions.declare_file(ctx.label.name) 26 ctx.actions.write(test_executable, script, is_executable = True) 27 28 runfiles = ctx.runfiles(files = [first_toolchain_config_proto, second_toolchain_config_proto]) 29 runfiles = runfiles.merge(ctx.attr._comparator[DefaultInfo].default_runfiles) 30 31 return DefaultInfo(runfiles = runfiles, executable = test_executable) 32 33cc_toolchain_config_compare_test = rule( 34 implementation = _impl, 35 attrs = { 36 "first": attr.label( 37 mandatory = True, 38 providers = [CcToolchainConfigInfo], 39 doc = "A C++ toolchain config rule", 40 ), 41 "second": attr.label( 42 mandatory = True, 43 providers = [CcToolchainConfigInfo], 44 doc = "A C++ toolchain config rule", 45 ), 46 "_comparator": attr.label( 47 default = ":ctoolchain_comparator", 48 executable = True, 49 cfg = "exec", 50 ), 51 }, 52 test = True, 53) 54