Bazel client: explain the name of A-server.jar

Also add a helper method to GlobalVariables to
retrieve this path, thus concentrating the
assumptions about the layout of extracted_binaries
in one place.

Change-Id: If172b6f5bf4451845ad89d3d488ef2a2c2e5d286
PiperOrigin-RevId: 158241854
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 0b22226..38a92d9 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -397,8 +397,8 @@
   }
   result.insert(result.end(), user_options.begin(), user_options.end());
 
-  globals->options->AddJVMArgumentSuffix(
-      real_install_dir, globals->extracted_binaries[0], &result);
+  globals->options->AddJVMArgumentSuffix(real_install_dir,
+                                         globals->ServerJarPath(), &result);
 
   // JVM arguments are complete. Now pass in Blaze startup options.
   // Note that we always use the --flag=ARG form (instead of the --flag ARG one)
@@ -611,8 +611,8 @@
     globals->restart_reason = NO_DAEMON;
   }
 
-  string exe = globals->options->GetExe(globals->jvm_path,
-                                        globals->extracted_binaries[0]);
+  string exe =
+      globals->options->GetExe(globals->jvm_path, globals->ServerJarPath());
   // Go to the workspace before we daemonize, so
   // we can still print errors to the terminal.
   GoToWorkspace(workspace_layout);
@@ -665,8 +665,8 @@
 
   GoToWorkspace(workspace_layout);
 
-  string exe = globals->options->GetExe(globals->jvm_path,
-                                        globals->extracted_binaries[0]);
+  string exe =
+      globals->options->GetExe(globals->jvm_path, globals->ServerJarPath());
   ExecuteProgram(exe, jvm_args_vector);
   pdie(blaze_exit_code::INTERNAL_ERROR, "execv of '%s' failed", exe.c_str());
 }
diff --git a/src/main/cpp/global_variables.h b/src/main/cpp/global_variables.h
index 4774f29..061e283 100644
--- a/src/main/cpp/global_variables.h
+++ b/src/main/cpp/global_variables.h
@@ -44,6 +44,12 @@
 struct GlobalVariables {
   GlobalVariables(OptionProcessor *option_processor);
 
+  std::string ServerJarPath() const {
+    // The server jar is called "A-server.jar" so it's the first binary we
+    // extracted.
+    return extracted_binaries.empty() ? "" : extracted_binaries[0];
+  }
+
   // Used to make concurrent invocations of this program safe.
   std::string lockfile;  // = <output_base>/lock
 
diff --git a/src/package-bazel.sh b/src/package-bazel.sh
index 19cda68..7851751 100755
--- a/src/package-bazel.sh
+++ b/src/package-bazel.sh
@@ -34,6 +34,8 @@
 trap "rm -fr ${PACKAGE_DIR}" EXIT
 
 cp $* ${PACKAGE_DIR}
+# The server jar needs to be the first binary we extract. This is how the Bazel
+# client knows what .jar to pass to the JVM.
 cp ${DEPLOY_JAR} ${PACKAGE_DIR}/A-server.jar
 cp ${INSTALL_BASE_KEY} ${PACKAGE_DIR}/install_base_key
 # The timestamp of embedded tools should already be zeroed out in the input zip