forked from higherkindness/rules_scala
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathphase_coverage_jacoco.bzl
57 lines (47 loc) · 1.86 KB
/
phase_coverage_jacoco.bzl
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
54
55
56
57
load(
"@rules_scala_annex//rules:providers.bzl",
_CodeCoverageConfiguration = "CodeCoverageConfiguration",
_JacocoInfo = "JacocoInfo",
)
load(
"@rules_scala_annex//rules/private:coverage_replacements_provider.bzl",
_coverage_replacements_provider = "coverage_replacements_provider",
)
def phase_coverage_jacoco(ctx, g):
if not ctx.configuration.coverage_enabled:
return
toolchain = ctx.toolchains["//rules/scala:toolchain_type"]
args = ctx.actions.args()
instrumented_output_jar = ctx.actions.declare_file(
"{}-offline.jar".format(ctx.outputs.jar.basename.split(".")[0]),
)
in_out_pairs = [
(ctx.outputs.jar, instrumented_output_jar),
]
args.add_all(in_out_pairs, map_each = _format_in_out_pairs)
args.set_param_file_format("multiline")
args.use_param_file("@%s", use_always = True)
ctx.actions.run(
arguments = [args],
executable = toolchain.code_coverage_configuration.instrumentation_worker.files_to_run,
execution_requirements = {
"supports-multiplex-workers": "1",
"supports-workers": "1",
"supports-multiplex-sandboxing": "1",
"supports-worker-cancellation": "1",
"supports-path-mapping": "1",
},
inputs = [in_out_pair[0] for in_out_pair in in_out_pairs],
mnemonic = "JacocoInstrumenter",
outputs = [in_out_pair[1] for in_out_pair in in_out_pairs],
toolchain = "@rules_scala_annex//rules/scala:toolchain_type",
)
replacements = {i: o for (i, o) in in_out_pairs}
g.out.providers.extend([
_coverage_replacements_provider.create(
replacements = replacements,
),
])
return _JacocoInfo(replacements = replacements)
def _format_in_out_pairs(in_out_pair):
return (["--jar", "%s=%s" % (in_out_pair[0].path, in_out_pair[1].path)])