Skip to content

Commit cb17d24

Browse files
ckolli5comius
authored andcommitted
Fix string formatting when java_home path is missing. (bazelbuild#15769)
Fixes bazelbuild#14631 Closes bazelbuild#14686. PiperOrigin-RevId: 426080592 Co-authored-by: Ivo List <[email protected]>
1 parent 4478d01 commit cb17d24

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/test/shell/integration/bazel_java_test.sh

+16
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,22 @@ function test_no_javabase() {
267267
expect_log "bazel-bin/javabase_test/a.runfiles/local_jdk/bin/java: No such file or directory"
268268
}
269269

270+
# Tests non-existent java_home path.
271+
function test_no_java_home_path() {
272+
cat << EOF >> WORKSPACE
273+
load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository")
274+
local_java_repository(
275+
name = "javabase",
276+
java_home = "$PWD/i-dont-exist",
277+
version = "11",
278+
)
279+
EOF
280+
281+
bazel build @javabase//... >& $TEST_log && fail "Build with missing java_home should fail."
282+
expect_log "The path indicated by the \"java_home\" attribute .* does not exist."
283+
}
284+
285+
270286
function test_genrule() {
271287
cat << EOF > WORKSPACE
272288
load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository")

tools/jdk/local_java_repository.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def _local_java_repository_impl(repository_ctx):
123123
java_home = repository_ctx.attr.java_home
124124
java_home_path = repository_ctx.path(java_home)
125125
if not java_home_path.exists:
126-
fail('The path indicated by the "java_home" attribute "%s" (absolute: "%s") ' +
127-
"does not exist." % (java_home, str(java_home_path)))
126+
fail(('The path indicated by the "java_home" attribute "%s" (absolute: "%s") ' +
127+
"does not exist.") % (java_home, str(java_home_path)))
128128

129129
repository_ctx.file(
130130
"WORKSPACE",

0 commit comments

Comments
 (0)