diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/cpp/blaze.cc | 7 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_platform.h | 5 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_posix.cc | 2 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_windows.cc | 19 |
4 files changed, 33 insertions, 0 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc index 653c67239f..cca002de10 100644 --- a/src/main/cpp/blaze.cc +++ b/src/main/cpp/blaze.cc @@ -1323,6 +1323,13 @@ int Main(int argc, const char *argv[], WorkspaceLayout *workspace_layout, globals = new GlobalVariables(option_processor); blaze::SetupStdStreams(); + if (argc == 1 && blaze::WarnIfStartedFromDesktop()) { + // Only check and warn for from-desktop start if there were no args. + // In this case the user probably clicked Bazel's icon (as opposed to either + // starting it from a terminal, or as a subprocess with args, or on Windows + // from a ".lnk" file with some args). + return blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR; + } // Best-effort operation to raise the resource limits from soft to hard. We // do this early during the main program instead of just before execing the diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h index 7e5749279d..a40ce95939 100644 --- a/src/main/cpp/blaze_util_platform.h +++ b/src/main/cpp/blaze_util_platform.h @@ -198,6 +198,11 @@ void SetEnv(const std::string& name, const std::string& value); void UnsetEnv(const std::string& name); +// Returns true and prints a warning if Bazel was started by clicking its icon. +// This is typical on Windows. Other platforms should return false, unless they +// wish to handle this case too. +bool WarnIfStartedFromDesktop(); + // Ensure we have open file descriptors for stdin/stdout/stderr. void SetupStdStreams(); diff --git a/src/main/cpp/blaze_util_posix.cc b/src/main/cpp/blaze_util_posix.cc index 4915f99d1d..fcf6d5cab6 100644 --- a/src/main/cpp/blaze_util_posix.cc +++ b/src/main/cpp/blaze_util_posix.cc @@ -512,6 +512,8 @@ void UnsetEnv(const string& name) { unsetenv(name.c_str()); } +bool WarnIfStartedFromDesktop() { return false; } + void SetupStdStreams() { // Set non-buffered output mode for stderr/stdout. The server already // line-buffers messages where it makes sense, so there's no need to do set diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc index dce52d5ad0..cffe06f350 100644 --- a/src/main/cpp/blaze_util_windows.cc +++ b/src/main/cpp/blaze_util_windows.cc @@ -1166,6 +1166,25 @@ void SetEnv(const string& name, const string& value) { void UnsetEnv(const string& name) { SetEnv(name, ""); } +bool WarnIfStartedFromDesktop() { + // GetConsoleProcessList returns: + // 0, if no console attached (Bazel runs as a subprocess) + // 1, if Bazel was started by clicking on its icon + // 2, if Bazel was started from the command line (even if its output is + // redirected) + DWORD dummy[2] = {0}; + if (GetConsoleProcessList(dummy, 2) != 1) { + return false; + } + printf( + "Bazel is a command line tool.\n\n" + "Try opening a console, such as the Windows Command Prompt (cmd.exe) " + "or PowerShell, and running \"bazel help\".\n\n" + "Press Enter to close this window..."); + ReadFile(GetStdHandle(STD_INPUT_HANDLE), dummy, 1, dummy, NULL); + return true; +} + #ifndef ENABLE_PROCESSED_OUTPUT // From MSDN about BOOL SetConsoleMode(HANDLE, DWORD). #define ENABLE_PROCESSED_OUTPUT 0x0001 |