Skip to content

Commit

Permalink
Fix rules_scala JDK lookup when using --nolegacy_external_runfiles. (#…
Browse files Browse the repository at this point in the history
…1397)

* Fix rules_scala JDK lookup when using --nolegacy_external_runfiles.

java_executable_exec_path does not look up the right path when resolving
the JDK from the runfiles directory and legacy_external_runfiles is disabled.
java_executable_runfiles_path should be used instead.

Examples of these paths when running "bazel build test:ScalaBinaryInGenrule":

java_executable_exec_path: external/remotejdk11_macos/bin/java
java_executable_runfiles_path: ../remotejdk11_macos/bin/java

The working directory appears to be
ScalaBinary.runfiles/io_bazel_rules_scala.

When legacy_external_runfiles is enabled, the JDK is present in
ScalaBinary.runfiles/remotejdk11_macos but is also linked
in ScalaBinary.runfiles/io_bazel_rules_scala/external/remotejdk11_macos,
so looking up using either exec_path or runfiles_path is correct.

When legacy_external_runfiles is disabled, the JDK only goes in
ScalaBinary.runfiles/remotejdk11_macos, so only runfiles_path will work.

* Add regression test

* missing bazel
  • Loading branch information
srdo-humio authored Jun 30, 2022
1 parent 681dedd commit e14f252
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scala/private/rule_impls.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def java_bin(ctx):
default_runtime = ctx.attr._java_runtime[java_common.JavaRuntimeInfo],
)

java_path = str(java_runtime.java_executable_exec_path)
java_path = str(java_runtime.java_executable_runfiles_path)

if paths.is_absolute(java_path):
javabin = java_path
Expand Down
1 change: 1 addition & 0 deletions test_rules_scala.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ $runner bazel test "--extra_toolchains=//scala:minimal_direct_source_deps -- tes
$runner bazel build "test_expect_failure/missing_direct_deps/internal_deps/... --strict_java_deps=warn --extra_toolchains=//test/toolchains:high_level_transitive_deps_strict_deps_warn"
$runner bazel build //test_expect_failure/proto_source_root/... --strict_proto_deps=off
$runner bazel test //test/... --extra_toolchains="//test_expect_failure/plus_one_deps:plus_one_deps"
$runner bazel build test:ScalaBinaryInGenrule --nolegacy_external_runfiles
$runner bazel build //test_statsfile:Simple_statsfile
$runner bazel build //test_statsfile:SimpleNoStatsFile_statsfile --extra_toolchains="//test/toolchains:enable_stats_file_disabled_toolchain"
. "${test_dir}"/test_build_event_protocol.sh
Expand Down

0 comments on commit e14f252

Please sign in to comment.