Convey the value of the --host_javabase startup option to the server.

--
PiperOrigin-RevId: 149282686
MOS_MIGRATED_REVID=149282686
diff --git a/scripts/bash_completion_test.sh b/scripts/bash_completion_test.sh
index 1f261bc..3bf7999 100755
--- a/scripts/bash_completion_test.sh
+++ b/scripts/bash_completion_test.sh
@@ -409,7 +409,7 @@
 test_common_options() {
     # 'Test common option completion'
     assert_expansion '--h' \
-                     '--host_jvm_'
+                     '--host_j'
     assert_expansion '--host_jvm_a' \
                      '--host_jvm_args='
 }
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index eec8f47..5fdf5ad 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -481,6 +481,11 @@
     result.push_back("--use_custom_exit_code_on_abrupt_exit=false");
   }
 
+  if (!globals->options->GetExplicitHostJavabase().empty()) {
+    result.push_back("--host_javabase=" +
+                     globals->options->GetExplicitHostJavabase());
+  }
+
   // This is only for Blaze reporting purposes; the real interpretation of the
   // jvm flags occurs when we set up the java command line.
   if (globals->options->host_jvm_debug) {
diff --git a/src/main/cpp/startup_options.cc b/src/main/cpp/startup_options.cc
index 9c1a16b..b605de3 100644
--- a/src/main/cpp/startup_options.cc
+++ b/src/main/cpp/startup_options.cc
@@ -348,8 +348,17 @@
 
 string StartupOptions::GetHostJavabase() {
   if (host_javabase.empty()) {
-    host_javabase = GetDefaultHostJavabase();
+    if (default_host_javabase.empty()) {
+      default_host_javabase = GetDefaultHostJavabase();
+    }
+
+    return default_host_javabase;
+  } else {
+    return host_javabase;
   }
+}
+
+string StartupOptions::GetExplicitHostJavabase() const {
   return host_javabase;
 }
 
diff --git a/src/main/cpp/startup_options.h b/src/main/cpp/startup_options.h
index 7bde6e7..a931ab9 100644
--- a/src/main/cpp/startup_options.h
+++ b/src/main/cpp/startup_options.h
@@ -195,6 +195,10 @@
   // the --host_javabase option.
   std::string GetHostJavabase();
 
+  // Returns the explicit value of the --host_javabase startup option or the
+  // empty string if it was not specified on the command line.
+  std::string GetExplicitHostJavabase() const;
+
   // Port for gRPC command server. 0 means let the kernel choose, -1 means no
   // gRPC command server.
   int command_port;
@@ -230,6 +234,7 @@
 
  private:
   std::string host_javabase;
+  std::string default_host_javabase;
 };
 
 }  // namespace blaze
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/HostJvmStartupOptions.java b/src/main/java/com/google/devtools/build/lib/runtime/HostJvmStartupOptions.java
index 449f452..368b231 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/HostJvmStartupOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/HostJvmStartupOptions.java
@@ -28,6 +28,13 @@
  */
 public class HostJvmStartupOptions extends OptionsBase {
 
+  @Option(name = "host_javabase",
+          defaultValue = "", // NOTE: purely decorative! Se BlazeServerStartupOptions.
+          category = "host jvm startup",
+          valueHelp = "<jvm path>",
+          help = "Path to the JVM used to execute Blaze itself.")
+  public String hostJavabase;
+
   @Option(name = "host_jvm_args",
           defaultValue = "", // NOTE: purely decorative!  See BlazeServerStartupOptions.
           category = "host jvm startup",