From 2a8b6579c9535b649f2970307bc058895b880eb5 Mon Sep 17 00:00:00 2001 From: cushon Date: Wed, 25 Jul 2018 10:33:40 -0700 Subject: Add a --server_javabase startup option as an alias for the LHS --host_javabase to avoid confusion between the LHS and RHS host_javabases. The LHS --host_javabase option should be considered deprecated and will eventually be removed. RELNOTES: Rename the startup flag --host_javabase to --server_javabase to avoid confusion with the build flag --host_javabase PiperOrigin-RevId: 206015757 --- scripts/bash_completion_test.sh | 2 +- site/docs/user-manual.html | 21 ++++---- src/main/cpp/blaze.cc | 8 +-- src/main/cpp/startup_options.cc | 60 +++++++++++++--------- src/main/cpp/startup_options.h | 22 ++++---- .../build/lib/runtime/HostJvmStartupOptions.java | 4 +- src/test/cpp/bazel_startup_options_test.cc | 1 + 7 files changed, 69 insertions(+), 49 deletions(-) diff --git a/scripts/bash_completion_test.sh b/scripts/bash_completion_test.sh index adb75f7149..2a7bef24e9 100755 --- a/scripts/bash_completion_test.sh +++ b/scripts/bash_completion_test.sh @@ -409,7 +409,7 @@ test_basic_subcommand_expansion() { test_common_options() { # 'Test common option completion' assert_expansion '--h' \ - '--host_j' + '--host_jvm_' assert_expansion '--host_jvm_a' \ '--host_jvm_args=' } diff --git a/site/docs/user-manual.html b/site/docs/user-manual.html index 8badefd2dd..de4363c18b 100644 --- a/site/docs/user-manual.html +++ b/site/docs/user-manual.html @@ -1777,8 +1777,7 @@ The default is armeabi-v7a.

--host_javabase label

- This option (sometimes referred to as the 'right-hand side' host_javabase) - sets the label of the base Java installation to use in the host configuration, + This option sets the label of the base Java installation to use in the host configuration, for example for host build tools including JavaBuilder and Singlejar.

@@ -1787,11 +1786,6 @@ The default is armeabi-v7a. --java_toolchain option.

-

- This option should not be confused with the startup option - --host_javabase - (sometimes known as the 'left-hand side' host_javabase). -

Build strategy options

@@ -3577,21 +3571,28 @@ adb -s deadbeef install ... base) if there is a better location in your filesystem layout.

-

--host_javabase=dir

+ +

--server_javabase=dir

Specifies the Java virtual machine in which Bazel itself runs. The value must be a path to the directory containing a JDK or JRE. It should not be a label. This option should appear before any bazel command, and not be confused with the build option - --host_javabase, for example: + --server_javabase, for example:

-  % bazel --host_javabase=/usr/local/buildtools/java/jdk9 build //foo
+  % bazel --server_javabase=/usr/local/buildtools/java/jdk9 build //foo
 

This flag does not affect the JVMs used by Bazel subprocesses such as applications, tests, tools, and so on. Use build options --javabase or --host_javabase instead.

+

+ This flag was previously named --host_javabase (sometimes referred to as the + 'left-hand side' --host_javabase), but was renamed to avoid confusion with the + build flag --host_javabase (sometimes referred to as the + 'right-hand side' --host_javabase). +

--host_jvm_args=string

diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc index 84abd69407..12c7cdd1a2 100644 --- a/src/main/cpp/blaze.cc +++ b/src/main/cpp/blaze.cc @@ -441,7 +441,7 @@ static vector GetArgumentArray( // versions. string error; blaze_exit_code::ExitCode jvm_args_exit_code = - globals->options->AddJVMArguments(globals->options->GetHostJavabase(), + globals->options->AddJVMArguments(globals->options->GetServerJavabase(), &result, user_options, &error); if (jvm_args_exit_code != blaze_exit_code::SUCCESS) { BAZEL_DIE(jvm_args_exit_code) << error; @@ -576,9 +576,9 @@ static vector GetArgumentArray( // These flags are passed to the java process only for Blaze reporting // purposes; the real interpretation of the jvm flags occurs when we set up // the java command line. - if (!globals->options->GetExplicitHostJavabase().empty()) { - result.push_back("--host_javabase=" + - globals->options->GetExplicitHostJavabase()); + if (!globals->options->GetExplicitServerJavabase().empty()) { + result.push_back("--server_javabase=" + + globals->options->GetExplicitServerJavabase()); } if (globals->options->host_jvm_debug) { result.push_back("--host_jvm_debug"); diff --git a/src/main/cpp/startup_options.cc b/src/main/cpp/startup_options.cc index 9f0589d3da..b2db261526 100644 --- a/src/main/cpp/startup_options.cc +++ b/src/main/cpp/startup_options.cc @@ -138,7 +138,9 @@ StartupOptions::StartupOptions(const string &product_name, RegisterUnaryStartupFlag("command_port"); RegisterUnaryStartupFlag("connect_timeout_secs"); RegisterUnaryStartupFlag("experimental_oom_more_eagerly_threshold"); + // TODO(b/5568649): remove this deprecated alias for server_javabase RegisterUnaryStartupFlag("host_javabase"); + RegisterUnaryStartupFlag("server_javabase"); RegisterUnaryStartupFlag("host_jvm_args"); RegisterUnaryStartupFlag("host_jvm_profile"); RegisterUnaryStartupFlag("invocation_policy"); @@ -222,12 +224,16 @@ blaze_exit_code::ExitCode StartupOptions::ProcessArg( NULL) { host_jvm_profile = value; option_sources["host_jvm_profile"] = rcfile; - } else if ((value = GetUnaryOption(arg, next_arg, "--host_javabase")) != + } else if ((value = GetUnaryOption(arg, next_arg, "--server_javabase")) != NULL) { // TODO(bazel-team): Consider examining the javabase and re-execing in case // of architecture mismatch. - host_javabase = blaze::AbsolutePathFromFlag(value); - option_sources["host_javabase"] = rcfile; + ProcessServerJavabase(value, rcfile); + } else if ((value = GetUnaryOption(arg, next_arg, "--host_javabase")) != + NULL) { + ProcessServerJavabase(value, rcfile); + BAZEL_LOG(WARNING) << "The startup option --host_javabase is " + "deprecated; prefer --server_javabase."; } else if ((value = GetUnaryOption(arg, next_arg, "--host_jvm_args")) != NULL) { host_jvm_args.push_back(value); @@ -379,6 +385,12 @@ blaze_exit_code::ExitCode StartupOptions::ProcessArg( return blaze_exit_code::SUCCESS; } +void StartupOptions::ProcessServerJavabase(const char *value, + const string &rcfile) { + server_javabase_ = blaze::AbsolutePathFromFlag(value); + option_sources["server_javabase"] = rcfile; +} + blaze_exit_code::ExitCode StartupOptions::ProcessArgs( const std::vector& rcstartup_flags, std::string *error) { @@ -427,16 +439,16 @@ string StartupOptions::GetEmbeddedJavabase() { return ""; } -string StartupOptions::GetHostJavabase() { - // 1) Allow overriding the host_javabase via --host_javabase. - if (!host_javabase.empty()) { - return host_javabase; +string StartupOptions::GetServerJavabase() { + // 1) Allow overriding the server_javabase via --server_javabase. + if (!server_javabase_.empty()) { + return server_javabase_; } - if (default_host_javabase.empty()) { + if (default_server_javabase_.empty()) { string bundled_jre_path = GetEmbeddedJavabase(); if (!bundled_jre_path.empty()) { // 2) Use a bundled JVM if we have one. - default_host_javabase = bundled_jre_path; + default_server_javabase_ = bundled_jre_path; } else { // 3) Otherwise fall back to using the default system JVM. string system_javabase = GetSystemJavabase(); @@ -445,19 +457,19 @@ string StartupOptions::GetHostJavabase() { << "Could not find system javabase. Ensure JAVA_HOME is set, or " "javac is on your PATH."; } - default_host_javabase = system_javabase; + default_server_javabase_ = system_javabase; } } - return default_host_javabase; + return default_server_javabase_; } -string StartupOptions::GetExplicitHostJavabase() const { - return host_javabase; +string StartupOptions::GetExplicitServerJavabase() const { + return server_javabase_; } string StartupOptions::GetJvm() { string java_program = - blaze_util::JoinPath(GetHostJavabase(), GetJavaBinaryUnderJavabase()); + blaze_util::JoinPath(GetServerJavabase(), GetJavaBinaryUnderJavabase()); if (!blaze_util::CanExecuteFile(java_program)) { if (!blaze_util::PathExists(java_program)) { BAZEL_LOG(ERROR) << "Couldn't find java at '" << java_program << "'."; @@ -469,12 +481,14 @@ string StartupOptions::GetJvm() { exit(1); } // If the full JDK is installed - string jdk_rt_jar = blaze_util::JoinPath(GetHostJavabase(), "jre/lib/rt.jar"); + string jdk_rt_jar = + blaze_util::JoinPath(GetServerJavabase(), "jre/lib/rt.jar"); // If just the JRE is installed - string jre_rt_jar = blaze_util::JoinPath(GetHostJavabase(), "lib/rt.jar"); + string jre_rt_jar = blaze_util::JoinPath(GetServerJavabase(), "lib/rt.jar"); // rt.jar does not exist in java 9+ so check for java instead - string jre_java = blaze_util::JoinPath(GetHostJavabase(), "bin/java"); - string jre_java_exe = blaze_util::JoinPath(GetHostJavabase(), "bin/java.exe"); + string jre_java = blaze_util::JoinPath(GetServerJavabase(), "bin/java"); + string jre_java_exe = + blaze_util::JoinPath(GetServerJavabase(), "bin/java.exe"); if (blaze_util::CanReadFile(jdk_rt_jar) || blaze_util::CanReadFile(jre_rt_jar) || blaze_util::CanReadFile(jre_java) || @@ -483,7 +497,7 @@ string StartupOptions::GetJvm() { } BAZEL_LOG(ERROR) << "Problem with java installation: couldn't find/access " "rt.jar or java in " - << GetHostJavabase(); + << GetServerJavabase(); exit(1); } @@ -504,10 +518,10 @@ void StartupOptions::AddJVMArgumentSuffix(const string &real_install_dir, } blaze_exit_code::ExitCode StartupOptions::AddJVMArguments( - const string &host_javabase, std::vector *result, + const string &server_javabase, std::vector *result, const vector &user_options, string *error) const { AddJVMLoggingArguments(result); - return AddJVMMemoryArguments(host_javabase, result, user_options, error); + return AddJVMMemoryArguments(server_javabase, result, user_options, error); } void StartupOptions::AddJVMLoggingArguments(std::vector *result) const { @@ -534,8 +548,8 @@ void StartupOptions::AddJVMLoggingArguments(std::vector *result) const { } blaze_exit_code::ExitCode StartupOptions::AddJVMMemoryArguments( - const string &host_javabase, std::vector *result, - const vector &user_options, string *error) const { + const string &, std::vector *, const vector &, + string *) const { return blaze_exit_code::SUCCESS; } diff --git a/src/main/cpp/startup_options.h b/src/main/cpp/startup_options.h index 3998195545..af9f276e24 100644 --- a/src/main/cpp/startup_options.h +++ b/src/main/cpp/startup_options.h @@ -110,6 +110,10 @@ class StartupOptions { bool *is_space_separated, std::string *error); + // Processes the --server_javabase flag, or its deprecated alias + // --host_javabase. + void ProcessServerJavabase(const char *value, const std::string &rcfile); + // Process an ordered list of RcStartupFlags using ProcessArg. blaze_exit_code::ExitCode ProcessArgs( const std::vector& rcstartup_flags, @@ -167,7 +171,7 @@ class StartupOptions { // Returns the exit code after this operation. "error" will be set to a // descriptive string for any value other than blaze_exit_code::SUCCESS. blaze_exit_code::ExitCode AddJVMArguments( - const std::string &host_javabase, std::vector *result, + const std::string &server_javabase, std::vector *result, const std::vector &user_options, std::string *error) const; // Adds JVM logging-related flags for Bazel. @@ -181,8 +185,8 @@ class StartupOptions { // This is called by StartupOptions::AddJVMArguments and is a separate method // so that subclasses of StartupOptions can override it. virtual blaze_exit_code::ExitCode AddJVMMemoryArguments( - const std::string &host_javabase, std::vector *result, - const std::vector &user_options, std::string *error) const; + const std::string &server_javabase, std::vector *result, + const std::vector &user_options, std::string *error) const; // Checks whether the argument is a valid nullary option. // E.g. --master_bazelrc, --nomaster_bazelrc. @@ -270,12 +274,12 @@ class StartupOptions { std::string GetEmbeddedJavabase(); // Returns the GetHostJavabase. This should be called after parsing - // the --host_javabase option. - std::string GetHostJavabase(); + // the --server_javabase option. + std::string GetServerJavabase(); - // Returns the explicit value of the --host_javabase startup option or the + // Returns the explicit value of the --server_javabase startup option or the // empty string if it was not specified on the command line. - std::string GetExplicitHostJavabase() const; + std::string GetExplicitServerJavabase() const; // Port to start up the gRPC command server on. If 0, let the kernel choose. int command_port; @@ -310,8 +314,8 @@ class StartupOptions { void RegisterNullaryStartupFlag(const std::string& flag_name); private: - std::string host_javabase; - std::string default_host_javabase; + std::string server_javabase_; + std::string default_server_javabase_; // Contains the collection of startup flags that Bazel accepts. std::set> valid_startup_flags; 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 28e07bb0ff..3677c7c222 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 @@ -30,13 +30,13 @@ import java.util.List; public class HostJvmStartupOptions extends OptionsBase { @Option( - name = "host_javabase", + name = "server_javabase", defaultValue = "", // NOTE: purely decorative! See BlazeServerStartupOptions. valueHelp = "", documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, effectTags = {OptionEffectTag.UNKNOWN}, help = "Path to the JVM used to execute Bazel itself.") - public String hostJavabase; + public String serverJavabase; @Option( name = "host_jvm_args", diff --git a/src/test/cpp/bazel_startup_options_test.cc b/src/test/cpp/bazel_startup_options_test.cc index 686f43178d..ff37ed4781 100644 --- a/src/test/cpp/bazel_startup_options_test.cc +++ b/src/test/cpp/bazel_startup_options_test.cc @@ -95,6 +95,7 @@ TEST_F(BazelStartupOptionsTest, ValidStartupFlags) { ExpectIsUnaryOption(options, "connect_timeout_secs"); ExpectIsUnaryOption(options, "experimental_oom_more_eagerly_threshold"); ExpectIsUnaryOption(options, "host_javabase"); + ExpectIsUnaryOption(options, "server_javabase"); ExpectIsUnaryOption(options, "host_jvm_args"); ExpectIsUnaryOption(options, "host_jvm_profile"); ExpectIsUnaryOption(options, "invocation_policy"); -- cgit v1.2.3