Skip to content

Commit ae523f8

Browse files
fmeumcopybara-github
authored andcommitted
Use tree artifacts in bootclasspath rule
Remote execution now creates the directories for output tree artifacts prior to execution, so that the output of the Java compiler can be modelled as a tree artifact even though not all versions create the output directory if it doesn't exist. Closes #15384. PiperOrigin-RevId: 447759377
1 parent b227a9a commit ae523f8

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

tools/jdk/default_java_toolchain.bzl

+6-14
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,7 @@ def java_runtime_files(name, srcs):
183183
def _bootclasspath_impl(ctx):
184184
host_javabase = ctx.attr.host_javabase[java_common.JavaRuntimeInfo]
185185

186-
# explicitly list output files instead of using TreeArtifact to work around
187-
# https://github.com/bazelbuild/bazel/issues/6203
188-
classes = [
189-
"DumpPlatformClassPath.class",
190-
]
191-
192-
class_outputs = [
193-
ctx.actions.declare_file("%s_classes/%s" % (ctx.label.name, clazz))
194-
for clazz in classes
195-
]
186+
class_dir = ctx.actions.declare_directory("%s_classes" % ctx.label.name)
196187

197188
args = ctx.actions.args()
198189
args.add("-source")
@@ -203,20 +194,20 @@ def _bootclasspath_impl(ctx):
203194
args.add("-cp")
204195
args.add("%s/lib/tools.jar" % host_javabase.java_home)
205196
args.add("-d")
206-
args.add(class_outputs[0].dirname)
197+
args.add_all([class_dir], expand_directories = False)
207198
args.add(ctx.file.src)
208199

209200
ctx.actions.run(
210201
executable = "%s/bin/javac" % host_javabase.java_home,
211202
mnemonic = "JavaToolchainCompileClasses",
212203
inputs = [ctx.file.src] + ctx.files.host_javabase,
213-
outputs = class_outputs,
204+
outputs = [class_dir],
214205
arguments = [args],
215206
)
216207

217208
bootclasspath = ctx.outputs.output_jar
218209

219-
inputs = class_outputs + ctx.files.host_javabase
210+
inputs = [class_dir] + ctx.files.host_javabase
220211

221212
args = ctx.actions.args()
222213
args.add("-XX:+IgnoreUnrecognizedVMOptions")
@@ -225,8 +216,9 @@ def _bootclasspath_impl(ctx):
225216
args.add("--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED")
226217
args.add_joined(
227218
"-cp",
228-
[class_outputs[0].dirname, "%s/lib/tools.jar" % host_javabase.java_home],
219+
[class_dir, "%s/lib/tools.jar" % host_javabase.java_home],
229220
join_with = ctx.configuration.host_path_separator,
221+
expand_directories = False,
230222
)
231223
args.add("DumpPlatformClassPath")
232224
args.add(bootclasspath)

0 commit comments

Comments
 (0)