-
-
Notifications
You must be signed in to change notification settings - Fork 646
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
Zinc 1.0.0 upgrade: Python portion #4729
Changes from all commits
820848e
965afac
ff482c3
bd1c6e7
81cf447
641d19d
b8d36e6
4c859dd
cdf9f70
877184e
bdad62a
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 |
---|---|---|
|
@@ -180,8 +180,6 @@ exclude_patterns: [ | |
[compile.zinc] | ||
jvm_options: [ | ||
'-Xmx4g', '-XX:+UseConcMarkSweepGC', '-XX:ParallelGCThreads=4', | ||
# bigger cache size for our big projects (default is just 5) | ||
'-Dzinc.analysis.cache.limit=1000', | ||
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. How come we don't need this any more? 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. I changed the default in the JVM code: because it's a weak-reference cache, making it huge is safe. |
||
] | ||
|
||
args: [ | ||
|
@@ -280,7 +278,7 @@ skip: True | |
[pycheck-context-manager] | ||
skip: True | ||
|
||
[scala-platform] | ||
[scala] | ||
version: 2.11 | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# coding=utf-8 | ||
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import (absolute_import, division, generators, nested_scopes, print_function, | ||
unicode_literals, with_statement) | ||
|
||
import hashlib | ||
|
||
from pants.backend.codegen.protobuf.java.java_protobuf_library import JavaProtobufLibrary | ||
from pants.backend.codegen.thrift.java.java_thrift_library import JavaThriftLibrary | ||
from pants.backend.jvm.subsystems.java import Java | ||
from pants.backend.jvm.subsystems.scala_platform import ScalaPlatform | ||
from pants.backend.jvm.targets.annotation_processor import AnnotationProcessor | ||
from pants.backend.jvm.targets.jar_library import JarLibrary | ||
from pants.backend.jvm.targets.javac_plugin import JavacPlugin | ||
from pants.backend.jvm.targets.scalac_plugin import ScalacPlugin | ||
from pants.base.fingerprint_strategy import FingerprintStrategy | ||
from pants.build_graph.aliased_target import AliasTarget | ||
from pants.build_graph.resources import Resources | ||
from pants.build_graph.target import Target | ||
from pants.build_graph.target_scopes import Scopes | ||
from pants.subsystem.subsystem import Subsystem | ||
|
||
|
||
class SyntheticTargetNotFound(Exception): | ||
"""Exports were resolved for a thrift target which hasn't had a synthetic target generated yet.""" | ||
|
||
|
||
class DependencyContext(Subsystem): | ||
"""Implements calculating `exports` and exception (compiler-plugin) aware dependencies. | ||
|
||
This is a subsystem because in future the compiler plugin types should be injected | ||
via subsystem or option dependencies rather than declared statically. | ||
""" | ||
|
||
options_scope = 'jvm-dependency-context' | ||
|
||
target_closure_kwargs = dict(include_scopes=Scopes.JVM_COMPILE_SCOPES, respect_intransitive=True) | ||
compiler_plugin_types = (AnnotationProcessor, JavacPlugin, ScalacPlugin) | ||
alias_types = (AliasTarget, Target) | ||
codegen_types = (JavaThriftLibrary, JavaProtobufLibrary) | ||
|
||
@classmethod | ||
def subsystem_dependencies(cls): | ||
return super(DependencyContext, cls).subsystem_dependencies() + (Java, ScalaPlatform) | ||
|
||
def all_dependencies(self, target): | ||
"""All transitive dependencies of the context's target.""" | ||
for dep in target.closure(bfs=True, **self.target_closure_kwargs): | ||
yield dep | ||
|
||
def create_fingerprint_strategy(self, classpath_products): | ||
return ResolvedJarAwareFingerprintStrategy(classpath_products, self) | ||
|
||
def defaulted_property(self, target, selector): | ||
"""Computes a language property setting for the given JvmTarget. | ||
|
||
:param selector A function that takes a target or platform and returns the boolean value of the | ||
property for that target or platform, or None if that target or platform does | ||
not directly define the property. | ||
|
||
If the target does not override the language property, returns true iff the property | ||
is true for any of the matched languages for the target. | ||
""" | ||
if selector(target) is not None: | ||
return selector(target) | ||
|
||
prop = False | ||
if target.has_sources('.java'): | ||
prop |= selector(Java.global_instance()) | ||
if target.has_sources('.scala'): | ||
prop |= selector(ScalaPlatform.global_instance()) | ||
return prop | ||
|
||
|
||
class ResolvedJarAwareFingerprintStrategy(FingerprintStrategy): | ||
"""Task fingerprint strategy that also includes the resolved coordinates of dependent jars.""" | ||
|
||
def __init__(self, classpath_products, dep_context): | ||
super(ResolvedJarAwareFingerprintStrategy, self).__init__() | ||
self._classpath_products = classpath_products | ||
self._dep_context = dep_context | ||
|
||
def compute_fingerprint(self, target): | ||
if isinstance(target, Resources): | ||
# Just do nothing, this kind of dependency shouldn't affect result's hash. | ||
return None | ||
|
||
hasher = hashlib.sha1() | ||
hasher.update(target.payload.fingerprint()) | ||
if isinstance(target, JarLibrary): | ||
# NB: Collects only the jars for the current jar_library, and hashes them to ensure that both | ||
# the resolved coordinates, and the requested coordinates are used. This ensures that if a | ||
# source file depends on a library with source compatible but binary incompatible signature | ||
# changes between versions, that you won't get runtime errors due to using an artifact built | ||
# against a binary incompatible version resolved for a previous compile. | ||
classpath_entries = self._classpath_products.get_artifact_classpath_entries_for_targets( | ||
[target]) | ||
for _, entry in classpath_entries: | ||
hasher.update(str(entry.coordinate)) | ||
return hasher.hexdigest() | ||
|
||
def direct(self, target): | ||
return self._dep_context.defaulted_property(target, lambda x: x.strict_deps) | ||
|
||
def dependencies(self, target): | ||
if self.direct(target): | ||
return target.strict_dependencies(self._dep_context) | ||
return super(ResolvedJarAwareFingerprintStrategy, self).dependencies(target) | ||
|
||
def __hash__(self): | ||
# NB: FingerprintStrategy requires a useful override of eq/hash. | ||
return hash(type(self)) | ||
|
||
def __eq__(self, other): | ||
# NB: See __hash__. | ||
return type(self) == type(other) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,10 @@ class ScalaPlatform(JvmToolMixin, ZincLanguageMixin, InjectablesMixin, Subsystem | |
|
||
:API: public | ||
""" | ||
options_scope = 'scala-platform' | ||
options_scope = 'scala' | ||
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. 👍 |
||
|
||
deprecated_options_scope = 'scala-platform' | ||
deprecated_options_scope_removal_version = '1.9.0.dev0' | ||
|
||
@classmethod | ||
def _create_jardep(cls, name, version): | ||
|
@@ -88,6 +91,15 @@ def register_style_tool(version): | |
classpath=[scala_style_jar]) | ||
|
||
super(ScalaPlatform, cls).register_options(register) | ||
|
||
register('--scalac-plugins', advanced=True, type=list, fingerprint=True, | ||
help='Use these scalac plugins.') | ||
register('--scalac-plugin-args', advanced=True, type=dict, default={}, fingerprint=True, | ||
help='Map from scalac plugin name to list of arguments for that plugin.') | ||
cls.register_jvm_tool(register, 'scalac-plugin-dep', classpath=[], | ||
help='Search for scalac plugins here, as well as in any ' | ||
'explicit dependencies.') | ||
|
||
register('--version', advanced=True, default='2.12', | ||
choices=['2.10', '2.11', '2.12', 'custom'], fingerprint=True, | ||
help='The scala platform version. If --version=custom, the targets ' | ||
|
@@ -153,7 +165,7 @@ def suffix_version(self, name): | |
raise RuntimeError('Suffix version must be specified if using a custom scala version. ' | ||
'Suffix version is used for bootstrapping jars. If a custom ' | ||
'scala version is not specified, then the version specified in ' | ||
'--scala-platform-suffix-version is used. For example for Scala ' | ||
'--scala-suffix-version is used. For example for Scala ' | ||
'2.10.7 you would use the suffix version "2.10".') | ||
|
||
elif name.endswith(self.version): | ||
|
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.
Ha! I have this bug internally, it turns out. I was just bitten by it the other day, but did not catch this was the cause. When properly configured, our CIs aren't using the {m2.x} definitions, so I just fixed that and didn't keep digging. I will have to land the equivalent change :)
I recently rewrote all our ivyprofile and settings files and have found that one line changes often reflect hours of frustration from the author 😱