Skip to content

Commit

Permalink
Use tree artifacts in bootclasspath rule
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fmeum authored and Copybara-Service committed May 10, 2022
1 parent b227a9a commit ae523f8
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions tools/jdk/default_java_toolchain.bzl
Expand Up @@ -183,16 +183,7 @@ def java_runtime_files(name, srcs):
def _bootclasspath_impl(ctx):
host_javabase = ctx.attr.host_javabase[java_common.JavaRuntimeInfo]

# explicitly list output files instead of using TreeArtifact to work around
# https://github.com/bazelbuild/bazel/issues/6203
classes = [
"DumpPlatformClassPath.class",
]

class_outputs = [
ctx.actions.declare_file("%s_classes/%s" % (ctx.label.name, clazz))
for clazz in classes
]
class_dir = ctx.actions.declare_directory("%s_classes" % ctx.label.name)

args = ctx.actions.args()
args.add("-source")
Expand All @@ -203,20 +194,20 @@ def _bootclasspath_impl(ctx):
args.add("-cp")
args.add("%s/lib/tools.jar" % host_javabase.java_home)
args.add("-d")
args.add(class_outputs[0].dirname)
args.add_all([class_dir], expand_directories = False)
args.add(ctx.file.src)

ctx.actions.run(
executable = "%s/bin/javac" % host_javabase.java_home,
mnemonic = "JavaToolchainCompileClasses",
inputs = [ctx.file.src] + ctx.files.host_javabase,
outputs = class_outputs,
outputs = [class_dir],
arguments = [args],
)

bootclasspath = ctx.outputs.output_jar

inputs = class_outputs + ctx.files.host_javabase
inputs = [class_dir] + ctx.files.host_javabase

args = ctx.actions.args()
args.add("-XX:+IgnoreUnrecognizedVMOptions")
Expand All @@ -225,8 +216,9 @@ def _bootclasspath_impl(ctx):
args.add("--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED")
args.add_joined(
"-cp",
[class_outputs[0].dirname, "%s/lib/tools.jar" % host_javabase.java_home],
[class_dir, "%s/lib/tools.jar" % host_javabase.java_home],
join_with = ctx.configuration.host_path_separator,
expand_directories = False,
)
args.add("DumpPlatformClassPath")
args.add(bootclasspath)
Expand Down

0 comments on commit ae523f8

Please sign in to comment.