forked from bazelbuild/rules_scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Separate coverage from compile * Remove unused * Simplify condition * Simplify struct * Simplify return statement * Simplify phase * Fix lint * Remove condition
- Loading branch information
Showing
10 changed files
with
100 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# | ||
# PHASE: coverage | ||
# | ||
# DOCUMENT THIS | ||
# | ||
|
||
load( | ||
"@io_bazel_rules_scala//scala/private:coverage_replacements_provider.bzl", | ||
_coverage_replacements_provider = "coverage_replacements_provider", | ||
) | ||
|
||
def phase_coverage_library(ctx, p): | ||
args = struct( | ||
srcjars = p.collect_srcjars, | ||
) | ||
return _phase_coverage_default(ctx, p, args) | ||
|
||
def phase_coverage_common(ctx, p): | ||
return _phase_coverage_default(ctx, p) | ||
|
||
def _phase_coverage_default(ctx, p, _args = struct()): | ||
return _phase_coverage( | ||
ctx, | ||
p, | ||
_args.srcjars if hasattr(_args, "srcjars") else depset(), | ||
) | ||
|
||
def _phase_coverage(ctx, p, srcjars): | ||
if len(ctx.files.srcs) + len(srcjars.to_list()) == 0 or not ctx.configuration.coverage_enabled: | ||
return struct( | ||
replacements = {}, | ||
external_providers = {}, | ||
) | ||
else: | ||
input_jar = ctx.outputs.jar | ||
output_jar = ctx.actions.declare_file( | ||
"{}-offline.jar".format(input_jar.basename.split(".")[0]), | ||
) | ||
in_out_pairs = [ | ||
(input_jar, output_jar), | ||
] | ||
|
||
args = ctx.actions.args() | ||
args.add_all(in_out_pairs, map_each = _jacoco_offline_instrument_format_each) | ||
args.set_param_file_format("multiline") | ||
args.use_param_file("@%s", use_always = True) | ||
|
||
ctx.actions.run( | ||
mnemonic = "JacocoInstrumenter", | ||
inputs = [in_out_pair[0] for in_out_pair in in_out_pairs], | ||
outputs = [in_out_pair[1] for in_out_pair in in_out_pairs], | ||
executable = ctx.attr._code_coverage_instrumentation_worker.files_to_run, | ||
execution_requirements = {"supports-workers": "1"}, | ||
arguments = [args], | ||
) | ||
|
||
replacements = {i: o for (i, o) in in_out_pairs} | ||
provider = _coverage_replacements_provider.create( | ||
replacements = replacements, | ||
) | ||
instrumented_files_provider = coverage_common.instrumented_files_info( | ||
ctx, | ||
source_attributes = ["srcs"], | ||
dependency_attributes = _coverage_replacements_provider.dependency_attributes, | ||
extensions = ["scala", "java"], | ||
) | ||
return struct( | ||
replacements = replacements, | ||
external_providers = { | ||
"_CoverageReplacements": provider, | ||
"InstrumentedFilesInfo": instrumented_files_provider, | ||
}, | ||
) | ||
|
||
def _jacoco_offline_instrument_format_each(in_out_pair): | ||
return (["%s=%s" % (in_out_pair[0].path, in_out_pair[1].path)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters