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
Enable passing option sets to the compiler #6065
Changes from 5 commits
061befd
a15869c
00bb205
dd06b54
7ffa217
0f29b76
0ad0007
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
from __future__ import (absolute_import, division, generators, nested_scopes, print_function, | ||
unicode_literals, with_statement) | ||
|
||
from pants.base.deprecated import deprecated | ||
|
||
|
||
class ZincLanguageMixin(object): | ||
"""A mixin for subsystems for languages compiled with Zinc.""" | ||
|
@@ -20,8 +22,14 @@ def register_options(cls, register): | |
|
||
register('--fatal-warnings', advanced=True, type=bool, | ||
fingerprint=True, | ||
removal_version='1.11.0.dev0', | ||
removal_hint='Use --compiler-option-sets=fatal_warnings instead of fatal_warnings', | ||
help='The default for the "fatal_warnings" argument for targets of this language.') | ||
|
||
register('--compiler-option-sets', advanced=True, default=[], type=list, | ||
fingerprint=True, | ||
help='The option sets to be enabled for the compilation of this target.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, the If a target passes the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome! I'm not entirely sure where you were going with this comment 😅 PS. I'm using a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, they are allowed to do that. But if they do not do that, we use the default from this option. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be the same as with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The help for this option should likely be updated to align with the help for the deprecated
|
||
|
||
register('--zinc-file-manager', advanced=True, default=True, type=bool, | ||
fingerprint=True, | ||
help='Use zinc provided file manager to ensure transactional rollback.') | ||
|
@@ -34,12 +42,24 @@ def strict_deps(self): | |
return self.get_options().strict_deps | ||
|
||
@property | ||
@deprecated('1.11.0.dev0', 'Consume fatal_warnings from compiler_option_sets instead.') | ||
def fatal_warnings(self): | ||
"""If true, make warnings fatal for targets that do not specify fatal_warnings. | ||
:rtype: bool | ||
""" | ||
return self.get_options().fatal_warnings | ||
|
||
@property | ||
def compiler_option_sets(self): | ||
"""For every element in this list, enable the corresponding flags on compilation | ||
of targets. | ||
:rtype: list | ||
""" | ||
option_sets = self.get_options().compiler_option_sets | ||
if 'fatal_warnings' not in option_sets and self.fatal_warnings: | ||
option_sets.append('fatal_warnings') | ||
return option_sets | ||
|
||
@property | ||
def zinc_file_manager(self): | ||
"""If false, the default file manager will be used instead of the zinc provided one. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
from pants.backend.jvm.subsystems.jvm_platform import JvmPlatform | ||
from pants.backend.jvm.targets.jar_library import JarLibrary | ||
from pants.backend.jvm.targets.jarable import Jarable | ||
from pants.base.deprecated import deprecated_conditional | ||
from pants.base.payload import Payload | ||
from pants.base.payload_field import ExcludesField, PrimitiveField, PrimitivesSetField | ||
from pants.build_graph.resources import Resources | ||
|
@@ -40,6 +41,7 @@ def __init__(self, | |
strict_deps=None, | ||
exports=None, | ||
fatal_warnings=None, | ||
compiler_option_sets=None, | ||
zinc_file_manager=None, | ||
# Some subclasses can have both .java and .scala sources | ||
# (e.g., JUnitTests, JvmBinary, even ScalaLibrary), so it's convenient | ||
|
@@ -83,7 +85,7 @@ def __init__(self, | |
if A exports B, and B exports C, then any targets that depends on A will | ||
have access to both B and C. | ||
:param bool fatal_warnings: Whether to turn warnings into errors for this target. If present, | ||
takes priority over the language's fatal-warnings option. | ||
takes priority over the language's fatal-warnings option. Deprecated. | ||
:param bool zinc_file_manager: Whether to use zinc provided file manager that allows | ||
transactional rollbacks, but in certain cases may conflict with | ||
user libraries. | ||
|
@@ -96,14 +98,29 @@ def __init__(self, | |
self.address = address # Set in case a TargetDefinitionException is thrown early | ||
payload = payload or Payload() | ||
excludes = ExcludesField(self.assert_list(excludes, expected_type=Exclude, key_arg='excludes')) | ||
deprecated_conditional( | ||
lambda: fatal_warnings is not None, | ||
removal_version='1.11.0dev0', | ||
entity_description='fatal_warnings', | ||
hint_message="fatal_warnings should be defined as part of the target compiler_option_sets" | ||
) | ||
if fatal_warnings is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This bunch of code is handling the case where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One option might be to have the internal representation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...oh. This is already nicer than that. |
||
compiler_option_sets = [] if compiler_option_sets is None else compiler_option_sets | ||
if fatal_warnings: | ||
compiler_option_sets.append('fatal_warnings') | ||
else: | ||
try: | ||
compiler_option_sets.remove('fatal_warnings') | ||
except ValueError: | ||
pass | ||
payload.add_fields({ | ||
'sources': self.create_sources_field(sources, address.spec_path, key_arg='sources'), | ||
'provides': provides, | ||
'excludes': excludes, | ||
'platform': PrimitiveField(platform), | ||
'strict_deps': PrimitiveField(strict_deps), | ||
'exports': PrimitivesSetField(exports or []), | ||
'fatal_warnings': PrimitiveField(fatal_warnings), | ||
'compiler_option_sets': PrimitivesSetField(compiler_option_sets), | ||
'zinc_file_manager': PrimitiveField(zinc_file_manager), | ||
'javac_plugins': PrimitivesSetField(javac_plugins or []), | ||
'javac_plugin_args': PrimitiveField(javac_plugin_args), | ||
|
@@ -137,7 +154,16 @@ def fatal_warnings(self): | |
:return: See constructor. | ||
:rtype: bool or None | ||
""" | ||
return self.payload.fatal_warnings | ||
return 'fatal_warnings' in self.payload.compiler_option_sets | ||
|
||
@memoized_property | ||
def compiler_option_sets(self): | ||
"""For every element in this list, enable the corresponding flags on compilation | ||
of targets. | ||
:return: See constructor. | ||
:rtype: list | ||
""" | ||
return self.payload.compiler_option_sets | ||
|
||
@property | ||
def zinc_file_manager(self): | ||
|
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 should also use
PrimitivesSetField
.