From 4405b26687c6dfbf993bd14160b72a916bed35a4 Mon Sep 17 00:00:00 2001 From: Ryan Michael Date: Wed, 21 Aug 2019 17:26:45 -0400 Subject: [PATCH] Include transitive_proto_paths in the call to protoc Proto rules that specify `strip_import_prefix` or `import_prefix` may have a different import path than their workspace-relative path, and so may not be visible on compile. This includes the transitive proto paths for a compile target to the ScalaPB compiler invocation ensuring that such targets can be compiled. --- rules/scala_proto/private/ScalaProtoWorker.scala | 8 +++++++- rules/scala_proto/private/core.bzl | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/rules/scala_proto/private/ScalaProtoWorker.scala b/rules/scala_proto/private/ScalaProtoWorker.scala index 195e0f9a2..96433254c 100644 --- a/rules/scala_proto/private/ScalaProtoWorker.scala +++ b/rules/scala_proto/private/ScalaProtoWorker.scala @@ -29,18 +29,24 @@ object ScalaProtoWorker extends WorkerMain[Unit] { .`type`(Arguments.fileType.verifyCanRead.verifyIsFile) .setDefault_(Collections.emptyList) parser + .addArgument("-I", "--proto_path") + .help("Proto include paths") + .metavar("proto_path") + .action(Arguments.append()) + parser } override def init(args: Option[Array[String]]): Unit = () protected[this] def work(ctx: Unit, args: Array[String]): Unit = { val namespace = argParser.parseArgs(args) + val proto_paths = namespace.getList[String]("proto_path").asScala.map(f => s"--proto_path=$f").toList val sources = namespace.getList[File]("sources").asScala.toList val scalaOut = namespace.get[File]("output_dir").toPath Files.createDirectories(scalaOut) - val params = s"--scala_out=$scalaOut" :: sources.map(_.getPath) + val params = s"--scala_out=$scalaOut" :: proto_paths ++ sources.map(_.getPath) ProtocBridge.runWithGenerators( protoc = a => com.github.os72.protocjar.Protoc.runProtoc(a.toArray), diff --git a/rules/scala_proto/private/core.bzl b/rules/scala_proto/private/core.bzl index 44d7277e2..290679d66 100644 --- a/rules/scala_proto/private/core.bzl +++ b/rules/scala_proto/private/core.bzl @@ -32,6 +32,11 @@ def scala_proto_library_implementation(ctx): args = ctx.actions.args() args.add("--output_dir", gendir.path) + + for path in transitive_proto_path.to_list(): + args.add("--proto_path=" + path) + if compiler.generator_params: + args.add("--generator_params", compiler.generator_params) args.add_all("--", transitive_sources) args.set_param_file_format("multiline") args.use_param_file("@%s", use_always = True)