forked from bazelbuild/rules_scala
-
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.
Wrap ScalaPbCodeGenerator, expose Scala 2.11 error
Wraps `scalapb.ScalaPbCodeGenerator` to catch and return all errors. Without this, any errors escaping from `scalapb.ScalaPbCodeGenerator` will cause the `scala_proto` aspect workers to hang. Also deletes some `@io_bazel_rules_scala` references, replacing them with `Label` instances as appropriate. The `test_scala_version 2.11.12` case from `test_version.sh` would previously hang given the combination of ScalaPB 0.9.8 (the newest available for Scala 2.11) and Protobuf v28.3. Running the following in a `test_version/test_scala_version_*` repo generated by `test_version.sh` reproduced the hang: ```txt $ bazel build --repo_env=SCALA_VERSION=2.11.12 //proto:test_proto [ ...wait 10 seconds, then CTRL-C... ] INFO: Analyzed target //proto:test_proto (2 packages loaded, 22 targets configured). INFO: Found 1 target... [1,038 / 1,047] 4 actions running ProtoScalaPBRule proto/test_service_scala_scalapb.srcjar; 10s worker ProtoScalaPBRule proto/test2_scala_scalapb.srcjar; 10s worker Target //proto:test_proto failed to build ``` With this change, the command now exposes the exact incompatibility between these versions: ```txt $ bazel build --repo_env=SCALA_VERSION=2.11.12 //proto:test_proto ERROR: .../test_version/test_scala_version_1731169107/proto/BUILD:14:14: ProtoScalaPBRule proto/test3_scala_scalapb.srcjar failed: (Exit 1): scalapb_worker failed: error executing command (from target //proto:test3) bazel-out/.../bin/external/io_bazel_rules_scala/src/scala/scripts/scalapb_worker ... (remaining 2 arguments skipped) --scala_out: java.lang.NoSuchMethodError: 'void com.google.protobuf.Descriptors$FileDescriptor.internalBuildGeneratedFileFrom(java.lang.String[], com.google.protobuf.Descriptors$FileDescriptor[], com.google.protobuf.Descriptors$FileDescriptor$InternalDescriptorAssigner)' at scalapb.options.compiler.Scalapb.<clinit>(Scalapb.java:10592) at scalapb.ScalaPbCodeGenerator$.run(ScalaPbCodeGenerator.scala:14) at scalapb.ScalaPbCodeGenerator$.run(ScalaPbCodeGenerator.scala:10) at scripts.ScalaPbCodeGenerator$.run(ScalaPbCodeGeneratorWrapper_2_11.scala:8) at protocbridge.frontend.PluginFrontend$$anonfun$runWithBytes$2.apply(PluginFrontend.scala:52) at protocbridge.frontend.PluginFrontend$$anonfun$runWithBytes$2.apply(PluginFrontend.scala:52) at scala.util.Try$.apply(Try.scala:192) at protocbridge.frontend.PluginFrontend$.runWithBytes(PluginFrontend.scala:51) at protocbridge.frontend.PluginFrontend$.runWithInputStream(PluginFrontend.scala:103) at protocbridge.frontend.PosixPluginFrontend$$anonfun$prepare$1.apply$mcV$sp(PosixPluginFrontend.scala:33) at protocbridge.frontend.PosixPluginFrontend$$anonfun$prepare$1.apply(PosixPluginFrontend.scala:31) at protocbridge.frontend.PosixPluginFrontend$$anonfun$prepare$1.apply(PosixPluginFrontend.scala:31) at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121) at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) java.lang.RuntimeException: Exit with code 1 at scala.sys.package$.error(package.scala:27) at scripts.ScalaPBWorker$.work(ScalaPBWorker.scala:44) at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:96) at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:49) at scripts.ScalaPBWorker$.main(ScalaPBWorker.scala:39) at scripts.ScalaPBWorker.main(ScalaPBWorker.scala) Target //proto:test_proto failed to build ```
- Loading branch information
Showing
7 changed files
with
107 additions
and
39 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package scripts | ||
|
||
import protocgen.{CodeGenApp,CodeGenRequest,CodeGenResponse} | ||
|
||
object ScalaPbCodeGenerator extends CodeGenApp { | ||
def process(request: CodeGenRequest): CodeGenResponse = { | ||
|
||
try { | ||
scalapb.ScalaPbCodeGenerator.process(request) | ||
|
||
} catch { | ||
case e: Throwable => | ||
val stackStream = new java.io.ByteArrayOutputStream | ||
e.printStackTrace(new java.io.PrintStream(stackStream)) | ||
CodeGenResponse.fail(stackStream.toString()) | ||
} | ||
} | ||
} |
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,20 @@ | ||
package scripts | ||
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse | ||
|
||
object ScalaPbCodeGenerator extends protocbridge.ProtocCodeGenerator { | ||
override def run(req: Array[Byte]): Array[Byte] = { | ||
|
||
try { | ||
scalapb.ScalaPbCodeGenerator.run(req) | ||
|
||
} catch { | ||
case e: Throwable => | ||
val b = CodeGeneratorResponse.newBuilder | ||
val stackStream = new java.io.ByteArrayOutputStream | ||
|
||
e.printStackTrace(new java.io.PrintStream(stackStream)) | ||
b.setError(stackStream.toString()) | ||
b.build.toByteArray | ||
} | ||
} | ||
} |
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