1"""A test rule that compares two CToolchains in proto format.""" 2 3def _impl(ctx): 4 toolchain_config_proto = ctx.actions.declare_file(ctx.label.name + "_toolchain_config.proto") 5 ctx.actions.write( 6 toolchain_config_proto, 7 ctx.attr.toolchain_config[CcToolchainConfigInfo].proto, 8 ) 9 10 script = ("%s --before='%s' --after='%s' --toolchain_identifier='%s'" % ( 11 ctx.executable._comparator.short_path, 12 ctx.file.crosstool.short_path, 13 toolchain_config_proto.short_path, 14 ctx.attr.toolchain_identifier, 15 )) 16 test_executable = ctx.actions.declare_file(ctx.label.name) 17 ctx.actions.write(test_executable, script, is_executable = True) 18 19 runfiles = ctx.runfiles(files = [toolchain_config_proto, ctx.file.crosstool]) 20 runfiles = runfiles.merge(ctx.attr._comparator[DefaultInfo].default_runfiles) 21 22 return DefaultInfo(runfiles = runfiles, executable = test_executable) 23 24cc_toolchains_compare_test = rule( 25 implementation = _impl, 26 attrs = { 27 "crosstool": attr.label( 28 mandatory = True, 29 allow_single_file = True, 30 doc = "Location of the CROSSTOOL file", 31 ), 32 "toolchain_config": attr.label( 33 mandatory = True, 34 providers = [CcToolchainConfigInfo], 35 doc = ("Starlark rule that replaces the CROSSTOOL file functionality " + 36 "for the CToolchain with the given identifier"), 37 ), 38 "toolchain_identifier": attr.string( 39 mandatory = True, 40 doc = "identifier of the CToolchain that is being compared", 41 ), 42 "_comparator": attr.label( 43 default = ":ctoolchain_comparator", 44 executable = True, 45 cfg = "exec", 46 ), 47 }, 48 test = True, 49) 50