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 ab0be67e22 Update cfg values to make buildifier happy.
PiperOrigin-RevId: 449498641
Change-Id: I145fc5dfec522753deaa64ace04ca56546351ff5
2022-05-18 09:16:43 -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 = "exec",
),
},
test = True,
)