forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the thrift codegen task. (pantsbuild#4155)
Almost all the logic is now in a base class that thrift gen for other languages can share. To prove that this works, created a python thrift gen task in only a handful of lines of code.
- Loading branch information
Showing
40 changed files
with
342 additions
and
127 deletions.
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 |
---|---|---|
|
@@ -25,5 +25,5 @@ scandir==1.2 | |
setproctitle==1.1.10 | ||
setuptools==30.0.0 | ||
six>=1.9.0,<2 | ||
thrift==0.9.1 | ||
thrift>=0.9.1 | ||
wheel==0.29.0 |
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
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
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
61 changes: 61 additions & 0 deletions
61
src/python/pants/backend/codegen/thrift/java/apache_thrift_java_gen.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,61 @@ | ||
# coding=utf-8 | ||
# Copyright 2014 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) | ||
|
||
from pants.backend.codegen.thrift.java.java_thrift_library import JavaThriftLibrary | ||
from pants.backend.codegen.thrift.java.thrift_defaults import ThriftDefaults | ||
from pants.backend.codegen.thrift.lib.apache_thrift_gen_base import ApacheThriftGenBase | ||
from pants.backend.jvm.targets.java_library import JavaLibrary | ||
from pants.base.exceptions import TargetDefinitionException | ||
from pants.binaries.thrift_binary import ThriftBinary | ||
|
||
|
||
class ApacheThriftJavaGen(ApacheThriftGenBase): | ||
"""Generate Java source files from thrift IDL files.""" | ||
deprecated_options_scope = 'gen.thrift' # New scope is gen.thrift-java. | ||
deprecated_options_scope_removal_version = '1.5.0dev0' | ||
|
||
thrift_library_target_type = JavaThriftLibrary | ||
thrift_generator = 'java' | ||
|
||
_COMPILER = 'thrift' | ||
_RPC_STYLE = 'sync' | ||
|
||
@classmethod | ||
def subsystem_dependencies(cls): | ||
return (super(ApacheThriftJavaGen, cls).subsystem_dependencies() + | ||
(ThriftDefaults, ThriftBinary.Factory.scoped(cls))) | ||
|
||
@classmethod | ||
def implementation_version(cls): | ||
return super(ApacheThriftJavaGen, cls).implementation_version() + [('ApacheThriftJavaGen', 2)] | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(ApacheThriftJavaGen, self).__init__(*args, **kwargs) | ||
self._thrift_defaults = ThriftDefaults.global_instance() | ||
|
||
def synthetic_target_type(self, target): | ||
return JavaLibrary | ||
|
||
def is_gentarget(self, target): | ||
return (super(ApacheThriftJavaGen, self).is_gentarget(target) and | ||
self._thrift_defaults.compiler(target) == self._COMPILER) | ||
|
||
def _validate(self, target): | ||
# TODO: Fix ThriftDefaults to only pertain to scrooge (see TODO there) and then | ||
# get rid of this spurious validation. | ||
if self._thrift_defaults.language(target) != self.thrift_generator: | ||
raise TargetDefinitionException( | ||
target, | ||
'Compiler {} supports only language={}.'.format(self._COMPILER, self.thrift_generator)) | ||
if self._thrift_defaults.rpc_style(target) != self._RPC_STYLE: | ||
raise TargetDefinitionException( | ||
target, | ||
'Compiler {} supports only rpc_style={}.'.format(self._COMPILER, self._RPC_STYLE)) | ||
|
||
def execute_codegen(self, target, target_workdir): | ||
self._validate(target) | ||
super(ApacheThriftJavaGen, self).execute_codegen(target, target_workdir) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2016 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
python_library( | ||
dependencies = [ | ||
'3rdparty/python/twitter/commons:twitter.common.collections', | ||
'src/python/pants/base:build_environment', | ||
'src/python/pants/base:exceptions', | ||
'src/python/pants/base:workunit', | ||
'src/python/pants/binaries:thrift_util', | ||
'src/python/pants/option', | ||
'src/python/pants/task', | ||
'src/python/pants/util:memo', | ||
], | ||
) |
Empty file.
Oops, something went wrong.