diff options
author | cushon <cushon@google.com> | 2018-03-29 09:57:36 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-29 09:59:55 -0700 |
commit | dbe1ed769d4c957d7b8aea2c9c92febfc26f022d (patch) | |
tree | c5a5592074a815e7327ff3ee3865a22dbf92bab1 | |
parent | 6db5972b93ac1178a2ddee88c56342fc4dcd2c0a (diff) |
Remove startup JVM version check
This was added during the JDK 7->8 transition to improve the diagnostic
when an older-than-supported host_javabase was used. The version number
handling doesn't work with JDK 9 (see [1]), and using Bazel binaries
with a bundled host_javabase avoid the error entirely so the message
is less important.
[1] http://openjdk.java.net/jeps/223
PiperOrigin-RevId: 190944476
-rw-r--r-- | src/BUILD | 18 | ||||
-rw-r--r-- | src/main/cpp/blaze.cc | 32 | ||||
-rw-r--r-- | src/main/cpp/blaze_util.cc | 45 | ||||
-rw-r--r-- | src/main/cpp/blaze_util.h | 14 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_platform.h | 6 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_posix.cc | 9 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_windows.cc | 72 | ||||
-rw-r--r-- | src/test/cpp/blaze_util_test.cc | 51 |
8 files changed, 1 insertions, 246 deletions
@@ -53,23 +53,6 @@ genquery( scope = ["//tools/defaults:java_toolchain"], ) -genrule( - name = "java-version", - srcs = [":java_toolchain_content"], - outs = ["java.version"], - cmd = """ - VERSION_LINE=$$(cat $< | grep target_version); - JAVA_VERSION=$$(echo $${VERSION_LINE} | sed 's/.*value=\\"\\([^\\"]\\)\\".*/\\1/'); - if [ -z "$${JAVA_VERSION}" ]; then - echo "1.8" >$@ # Java 8 is the default - elif [[ "$${JAVA_VERSION}" =~ ^[0-9]+$$ ]]; then - echo "1.$${JAVA_VERSION}" >$@ # Add 1. before 7 or 8 - else - echo "$${JAVA_VERSION}" >$@ - fi - """, -) - # Create dummy tools so we can do select to prevent building iOS target on # Linux. OSX_DUMMY_TARGETS = [ @@ -259,7 +242,6 @@ genrule( "//src/main/tools:jdk-support", "//src/main/tools:linux-sandbox", "//tools/osx:xcode-locator", - ":java-version", ], outs = ["package" + suffix + ".zip"], cmd = "$(location :package-bazel.sh) $@ " + ("" if embed else "''") + " $(SRCS)", diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc index 2a125381b1..eb555dee58 100644 --- a/src/main/cpp/blaze.cc +++ b/src/main/cpp/blaze.cc @@ -640,36 +640,6 @@ static void GoToWorkspace(const WorkspaceLayout *workspace_layout) { } } -// Check the java version if a java version specification is bundled. On -// success, returns the executable path of the java command. -static void VerifyJavaVersionAndSetJvm() { - string exe = globals->options->GetJvm(); - - string version_spec_file = blaze_util::JoinPath( - GetEmbeddedBinariesRoot(globals->options->install_base), "java.version"); - string version_spec = ""; - if (blaze_util::ReadFile(version_spec_file, &version_spec)) { - blaze_util::StripWhitespace(&version_spec); - // A version specification is given, get version of java. - string jvm_version = GetJvmVersion(exe); - - // Compare that jvm_version is found and at least the one specified. - if (jvm_version.empty()) { - die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, - "Java version not detected while at least %s is needed.\n" - "Please set JAVA_HOME.", - version_spec.c_str()); - } else if (!CheckJavaVersionIsAtLeast(jvm_version, version_spec)) { - die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, - "Java version is %s while at least %s is needed.\n" - "Please set JAVA_HOME.", - jvm_version.c_str(), version_spec.c_str()); - } - } - - globals->jvm_path = exe; -} - // Starts the Blaze server. static int StartServer(const WorkspaceLayout *workspace_layout, BlazeServerStartup **server_startup) { @@ -1489,7 +1459,7 @@ int Main(int argc, const char *argv[], WorkspaceLayout *workspace_layout, WarnFilesystemType(globals->options->output_base); ExtractData(self_path); - VerifyJavaVersionAndSetJvm(); + globals->jvm_path = globals->options->GetJvm(); blaze_server->Connect(); EnsureCorrectRunningVersion(blaze_server); diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc index e8d238a479..a2a7d3f6f1 100644 --- a/src/main/cpp/blaze_util.cc +++ b/src/main/cpp/blaze_util.cc @@ -124,51 +124,6 @@ bool SearchNullaryOption(const vector<string>& args, return result; } -// Read the Jvm version from a file descriptor. The read fd -// should contains a similar output as the java -version output. -string ReadJvmVersion(const string& version_string) { - // try to look out for 'version "' - static const string version_pattern = "version \""; - size_t found = version_string.find(version_pattern); - if (found != string::npos) { - found += version_pattern.size(); - // If we found "version \"", process until next '"' - size_t end = version_string.find("\"", found); - if (end == string::npos) { // consider end of string as a '"' - end = version_string.size(); - } - return version_string.substr(found, end - found); - } - - return ""; -} - -bool CheckJavaVersionIsAtLeast(const string &jvm_version, - const string &version_spec) { - vector<string> jvm_version_vect = blaze_util::Split(jvm_version, '.'); - int jvm_version_size = static_cast<int>(jvm_version_vect.size()); - vector<string> version_spec_vect = blaze_util::Split(version_spec, '.'); - int version_spec_size = static_cast<int>(version_spec_vect.size()); - int i; - for (i = 0; i < jvm_version_size && i < version_spec_size; i++) { - int jvm = blaze_util::strto32(jvm_version_vect[i].c_str(), NULL, 10); - int spec = blaze_util::strto32(version_spec_vect[i].c_str(), NULL, 10); - if (jvm > spec) { - return true; - } else if (jvm < spec) { - return false; - } - } - if (i < version_spec_size) { - for (; i < version_spec_size; i++) { - if (version_spec_vect[i] != "0") { - return false; - } - } - } - return true; -} - bool IsArg(const string& arg) { return blaze_util::starts_with(arg, "-") && (arg != "--help") && (arg != "-help") && (arg != "-h"); diff --git a/src/main/cpp/blaze_util.h b/src/main/cpp/blaze_util.h index 011221871e..b8055c3b0a 100644 --- a/src/main/cpp/blaze_util.h +++ b/src/main/cpp/blaze_util.h @@ -66,20 +66,6 @@ bool SearchNullaryOption(const std::vector<std::string>& args, const std::string& flag_name, const bool default_value); -// Read the JVM version from a string. The string should contain the output of a -// "java -version" execution and is supposed to contain a string of the form -// 'version "version-number"' in the first 255 bytes. If the string is found, -// version-number is returned, else the empty string is returned. -std::string ReadJvmVersion(const std::string &version_string); - -// Returns true iff jvm_version is at least the version specified by -// version_spec. -// jvm_version is supposed to be a string specifying a java runtime version -// as specified by the JSR-56 appendix A. version_spec is supposed to be a -// version is the format [0-9]+(.[1-9]+)*. -bool CheckJavaVersionIsAtLeast(const std::string &jvm_version, - const std::string &version_spec); - // Returns true iff arg is a valid command line argument for bazel. bool IsArg(const std::string& arg); diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h index 42706b50e9..6818c95ef6 100644 --- a/src/main/cpp/blaze_util_platform.h +++ b/src/main/cpp/blaze_util_platform.h @@ -114,12 +114,6 @@ int ExecuteDaemon(const std::string& exe, const std::string& server_dir, BlazeServerStartup** server_startup); -// Get the version string from the given java executable. The java executable -// is supposed to output a string in the form '.*version ".*".*'. This method -// will return the part in between the two quote or the empty string on failure -// to match the good string. -std::string GetJvmVersion(const std::string& java_exe); - // Convert a path from Bazel internal form to underlying OS form. // On Unixes this is an identity operation. // On Windows, Bazel internal form is cygwin path, and underlying OS form diff --git a/src/main/cpp/blaze_util_posix.cc b/src/main/cpp/blaze_util_posix.cc index 076985fce0..eca9fdbc6c 100644 --- a/src/main/cpp/blaze_util_posix.cc +++ b/src/main/cpp/blaze_util_posix.cc @@ -437,15 +437,6 @@ static string RunProgram(const string& exe, return string(""); // We cannot reach here, just placate the compiler. } -string GetJvmVersion(const string& java_exe) { - vector<string> args; - args.push_back("java"); - args.push_back("-version"); - - string version_string = RunProgram(java_exe, args); - return ReadJvmVersion(version_string); -} - bool CompareAbsolutePaths(const string& a, const string& b) { return a == b; } diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc index 24f72d28d4..449fd321a5 100644 --- a/src/main/cpp/blaze_util_windows.cc +++ b/src/main/cpp/blaze_util_windows.cc @@ -349,78 +349,6 @@ static void CreateCommandLine(CmdLine* result, const string& exe, } // namespace -string GetJvmVersion(const string& java_exe) { - HANDLE pipe_read, pipe_write; - - SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; - if (!::CreatePipe(&pipe_read, &pipe_write, &sa, 0)) { - pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, - "GetJvmVersion: CreatePipe"); - } - - if (!SetHandleInformation(pipe_read, HANDLE_FLAG_INHERIT, 0)) { - CloseHandle(pipe_read); - CloseHandle(pipe_write); - pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, - "GetJvmVersion: SetHandleInformation"); - } - - PROCESS_INFORMATION processInfo = {0}; - STARTUPINFOA startupInfo = {0}; - startupInfo.hStdError = pipe_write; - startupInfo.hStdOutput = pipe_write; - startupInfo.dwFlags |= STARTF_USESTDHANDLES; - - string win_java_exe; - if (!blaze_util::AsShortWindowsPath(java_exe, &win_java_exe)) { - CloseHandle(pipe_read); - CloseHandle(pipe_write); - pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, - "GetJvmVersion: AsShortWindowsPath(%s)", java_exe.c_str()); - } - win_java_exe = string("\"") + win_java_exe + "\" -version"; - - char cmdline[MAX_CMDLINE_LENGTH]; - strncpy(cmdline, win_java_exe.c_str(), win_java_exe.size() + 1); - BOOL ok = CreateProcessA( - /* lpApplicationName */ NULL, - /* lpCommandLine */ cmdline, - /* lpProcessAttributes */ NULL, - /* lpThreadAttributes */ NULL, - /* bInheritHandles */ TRUE, - /* dwCreationFlags */ 0, - /* lpEnvironment */ NULL, - /* lpCurrentDirectory */ NULL, - /* lpStartupInfo */ &startupInfo, - /* lpProcessInformation */ &processInfo); - - if (!ok) { - CloseHandle(pipe_read); - CloseHandle(pipe_write); - pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, - "RunProgram: CreateProcess(%s)", cmdline); - } - - CloseHandle(pipe_write); - std::string result = ""; - DWORD bytes_read; - CHAR buf[1024]; - - for (;;) { - ok = ::ReadFile(pipe_read, buf, 1023, &bytes_read, NULL); - if (!ok || bytes_read == 0) { - break; - } - buf[bytes_read] = 0; - result = result + buf; - } - - CloseHandle(pipe_read); - CloseHandle(processInfo.hProcess); - CloseHandle(processInfo.hThread); - return ReadJvmVersion(result); -} - static bool GetProcessStartupTime(HANDLE process, uint64_t* result) { FILETIME creation_time, dummy1, dummy2, dummy3; // GetProcessTimes cannot handle NULL arguments. diff --git a/src/test/cpp/blaze_util_test.cc b/src/test/cpp/blaze_util_test.cc index 94ed3b9f81..15963b6b5a 100644 --- a/src/test/cpp/blaze_util_test.cc +++ b/src/test/cpp/blaze_util_test.cc @@ -93,10 +93,6 @@ class BlazeUtilTest : public ::testing::Test { static void AssertReadFrom(string input) { AssertReadFrom2(input, ""); } - static void AssertReadJvmVersion(string expected, const string& input) { - ASSERT_EQ(expected, ReadJvmVersion(input)); - } - void ReadFromTest() const { AssertReadFrom( "DummyJDK Blabla\n" @@ -107,57 +103,10 @@ class BlazeUtilTest : public ::testing::Test { "More DummyJDK Blabla\n"); AssertReadFrom2("first_line\n", "second line version \"1.4.2_0\"\n"); } - - void ReadJvmVersionTest() const { - AssertReadJvmVersion("1.42", "dummyjdk version \"1.42\"\n" - "DummyJDK Blabla\n" - "More DummyJDK Blabla\n"); - AssertReadJvmVersion("1.42.qual", "dummyjdk version \"1.42.qual\"\n" - "DummyJDK Blabla\n" - "More DummyJDK Blabla\n"); - AssertReadJvmVersion("1.42.qualifie", "dummyjdk version \"1.42.qualifie"); - AssertReadJvmVersion("", "dummyjdk version "); - AssertReadJvmVersion("1.4.2_0", - "first_line\nsecond line version \"1.4.2_0\"\n"); - } - - void CheckJavaVersionIsAtLeastTest() const { - ASSERT_TRUE(CheckJavaVersionIsAtLeast("1.7.0-ver-specifier-42", "")); - ASSERT_TRUE(CheckJavaVersionIsAtLeast("1.7.0-ver-specifier-42", "0")); - ASSERT_TRUE(CheckJavaVersionIsAtLeast("1.7.0-ver-specifier-42", "1")); - ASSERT_TRUE(CheckJavaVersionIsAtLeast("1.7.0-ver-specifier-42", "1.7")); - ASSERT_TRUE(CheckJavaVersionIsAtLeast("1.7.0-ver-specifier-42", "1.7.0")); - ASSERT_TRUE(CheckJavaVersionIsAtLeast("1.7.0-ver-specifier-42", "1.0")); - ASSERT_TRUE(CheckJavaVersionIsAtLeast("1.7.0-ver-specifier-42", "1.6")); - ASSERT_TRUE(CheckJavaVersionIsAtLeast("1.42", "1")); - ASSERT_TRUE(CheckJavaVersionIsAtLeast("1.42", "1.7")); - ASSERT_TRUE(CheckJavaVersionIsAtLeast("1.42", "1.11")); - ASSERT_TRUE(CheckJavaVersionIsAtLeast("1.42.42", "1.11")); - ASSERT_TRUE(CheckJavaVersionIsAtLeast("1.42.42", "1.11.11")); - - ASSERT_FALSE(CheckJavaVersionIsAtLeast("1.7.0-ver-specifier-42", "42")); - ASSERT_FALSE(CheckJavaVersionIsAtLeast("1.7.0-ver-specifier-42", "2")); - ASSERT_FALSE(CheckJavaVersionIsAtLeast("1.7.0-ver-specifier-42", "1.8")); - ASSERT_FALSE(CheckJavaVersionIsAtLeast("1.7.0-ver-specifier-42", "1.7.1")); - ASSERT_FALSE(CheckJavaVersionIsAtLeast("1.7.0-ver-specifier-42", "1.42")); - ASSERT_FALSE(CheckJavaVersionIsAtLeast("1.42", "2")); - ASSERT_FALSE(CheckJavaVersionIsAtLeast("1.42", "1.69")); - ASSERT_FALSE(CheckJavaVersionIsAtLeast("1.42", "1.42.1")); - ASSERT_FALSE(CheckJavaVersionIsAtLeast("1.42.42", "1.42.43")); - ASSERT_FALSE(CheckJavaVersionIsAtLeast("1.42.42.0", "1.42.42.1")); - } }; -TEST_F(BlazeUtilTest, CheckJavaVersionIsAtLeast) { - CheckJavaVersionIsAtLeastTest(); -} - TEST_F(BlazeUtilTest, ReadFrom) { ReadFromTest(); } -TEST_F(BlazeUtilTest, ReadJvmVersion) { - ReadJvmVersionTest(); -} - TEST_F(BlazeUtilTest, TestSearchNullaryEmptyCase) { ASSERT_FALSE(SearchNullaryOption({}, "flag", false)); ASSERT_TRUE(SearchNullaryOption({}, "flag", true)); |