aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-07-27 16:37:08 +0200
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-07-28 09:40:53 +0200
commitc4fb218ea441797e3064039eba0255bbd145b794 (patch)
tree6c4c190d24b66455c8213293d247d085b41a169f /src/main/cpp
parent195a7a8044650f88ccd39f0392dfe97d7b4a56ab (diff)
Windows: detect if started from Windows Explorer
Bazel now detects whether it was started from a command line (or as a subprocess), or from Windows Explorer (by clicking its icon). In the latter case it displays an error message asking the user to run it from a command line, and waiting for a keypress so the user has time to read this message. Change-Id: I4b0430e30d2f1f243cec6ff63cb3abac907e60e3 PiperOrigin-RevId: 163338527
Diffstat (limited to 'src/main/cpp')
-rw-r--r--src/main/cpp/blaze.cc7
-rw-r--r--src/main/cpp/blaze_util_platform.h5
-rw-r--r--src/main/cpp/blaze_util_posix.cc2
-rw-r--r--src/main/cpp/blaze_util_windows.cc19
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