bazel-contrib / bazel-contrib/rules_scala
FileAlreadyExistsException during proto compilation
- Dominant language
- Starlark
- Stars
- 384
- Forks
- 292
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 47
Description
Hello!
I've tried to use latest `rules_scala` version (`8092d5f6165a8d9c4797d5f089c1ba4eee3326b1`) and faced an interesting problem: during proto compilation of independent rules bazel if both are depending on some common protobuf (like timestamp.proto), bazel crashes with `FileAlreadyExistsException`. If you just rerun the previous command, everything will pass successfully. It looks like there is some kind of conflict (or just forgot to check that file already exists) during creation of `_virtual_imports`:
```
sholokhov$ bazel build //shared-libs/protocols:service_events_scala_proto
INFO: Invocation ID: 216a834e-0e37-4dac-8306-3e6f0f61386a
INFO: Analyzed target //shared-libs/protocols:service_events_scala_proto (96 packages loaded, 1058 targets configured).
INFO: Found 1 target...
INFO: From Linking external/com_google_protobuf/libprotobuf_lite.a [for host]:
/Library/Developer/CommandLineTools/usr/bin/libtool: file: bazel-out/host/bin/external/com_google_protobuf/_objs/protobuf_lite/io_win32.o has no symbols
INFO: From Linking external/com_google_protobuf/libprotobuf.a [for host]:
/Library/Developer/CommandLineTools/usr/bin/libtool: file: bazel-out/host/bin/external/com_google_protobuf/_objs/protobuf/error_listener.o has no symbols
INFO: From Building external/com_google_protobuf/libprotobuf_java.jar (122 source files, 1 source jar) [for host]:
warning: -parameters is not supported for target value 1.7. Use 1.8 or later.
INFO: From scala @io_bazel_rules_scala//src/scala/scripts:scalapb_generator_lib [for host]:
warning: there was one deprecation warning
warning: there were two deprecation warnings (since 2.11.0)
warning: there were three deprecation warnings in total; re-run with -deprecation for details
three warnings found
ERROR: /code/shared-libs/protocols/BUILD.bazel:34:1: creating scalapb files //shared-libs/protocols:iam_events_proto failed (Exit 1)
java.nio.file.FileAlreadyExistsException: external/com_google_protobuf/google/protobuf/timestamp.proto
at java.base/sun.nio.fs.UnixCopyFile.copy(UnixCopyFile.java:573)
at java.base/sun.nio.fs.UnixFileSystemProvider.copy(UnixFileSystemProvider.java:254)
at java.base/java.nio.file.Files.copy(Files.java:1294)
at scripts.ScalaPBGenerator.$anonfun$setupIncludedProto$1(ScalaPBGenerator.scala:42)
at scala.collection.immutable.List.foreach(List.scala:392)
at scripts.ScalaPBGenerator.setupIncludedProto(ScalaPBGenerator.scala:37)
at scripts.ScalaPBGenerator.processRequest(ScalaPBGenerator.scala:53)
at io.bazel.rulesscala.worker.GenericWorker.runPersistentWorker(GenericWorker.java:45)
at io.bazel.rulesscala.worker.GenericWorker.run(GenericWorker.java:111)
at scripts.ScalaPBWorker$.main(ScalaPBGenerator.scala:26)
at scripts.ScalaPBWorker.main(ScalaPBGenerator.scala)
Target //shared-libs/protocols:service_events_scala_proto failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 56.293s, Critical Path: 32.41s
INFO: 206 processes: 1 remote cache hit, 193 darwin-sandbox, 12 worker.
FAILED: Build did NOT complete successfully
# just rerun previous command
sholokhov$ bazel build //shared-libs/protocols:service_events_scala_proto
INFO: Invocation ID: 57ca90aa-87b8-445c-b170-98689f1aa259
INFO: Analyzed target //shared-libs/protocols:service_events_scala_proto (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //shared-libs/protocols:service_events_scala_proto up-to-date:
bazel-bin/shared-libs/protocols/billing_events_proto_scalapb.jar
bazel-bin/shared-libs/protocols/iam_events_proto_scalapb.jar
INFO: Elapsed time: 12.149s, Critical Path: 11.99s
INFO: 8 processes: 8 worker.
INFO: Build completed successfully, 9 total actions
```
Bazel 0.27.0.
Just in case, dependency graph:

Contributor guide
Research direction
Start with scripts/ScalaPBGenerator.scala, especially setupIncludedProto at the stack-trace location, and reproduce the failure with the Bazel target //shared-libs/protocols:service_events_scala_proto. Investigate the duplicate timestamp.proto copy during independent proto compilation; done means the first build completes without FileAlreadyExistsException, rather than succeeding only after a rerun.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100