-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate coverage #972
Merged
Merged
Separate coverage #972
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d53a96b
Separate coverage from compile
borkaehw d8563bb
Remove unused
borkaehw 783765a
Simplify condition
borkaehw af05c57
Simplify struct
borkaehw d16614c
Simplify return statement
borkaehw 4686086
Simplify phase
borkaehw 2a70763
Fix lint
borkaehw f627ac6
Remove condition
borkaehw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this sounds like a bug in rules_scala that we don't support srcjars for binary rules.
In any case this is in no way a call for action on this PR. Just an observation.