为什么java_executable_exec_path给我一个遗留的“外部”runfiles路径

时间:2018-03-19 22:11:07

标签: java scala bazel

假设我有一个像这样的最小Scala WORKSPACE文件:

workspace(name = "scala_example")

git_repository(
    name = "io_bazel_rules_scala",
    commit = "e9e65ada59823c263352d10c30411f4739d5df25",
    remote = "https://github.com/bazelbuild/rules_scala",
)

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")
scala_repositories()

load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
scala_register_toolchains()

然后是BUILD

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_binary")

scala_binary(
    name = "example-bin",
    srcs = glob(["*.scala"]),
    main_class = "Example",
)

Example.scala

object Example { def main(args: Array[String]): Unit = println("running") }

我可以运行bazel run example-bin,一切正常。我的问题是enter image description here改变了将Java二进制路径设置为使用以下方式的方式:

ctx.attr._java_runtime[java_common.JavaRuntimeInfo].java_executable_exec_path

...而不是之前的ctx.executable._java.short_path

在此更改之后,Java二进制路径在路径中包含external目录,这似乎是遗留事物(?)。这意味着在此更改之后,如果我运行以下内容:

bazel run --nolegacy_external_runfiles example-bin

它不再有效:

INFO: Running command line: bazel-bin/example-bin
.../.cache/bazel/_bazel_travis/03e97e9dbbfe483081a6eca2764532e8/execroot/scala_example/bazel-out/k8-fastbuild/bin/example-bin.runfiles/scala_example/example-bin_wrapper.sh: line 4: .../.cache/bazel/_bazel_travis/03e97e9dbbfe483081a6eca2764532e8/execroot/scala_example/bazel-out/k8-fastbuild/bin/example-bin.runfiles/scala_example/external/local_jdk/bin/java: No such file or directory
ERROR: Non-zero return code '127' from command: Process exited with status 127

它还打破了我所期望的非external路径的一些脚本。

为什么java_executable_exec_path给我这条external路径?是否有一些选择我可以让bazel说服它不要这样做?

1 个答案:

答案 0 :(得分:1)

很抱歉回复缓慢 - 看来这是因为Scala规则错误地使用了java_executable_exec_path,而他们应该使用java_executable_runfiles_path

我发送了拉取请求来修复它,然后我意识到你已经在https://github.com/bazelbuild/rules_scala/commit/4235ef58782ce2ec82981ea70b808397b64fe7df

中做了

由于后者现在可以在HEAD与Bazel一起使用,我至少会删除丑陋。