From 5fa18d12d95cd945d5ca76aba45f1b797527a95b Mon Sep 17 00:00:00 2001 From: Laszlo Csomor Date: Tue, 14 Mar 2017 15:25:13 +0000 Subject: Bazel client, Windows: can connect to fresh server Fix the bug that the MSYS-less client couldn't connect to the freshly started server and had to be started again. Fixes https://github.com/bazelbuild/bazel/issues/2672 See https://github.com/bazelbuild/bazel/issues/2107 -- PiperOrigin-RevId: 150069285 MOS_MIGRATED_REVID=150069285 --- src/main/cpp/blaze_util_windows.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/main/cpp') diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc index 5e68544317..41a99d00b7 100644 --- a/src/main/cpp/blaze_util_windows.cc +++ b/src/main/cpp/blaze_util_windows.cc @@ -520,6 +520,7 @@ string GetJvmVersion(const string& java_exe) { return ReadJvmVersion(result); } +#ifndef COMPILER_MSVC // If we pass DETACHED_PROCESS to CreateProcess(), cmd.exe appropriately // returns the command prompt when the client terminates. msys2, however, in // its infinite wisdom, waits until the *server* terminates and cannot be @@ -528,10 +529,6 @@ string GetJvmVersion(const string& java_exe) { // So, we first pretend to be a POSIX daemon so that msys2 knows about our // intentions and *then* we call CreateProcess(). Life ain't easy. static bool DaemonizeOnWindows() { -#ifdef COMPILER_MSVC - // TODO(bazel-team) 2016-11-18: implement this. - return false; -#else // not COMPILER_MSVC if (fork() > 0) { // We are the original client process. return true; @@ -548,8 +545,8 @@ static bool DaemonizeOnWindows() { // descriptors here. CreateProcess() will take care of that and it's useful // to see the error messages in ExecuteDaemon() on the console of the client. return false; -#endif // COMPILER_MSVC } +#endif // not COMPILER_MSVC // Keeping an eye on the server process on Windows is not implemented yet. // TODO(lberki): Implement this, because otherwise if we can't start up a server @@ -564,11 +561,15 @@ class DummyBlazeServerStartup : public BlazeServerStartup { void ExecuteDaemon(const string& exe, const std::vector& args_vector, const string& daemon_output, const string& server_dir, BlazeServerStartup** server_startup) { +#ifdef COMPILER_MSVC + *server_startup = new DummyBlazeServerStartup(); +#else // not COMPILER_MSVC if (DaemonizeOnWindows()) { // We are the client process *server_startup = new DummyBlazeServerStartup(); return; } +#endif // COMPILER_MSVC wstring wdaemon_output; if (!blaze_util::AsWindowsPathWithUncPrefix(daemon_output, &wdaemon_output)) { @@ -661,7 +662,9 @@ void ExecuteDaemon(const string& exe, const std::vector& args_vector, CloseHandle(processInfo.hProcess); CloseHandle(processInfo.hThread); +#ifndef COMPILER_MSVC exit(0); +#endif // COMPILER_MSVC } void BatchWaiterThread(HANDLE java_handle) { -- cgit v1.2.3