-
Notifications
You must be signed in to change notification settings - Fork 277
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
Add preliminary support for code coverage #692
Merged
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bab69b3
Add preliminary support for code coverage
andyscott 6810070
Fix conditional bug
andyscott c2ed1e7
Remove accidental tools/bazel launcher
andyscott 721b7ec
Get rid of default argument
andyscott 0fd3981
Merge branch 'master' into code-coverage
andyscott 1cbe4b0
Bump bazel versions to 0.18.x+
andyscott f6dc48e
Add back 0.16.x hash
andyscott e291ad8
Revert launcher template version
andyscott 14b9593
18 -> 19
andyscott 738b1b4
Merge branch 'master' into code-coverage
andyscott 9f0faf4
Feature flag coverage logic
andyscott d2761bf
Fix test script
andyscott d508a76
Remove negative case
andyscott 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# | ||
# Coverage Replacements are a mapping of normal compiled artifacts to | ||
# instrumented compiled artifacts. | ||
# | ||
# The intention is that the final test runner inspects the test | ||
# classpath and replaces artifacts by any mappings found in the | ||
# `replacements` field. | ||
# | ||
# Rules producing replacement artifacts should _not_ link the | ||
# replacement files as any of the default outputs via DefaultInfo, | ||
# JavaInfo, etc. This way, actions producing the replacement artifacts | ||
# will be executed on an as needed basis. | ||
# | ||
# Coverage Replacements use a provider and a helper aspect to | ||
# aggregate replacements files across the dependency graph. | ||
# | ||
# Under the hood, two providers are needed because Bazel doesn't allow | ||
# duplicate providers. | ||
# | ||
|
||
_CoverageReplacements = provider( | ||
fields = { | ||
"replacements": "hash of files to swap out", | ||
}, | ||
) | ||
|
||
_CombinedCoverageReplacements = provider( | ||
fields = { | ||
"replacements": "hash of files to swap out", | ||
}, | ||
) | ||
|
||
# the attributes used to form the dependency graph that we'll fold | ||
# over for our aggregation | ||
_dependency_attributes = [ | ||
"deps", | ||
"exports", | ||
] | ||
|
||
def _combine(*entriess, base = {}): | ||
return _CombinedCoverageReplacements(replacements = _dicts_add(base, *( | ||
[ | ||
entry[_CoverageReplacements].replacements | ||
for entries in entriess | ||
for entry in entries | ||
if _CoverageReplacements in entry | ||
] + [ | ||
entry[_CombinedCoverageReplacements].replacements | ||
for entries in entriess | ||
for entry in entries | ||
if _CombinedCoverageReplacements in entry | ||
] | ||
))) | ||
|
||
def _from_ctx(ctx, base = {}): | ||
return _combine( | ||
base = base, | ||
*[getattr(ctx.attr, name, []) for name in _dependency_attributes] | ||
) | ||
|
||
def _aspect_impl(target, ctx): | ||
if JavaInfo not in target: | ||
return [] | ||
else: | ||
return [_from_ctx(ctx.rule)] | ||
|
||
_aspect = aspect( | ||
attr_aspects = _dependency_attributes, | ||
implementation = _aspect_impl, | ||
) | ||
|
||
coverage_replacements_provider = struct( | ||
aspect = _aspect, | ||
combine = _combine, | ||
create = _CoverageReplacements, | ||
dependency_attributes = _dependency_attributes, | ||
from_ctx = _from_ctx, | ||
) | ||
|
||
# from bazel's skylib | ||
def _dicts_add(*dictionaries): | ||
result = {} | ||
for d in dictionaries: | ||
result.update(d) | ||
return result |
Oops, something went wrong.
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.
why
entriess
? Any meaning there?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.
It's just because it's a 2d array of entry items (or a 1d array of entries). In the comprehension I have: