Skip to content

Commit b0a5566

Browse files
committed
feat: add aspect to find cc_toolchain llvm-cov
This is useful for running coverage tools externally from bazel with the same toolchain that is used to build bazel targets.
1 parent 7acdb36 commit b0a5566

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tool_paths.bzl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
2+
3+
def _find_llvm_cov_aspect_impl(_target, ctx):
4+
cc_toolchain = find_cpp_toolchain(ctx)
5+
feature_configuration = cc_common.configure_features(
6+
ctx = ctx,
7+
cc_toolchain = cc_toolchain,
8+
requested_features = ctx.features,
9+
unsupported_features = ctx.disabled_features,
10+
)
11+
tool = cc_common.get_tool_for_action(
12+
feature_configuration=feature_configuration,
13+
action_name="llvm-cov",
14+
)
15+
llvm_cov_file = ctx.actions.declare_file("cc_toolchain_lcov_tool")
16+
ctx.actions.write(llvm_cov_file, tool)
17+
return [
18+
OutputGroupInfo(tool_paths = depset([llvm_cov_file])),
19+
]
20+
21+
find_llvm_cov = aspect(
22+
implementation = _find_llvm_cov_aspect_impl,
23+
attr_aspects = [],
24+
required_providers = [CcInfo],
25+
attrs = {
26+
"_cc_toolchain": attr.label(
27+
default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
28+
),
29+
},
30+
fragments = ["cpp"],
31+
toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
32+
)

0 commit comments

Comments
 (0)