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
Scoverage work - add scoverage to OSS pants #8064
Merged
Merged
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
3ef8021
adding scoverage 1/2
705a12b
adding scoverage 1/2
5ea8fc5
adding scoverage 1/2
fc48b64
removing scoverage target from BUILD.tools
21a5dd4
Update src/python/pants/backend/jvm/subsystems/scala_coverage_platfor…
sammy-1234 2429357
removing futures
f432d7b
changing name to scoverage_platform
c7f560a
adding scoverage dependency for unit tests to pass
c427e21
Scoverage (2/2) - adding report generator
324f59d
changing report generator's name
1a7e8fc
scoverage report generator
739032a
adding scoverage report gen
fc4ed94
testing with new report gen local publish
3212da7
changing scoverage to work with new reportGen
f9561dc
relocatiing modifications to scala library
3d913e3
playing with new report gen
3209a9f
adding scoverage runtime environment along with target filtering and …
3cd1b8b
removing report generator from here
3099ac7
Merge branch 'master' into scoverageWork
sammy-1234 66ace61
resolving unwanted file changes
3ff84cc
Merge branch 'scoverageWork' of https://github.com/sammy-1234/pants i…
a47ef75
minor changes to alignment
7bacd7b
minor changes to alignment
d9a94e1
minor changes to alignment
37295d6
adding log statements
f390ee4
improving test file for blacklisted targets
b15f45d
adding scoverage dependency to test_rsc_compile to resolve unit test …
ae22fed
adding extra args in constructor rather than as a property
e5b0a56
removing target's scoverage instance
12430dd
fixing blacklisted target specification
04065ac
cleaning checking of blacklisted targets; fixing scoverage test
e13edd8
removing option; removing target spec as an option
4e1b5c8
init change in scala_library; linting
02435cc
fixing lint again
ed7d4b0
trying to fix lint in test_scoverage_platform
7acd82c
changing args indentation in scoverage.py
d6a2dbc
running git hooks successfully
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
84 changes: 84 additions & 0 deletions
84
src/python/pants/backend/jvm/subsystems/scoverage_platform.py
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,84 @@ | ||
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
import logging | ||
import re | ||
from pants.build_graph.injectables_mixin import InjectablesMixin | ||
from pants.subsystem.subsystem import Subsystem | ||
from pants.java.jar.jar_dependency import JarDependency | ||
from pants.backend.jvm.targets.jar_library import JarLibrary | ||
from pants.build_graph.address import Address | ||
from pants.option.custom_types import target_option | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
SCOVERAGE = "scoverage" | ||
|
||
class ScoveragePlatform(InjectablesMixin, Subsystem): | ||
"""The scoverage platform.""" | ||
|
||
options_scope = 'scoverage' | ||
|
||
@classmethod | ||
def register_options(cls, register): | ||
super().register_options(register) | ||
register('--enable-scoverage', | ||
default=False, | ||
type=bool, | ||
help='Specifies whether to generate scoverage reports for scala test targets. ' | ||
'Default value is False. If True, ' | ||
'implies --test-junit-coverage-processor=scoverage.') | ||
|
||
register('--blacklist-targets', | ||
type=list, | ||
member_type=target_option, | ||
help='List of targets not to be instrumented. Accepts Regex patterns. All ' | ||
'targets matching any of the patterns will not be instrumented. If no targets ' | ||
'are specified, all targets will be instrumented.') | ||
|
||
|
||
def scoverage_jar(self): | ||
return [JarDependency(org='com.twitter.scoverage', name='scalac-scoverage-plugin_2.12', | ||
rev='1.0.1-twitter'), | ||
JarDependency(org='com.twitter.scoverage', name='scalac-scoverage-runtime_2.12', | ||
rev='1.0.1-twitter')] | ||
|
||
def injectables(self, build_graph): | ||
specs_to_create = [ | ||
('scoverage', self.scoverage_jar), | ||
] | ||
|
||
for spec_key, create_jardep_func in specs_to_create: | ||
spec = self.injectables_spec_for_key(spec_key) | ||
target_address = Address.parse(spec) | ||
if not build_graph.contains_address(target_address): | ||
target_jars = create_jardep_func() | ||
jars = target_jars if isinstance(target_jars, list) else [target_jars] | ||
build_graph.inject_synthetic_target(target_address, | ||
JarLibrary, | ||
jars=jars, | ||
scope='forced') | ||
elif not build_graph.get_target(target_address).is_synthetic: | ||
raise build_graph.ManualSyntheticTargetError(target_address) | ||
|
||
@property | ||
def injectables_spec_mapping(self): | ||
return { | ||
# Target spec for scoverage plugin. | ||
'scoverage': [f"//:scoverage"], | ||
} | ||
|
||
|
||
def is_blacklisted(self, target_address_spec) -> bool: | ||
""" | ||
Checks if the [target] is blacklisted or not. | ||
""" | ||
# No blacklisted targets specified. | ||
if not self.get_options().blacklist_targets: | ||
return False | ||
|
||
for filter in self.get_options().blacklist_targets: | ||
if re.search(filter, target_address_spec) is not None: | ||
logger.debug(f"{target_address_spec} found in blacklist, not instrumented.") | ||
return True | ||
return False |
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
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.
Having two super calls is pretty weird, and in general this has resulted in a lot of nesting.
An alternative might be to do something like: