Build a version of Bazel with a bundled OpenJDK inside the binary.

We're using Azul Systems, Inc.'s ZuluĀ® OpenJDK build[1], as it's a good
vanilla build of OpenJDK available for our three most important
platforms:

  zulu8.20.0.5-jdk8.0.121-linux_x64.tar.gz
  zulu8.20.0.5-jdk8.0.121-macosx_x64.zip
  zulu8.20.0.5-jdk8.0.121-win_x64.zip

You can build & run a Bazel binary with an embedded JDK by simple doing:

  bazel build //src:bazel_with_jdk
  bazel-bin/src/bazel_with_jdk info

The "bazel license" command prints the license of the embedded OpenJDK.

We mirror the binaries and sources of the OpenJDK used for bundling on
this website:

https://bazel-mirror.storage.googleapis.com/openjdk/index.html

RELNOTES: Bazel can now be built with a bundled version of the OpenJDK.
This makes it possible to use Bazel on systems without a JDK, or where
the installed JDK is too old.

[1] http://www.azul.com/downloads/zulu/

--
PiperOrigin-RevId: 150440467
MOS_MIGRATED_REVID=150440467
diff --git a/src/main/cpp/startup_options.cc b/src/main/cpp/startup_options.cc
index 414e95d..55cc85d 100644
--- a/src/main/cpp/startup_options.cc
+++ b/src/main/cpp/startup_options.cc
@@ -347,9 +347,19 @@
 }
 
 string StartupOptions::GetHostJavabase() {
+  // 1) Allow overriding the host_javabase via --host_javabase.
   if (host_javabase.empty()) {
     if (default_host_javabase.empty()) {
-      default_host_javabase = GetDefaultHostJavabase();
+      string bundled_jre_path = blaze_util::JoinPath(
+          install_base, "_embedded_binaries/embedded_tools/jdk");
+      if (blaze_util::CanExecuteFile(blaze_util::JoinPath(
+              bundled_jre_path, GetJavaBinaryUnderJavabase()))) {
+        // 2) Use a bundled JVM if we have one.
+        default_host_javabase = bundled_jre_path;
+      } else {
+        // 3) Otherwise fall back to using the default system JVM.
+        default_host_javabase = GetDefaultHostJavabase();
+      }
     }
 
     return default_host_javabase;