Skip to content

Commit

Permalink
Fix string formatting when java_home path is missing. (bazelbuild#15769)
Browse files Browse the repository at this point in the history
Fixes bazelbuild#14631

Closes bazelbuild#14686.

PiperOrigin-RevId: 426080592

Co-authored-by: Ivo List <ilist@google.com>
  • Loading branch information
2 people authored and fmeum committed Jul 2, 2022
1 parent 4478d01 commit cb17d24
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/test/shell/integration/bazel_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,22 @@ function test_no_javabase() {
expect_log "bazel-bin/javabase_test/a.runfiles/local_jdk/bin/java: No such file or directory"
}

# Tests non-existent java_home path.
function test_no_java_home_path() {
cat << EOF >> WORKSPACE
load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository")
local_java_repository(
name = "javabase",
java_home = "$PWD/i-dont-exist",
version = "11",
)
EOF

bazel build @javabase//... >& $TEST_log && fail "Build with missing java_home should fail."
expect_log "The path indicated by the \"java_home\" attribute .* does not exist."
}


function test_genrule() {
cat << EOF > WORKSPACE
load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository")
Expand Down
4 changes: 2 additions & 2 deletions tools/jdk/local_java_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def _local_java_repository_impl(repository_ctx):
java_home = repository_ctx.attr.java_home
java_home_path = repository_ctx.path(java_home)
if not java_home_path.exists:
fail('The path indicated by the "java_home" attribute "%s" (absolute: "%s") ' +
"does not exist." % (java_home, str(java_home_path)))
fail(('The path indicated by the "java_home" attribute "%s" (absolute: "%s") ' +
"does not exist.") % (java_home, str(java_home_path)))

repository_ctx.file(
"WORKSPACE",
Expand Down

0 comments on commit cb17d24

Please sign in to comment.