aboutsummaryrefslogtreecommitdiff
path: root/tools/migration/cc_toolchain_config_comparator.bzl
blob: 66746b386bf210a9e205785e5bc35bb26330962b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""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,
)