Skip to content

Commit

Permalink
Merge pull request #434 from ittaiz/adjust_transitive_proto_path
Browse files Browse the repository at this point in the history
adjust transitive_proto_path_flags skylark name to transitive_proto_path
  • Loading branch information
johnynek authored Mar 4, 2018
2 parents 55c5bd2 + 9151c62 commit 38bc14c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions scala_proto/scala_proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,16 @@ def _colon_paths(data):

def _gen_proto_srcjar_impl(ctx):
acc_imports = depset()
transitive_proto_path_flags = depset()
transitive_proto_paths = depset()

proto_deps, jvm_deps = [], []
for target in ctx.attr.deps:
if hasattr(target, 'proto'):
proto_deps.append(target)
acc_imports += target.proto.transitive_sources
#inline this if after 0.12.0 is the oldest supported version
if hasattr(target.proto, 'transitive_proto_path_flags'):
transitive_proto_path_flags += target.proto.transitive_proto_path_flags
if hasattr(target.proto, 'transitive_proto_path'):
transitive_proto_paths += target.proto.transitive_proto_path
else:
jvm_deps.append(target)

Expand All @@ -344,7 +344,7 @@ def _gen_proto_srcjar_impl(ctx):
# Command line args to worker cannot be empty so using padding
flags_arg = "-" + ",".join(ctx.attr.flags),
# Command line args to worker cannot be empty so using padding
packages = "-" + ":".join(transitive_proto_path_flags.to_list())
packages = "-" + ":".join(transitive_proto_paths.to_list())
)
argfile = ctx.new_file(ctx.outputs.srcjar, "%s_worker_input" % ctx.label.name)
ctx.file_action(output=argfile, content=worker_content)
Expand Down
10 changes: 8 additions & 2 deletions src/scala/scripts/PBGenerateRequest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.nio.file.{Files, Path, Paths}
class PBGenerateRequest(val jarOutput: String, val scalaPBOutput: Path, val scalaPBArgs: List[String])

object PBGenerateRequest {

def from(args: java.util.List[String]): PBGenerateRequest = {
val jarOutput = args.get(0)
val parsedProtoFiles = args.get(1).split(':').toList.map { rootAndFile =>
Expand All @@ -31,15 +32,20 @@ object PBGenerateRequest {
case s if s.charAt(0) == '-' => Some(s.tail) //drop padding character
case other => sys.error(s"expected a padding character of - (dash), but found: $other")
}
val transitiveProtoPathFlags = args.get(3) match {
val transitiveProtoPaths = args.get(3) match {
case "-" => Nil
case s if s.charAt(0) == '-' => s.tail.split(':').toList //drop padding character
case other => sys.error(s"expected a padding character of - (dash), but found: $other")
}

val tmp = Paths.get(Option(System.getProperty("java.io.tmpdir")).getOrElse("/tmp"))
val scalaPBOutput = Files.createTempDirectory(tmp, "bazelscalapb")
val flagPrefix = flagOpt.fold("")(_ + ":")
val scalaPBArgs = s"--scala_out=$flagPrefix$scalaPBOutput" :: (transitiveProtoPathFlags ++ imports ++ protoFiles)
val scalaPBArgs = s"--scala_out=$flagPrefix$scalaPBOutput" :: (padWithProtoPathPrefix(transitiveProtoPaths) ++ imports ++ protoFiles)
new PBGenerateRequest(jarOutput, scalaPBOutput, scalaPBArgs)
}

private def padWithProtoPathPrefix(transitiveProtoPathFlags: List[String]) =
transitiveProtoPathFlags.map("--proto_path="+_)

}

0 comments on commit 38bc14c

Please sign in to comment.