Skip to content

Commit bd581be

Browse files
authored
initial commit
1 parent e64f5a3 commit bd581be

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Replacement for the 'bazel coverage' command:
2+
3+
- we don't accidentally bust the analysis cache with 'coverage' flags differing from 'test'
4+
- forget having a Bazel-specific, Java-based, unmaintained LCOV merger and 'combined report' - that never should have been Bazel's job
5+
- developers really need git-aware diff to show "incremental coverage" - which of the lines I added or modified are covered by tests?

coverage.axl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Implement a 'coverage' task that wraps a test command.
3+
4+
Gathers the coverage.dat files to power common developer workflows.
5+
"""
6+
7+
# buildifier: disable=function-docstring
8+
def impl(ctx) -> int:
9+
out = ctx.std.io.stdout
10+
build = ctx.bazel.build(
11+
"//...",
12+
events = True,
13+
bazel_flags = [
14+
"--isatty=" + str(int(out.is_tty)),
15+
# We probably want to abbreviate the following flags under
16+
# "--config=coverage"
17+
"--collect_code_coverage",
18+
"--instrumentation_filter=",
19+
# See https://github.com/bazel-contrib/bazelrc-preset.bzl/issues/83
20+
"--experimental_fetch_all_coverage_outputs",
21+
"--experimental_split_coverage_postprocessing",
22+
],
23+
bazel_verb = "test"
24+
);
25+
26+
for event in build.events():
27+
# TODO: get the paths of produced (or cached) coverage report files
28+
# TODO: populate a GITHUB_OUTPUT variable so we can use https://github.com/codecov/codecov-action
29+
if event.type == "progress":
30+
out.write(event.payload.stdout)
31+
out.write(event.payload.stderr)
32+
33+
build.wait()
34+
# TODO: get the delta of changed files from VCS, and render 'incremental' coverage as the default presentation
35+
36+
return 0
37+
38+
coverage = task(
39+
implementation = impl,
40+
args = {
41+
"targets": args.positional(minimum = 1, maximum = 30),
42+
}
43+
)

0 commit comments

Comments
 (0)