Skip to content

Commit 7c332b5

Browse files
cushonbuchgr
authored andcommitted
In java_rules_skylark depend on the javabase through //tools/jdk:current_java_runtime
instead of referencing @local_jdk directly. See #5594 PiperOrigin-RevId: 207889762
1 parent b9c5065 commit 7c332b5

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

tools/build_rules/java_rules_skylark.bzl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@ def java_library_impl(ctx):
5050
cmd = "set -e;rm -rf " + build_output + " " + java_output + " " + javalist_output + "\n"
5151
cmd += "mkdir " + build_output + " " + java_output + "\n"
5252
files = " @" + sources_param_file.path
53+
java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo]
54+
jar_path = "%s/bin/jar" % java_runtime.java_home
5355

5456
if ctx.files.srcjars:
5557
files += " @" + javalist_output
5658
for file in ctx.files.srcjars:
57-
cmd += "%s tf %s | grep '\.java$' | sed 's|^|%s/|' >> %s\n" % (ctx.file._jar.path, file.path, java_output, javalist_output)
59+
cmd += "%s tf %s | grep '\.java$' | sed 's|^|%s/|' >> %s\n" % (jar_path, file.path, java_output, javalist_output)
5860
cmd += "unzip %s -d %s >/dev/null\n" % (file.path, java_output)
5961

6062
if ctx.files.srcs or ctx.files.srcjars:
61-
cmd += ctx.file._javac.path
63+
cmd += "%s/bin/javac" % java_runtime.java_home
6264
cmd += " " + " ".join(javac_options)
6365
if compile_time_jars:
6466
cmd += " -classpath '" + cmd_helper.join_paths(ctx.configuration.host_path_separator, compile_time_jars) + "'"
@@ -68,11 +70,11 @@ def java_library_impl(ctx):
6870
# stick them in the root of the jar.
6971
for r in ctx.files.resources:
7072
cmd += "cp %s %s\n" % (r.path, build_output)
71-
cmd += (ctx.file._jar.path + " cf " + class_jar.path + " -C " + build_output + " .\n" +
73+
cmd += (jar_path + " cf " + class_jar.path + " -C " + build_output + " .\n" +
7274
"touch " + build_output + "\n")
7375
ctx.action(
7476
inputs = (sources + compile_time_jars_list + [sources_param_file] +
75-
[ctx.file._jar] + ctx.files._jdk + ctx.files.resources + ctx.files.srcjars),
77+
ctx.files._jdk + ctx.files.resources + ctx.files.srcjars),
7678
outputs = [class_jar],
7779
mnemonic = "JavacBootstrap",
7880
command = cmd,
@@ -95,6 +97,8 @@ def java_binary_impl(ctx):
9597
manifest = ctx.outputs.manifest
9698
build_output = deploy_jar.path + ".build_output"
9799
main_class = ctx.attr.main_class
100+
java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo]
101+
jar_path = "%s/bin/jar" % java_runtime.java_home
98102
ctx.file_action(
99103
output = manifest,
100104
content = "Main-Class: " + main_class + "\n",
@@ -105,7 +109,7 @@ def java_binary_impl(ctx):
105109
cmd = "set -e;rm -rf " + build_output + ";mkdir " + build_output + "\n"
106110
for jar in library_result.runtime_jars:
107111
cmd += "unzip -qn " + jar.path + " -d " + build_output + "\n"
108-
cmd += (ctx.file._jar.path + " cmf " + manifest.path + " " +
112+
cmd += (jar_path + " cmf " + manifest.path + " " +
109113
deploy_jar.path + " -C " + build_output + " .\n" +
110114
"touch " + build_output + "\n")
111115

@@ -138,7 +142,7 @@ def java_binary_impl(ctx):
138142
" fi",
139143
"fi",
140144
"",
141-
"jvm_bin=%s" % (ctx.file._java.path),
145+
"jvm_bin=%s" % (ctx.attr._jdk[java_common.JavaRuntimeInfo].java_executable_exec_path),
142146
"if [[ ! -x ${jvm_bin} ]]; then",
143147
" jvm_bin=$(which java)",
144148
"fi",
@@ -182,11 +186,11 @@ def java_import_impl(ctx):
182186
)
183187

184188
java_library_attrs = {
185-
"_java": attr.label(default = Label("//tools/jdk:java"), single_file = True),
186-
"_javac": attr.label(default = Label("//tools/jdk:javac"), single_file = True),
187-
"_jar": attr.label(default = Label("//tools/jdk:jar"), single_file = True),
188-
"_jdk": attr.label(default = Label("//tools/jdk:jdk"), allow_files = True),
189-
"data": attr.label_list(allow_files = True, cfg = "data"),
189+
"_jdk": attr.label(
190+
default = Label("//tools/jdk:current_java_runtime"),
191+
providers = [java_common.JavaRuntimeInfo],
192+
),
193+
"data": attr.label_list(allow_files = True),
190194
"resources": attr.label_list(allow_files = True),
191195
"srcs": attr.label_list(allow_files = java_filetype),
192196
"jars": attr.label_list(allow_files = jar_filetype),

0 commit comments

Comments
 (0)