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

adjust transitive_proto_path_flags skylark name to transitive_proto_path #434

Merged
merged 1 commit into from
Mar 4, 2018
Merged
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
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="+_)

}