2
0
Fork 0
mirror of https://github.com/bazelbuild/rules_cc synced 2024-11-27 20:43:26 +00:00
rules_cc/tools/migration/cc_toolchain_config_comparator.bzl
Googler 401380cd22 Add a cc_toolchain_config_compare_test that compares 2 Starlark C++ toolchain configuration rules
With CROSSTOOL not existing anymore, the comparison script can continue being useful in refactoring Starlark toolchain config rules.

RELNOTES: None.
PiperOrigin-RevId: 262544859
Change-Id: I633fdc4c09c7643d6e5d1c10537efa3c9a82003c
2019-08-09 05:56:16 -07:00

54 lines
1.7 KiB
Python

"""A test rule that compares two C++ toolchain configuration rules in proto format."""
def _impl(ctx):
first_toolchain_config_proto = ctx.actions.declare_file(
ctx.label.name + "_first_toolchain_config.proto",
)
ctx.actions.write(
first_toolchain_config_proto,
ctx.attr.first[CcToolchainConfigInfo].proto,
)
second_toolchain_config_proto = ctx.actions.declare_file(
ctx.label.name + "_second_toolchain_config.proto",
)
ctx.actions.write(
second_toolchain_config_proto,
ctx.attr.second[CcToolchainConfigInfo].proto,
)
script = ("%s --before='%s' --after='%s'" % (
ctx.executable._comparator.short_path,
first_toolchain_config_proto.short_path,
second_toolchain_config_proto.short_path,
))
test_executable = ctx.actions.declare_file(ctx.label.name)
ctx.actions.write(test_executable, script, is_executable = True)
runfiles = ctx.runfiles(files = [first_toolchain_config_proto, second_toolchain_config_proto])
runfiles = runfiles.merge(ctx.attr._comparator[DefaultInfo].default_runfiles)
return DefaultInfo(runfiles = runfiles, executable = test_executable)
cc_toolchain_config_compare_test = rule(
implementation = _impl,
attrs = {
"first": attr.label(
mandatory = True,
providers = [CcToolchainConfigInfo],
doc = "A C++ toolchain config rule",
),
"second": attr.label(
mandatory = True,
providers = [CcToolchainConfigInfo],
doc = "A C++ toolchain config rule",
),
"_comparator": attr.label(
default = ":ctoolchain_comparator",
executable = True,
cfg = "host",
),
},
test = True,
)