Skip to content
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

Support Pants 1.30.x #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/python/scalapb/pants/register.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from pants.build_graph.build_file_aliases import BuildFileAliases
from scalapb.pants.targets.scalapb_library import ScalaPBLibrary
from scalapb.pants.targets.target_types import ScalaPBLibraryTarget
from scalapb.pants.tasks.scalapb_gen import ScalaPBGen
from pants.goal.task_registrar import TaskRegistrar as task

def build_file_aliases():
return BuildFileAliases(
targets={
'scalapb_library': ScalaPBLibrary,
ScalaPBLibrary.alias(): ScalaPBLibrary,
}
)

def register_goals():
task(name='scalapb-gen', action=ScalaPBGen).install('gen')

def target_types():
return [ScalaPBLibraryTarget]
10 changes: 4 additions & 6 deletions src/python/scalapb/pants/targets/scalapb_library.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import logging

from pants.backend.jvm.targets.import_jars_mixin import ImportJarsMixin
from pants.backend.jvm.targets.jvm_target import JvmTarget
from pants.base.payload import Payload
from pants.base.payload_field import PrimitiveField

import os


logger = logging.getLogger(__name__)

class ScalaPBLibrary(ImportJarsMixin, JvmTarget):
"""A Java library generated from Protocol Buffer IDL files."""

Expand All @@ -39,6 +33,10 @@ def __init__(self,
})
super(ScalaPBLibrary, self).__init__(payload=payload, **kwargs)

@classmethod
def alias(cls):
return "scalapb_library"

@property
def source_root(self):
return os.path.normpath(
Expand Down
34 changes: 34 additions & 0 deletions src/python/scalapb/pants/targets/target_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from pants.engine.target import (
COMMON_TARGET_FIELDS,
Dependencies,
Sources,
StringField,
StringSequenceField,
Target,
)

from pants.backend.jvm.target_types import (
COMMON_JVM_FIELDS,
)

class Imports(StringSequenceField):
alias = "imports"

class SourceRoot(StringField):
alias = "source_root"

class ProtobufSources(Sources):
default = ("*.proto",)
expected_file_extensions = (".proto",)

class ScalaPBLibraryTarget(Target):
"""A Scala library generated from Protobuf IDL files."""

alias = "scalapb_library"
core_fields = (
*COMMON_JVM_FIELDS,
Imports,
SourceRoot,
ProtobufSources
)
v1_only = True
7 changes: 5 additions & 2 deletions src/python/scalapb/pants/tasks/scalapb_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def register_options(cls, register):
super(ScalaPBGen, cls).register_options(register)
cls.register_jvm_tool(register, 'scalapbc')
register('--protoc-version', fingerprint=True,
help='Set a specific protoc version to use.', default='330')
help='Set a specific protoc version to use.', default='3.3.0')

def synthetic_target_type(self, target):
return ScalaLibrary
Expand All @@ -48,6 +48,8 @@ def execute_codegen(self, target, target_workdir):

source_roots = self._calculate_source_roots(target)
source_roots.update(self._proto_path_imports([target]))
# This is needed when used with unpacked jars
source_roots.add(target._sources_field.sources.rel_root)

scalapb_options = []
if target.payload.java_conversions:
Expand All @@ -69,7 +71,8 @@ def execute_codegen(self, target, target_workdir):
source_roots = list(source_roots)
source_roots.sort()
for source_root in source_roots:
args.append('--proto_path={0}'.format(source_root))
if (source_root != '.'):
args.append('--proto_path={0}'.format(source_root))

classpath = self.tool_classpath('scalapbc')

Expand Down