Pass --system path to Javac when the target JDK admits it.

Closes #16986.

PiperOrigin-RevId: 499189526
Change-Id: Ib6f93d27d6db3770b69fa499b56ac415d4c53368
diff --git a/tools/jdk/BUILD.tools b/tools/jdk/BUILD.tools
index fa7b40c..74d8d1d 100644
--- a/tools/jdk/BUILD.tools
+++ b/tools/jdk/BUILD.tools
@@ -306,8 +306,8 @@
 bootclasspath(
     name = "platformclasspath",
     src = "DumpPlatformClassPath.java",
-    host_javabase = "current_java_runtime",
-    target_javabase = "current_java_runtime",
+    host_javabase = ":current_java_runtime",
+    target_javabase = ":current_java_runtime",
 )
 
 default_java_toolchain(
diff --git a/tools/jdk/default_java_toolchain.bzl b/tools/jdk/default_java_toolchain.bzl
index 19d1413..cd95cb9 100644
--- a/tools/jdk/default_java_toolchain.bzl
+++ b/tools/jdk/default_java_toolchain.bzl
@@ -229,6 +229,10 @@
     args.add("DumpPlatformClassPath")
     args.add(bootclasspath)
 
+    system_files = ("release", "modules", "jrt-fs.jar")
+    system = [f for f in ctx.files.target_javabase if f.basename in system_files]
+    if len(system) != len(system_files):
+        system = None
     if ctx.attr.target_javabase:
         inputs.extend(ctx.files.target_javabase)
         args.add(ctx.attr.target_javabase[java_common.JavaRuntimeInfo].java_home)
@@ -242,6 +246,10 @@
     )
     return [
         DefaultInfo(files = depset([bootclasspath])),
+        java_common.BootClassPathInfo(
+            bootclasspath = [bootclasspath],
+            system = system,
+        ),
         OutputGroupInfo(jar = [bootclasspath]),
     ]
 
diff --git a/tools/jdk/jdk.BUILD b/tools/jdk/jdk.BUILD
index 86be2fe..2e2745f 100644
--- a/tools/jdk/jdk.BUILD
+++ b/tools/jdk/jdk.BUILD
@@ -182,7 +182,7 @@
 filegroup(
     name = "jdk-lib",
     srcs = glob(
-        ["lib/**"],
+        ["lib/**", "release"],
         allow_empty = True,
         exclude = [
             "lib/missioncontrol/**",