aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/blaze_util_windows.cc
diff options
context:
space:
mode:
authorGravatar elenairina <elenairina@google.com>2017-08-18 13:22:44 +0200
committerGravatar Irina Iancu <elenairina@google.com>2017-08-18 13:34:30 +0200
commitabc69c33ef9fd3b58d74b3ff28713f99c639c2af (patch)
tree78acf9468f4db6d04a355ab7054acadb3c3dcf70 /src/main/cpp/blaze_util_windows.cc
parent619ca49e28b6b9d962802b6491675d22ee5984e2 (diff)
Automated rollback of commit 2f38404728a12840e416566b453e9cdebab5d859.
Fixes #3584 *** Reason for rollback *** Broke bazel_windows_test fails on windows. *** Original change description *** Propagate detected value of BAZEL_SH to --client_env. Also make debug_log available as soon as possible on startup. Also adds some extra debug logging. Also removes some msys-only code paths. Fixes #3498. Change-Id: I5b769f2c5a728106e5252869745ec79e555cbaf2 PiperOrigin-RevId: 165692468
Diffstat (limited to 'src/main/cpp/blaze_util_windows.cc')
-rw-r--r--src/main/cpp/blaze_util_windows.cc26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc
index 42095e19c2..cffe06f350 100644
--- a/src/main/cpp/blaze_util_windows.cc
+++ b/src/main/cpp/blaze_util_windows.cc
@@ -739,6 +739,10 @@ void ExecuteDaemon(const string& exe, const std::vector<string>& args_vector,
startupInfo.dwFlags |= STARTF_USESTDHANDLES;
CmdLine cmdline;
CreateCommandLine(&cmdline, exe, args_vector);
+ // Propagate BAZEL_SH environment variable to a sub-process.
+ // TODO(dslomov): More principled approach to propagating
+ // environment variables.
+ SetEnvironmentVariableA("BAZEL_SH", getenv("BAZEL_SH"));
BOOL ok = CreateProcessA(
/* lpApplicationName */ NULL,
@@ -831,6 +835,11 @@ void ExecuteProgram(const string& exe, const std::vector<string>& args_vector) {
PROCESS_INFORMATION processInfo = {0};
+ // Propagate BAZEL_SH environment variable to a sub-process.
+ // todo(dslomov): More principled approach to propagating
+ // environment variables.
+ SetEnvironmentVariableA("BAZEL_SH", getenv("BAZEL_SH"));
+
HANDLE job = CreateJobObject(NULL, NULL);
if (job == NULL) {
pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
@@ -1142,8 +1151,17 @@ string GetEnv(const string& name) {
}
void SetEnv(const string& name, const string& value) {
- // _putenv_s both calls ::SetEnvionmentVariableA and updates environ(5).
- _putenv_s(name.c_str(), value.c_str());
+ if (value.empty()) {
+ ::SetEnvironmentVariableA(name.c_str(), NULL);
+#ifndef COMPILER_MSVC
+ unsetenv(name.c_str());
+#endif // not COMPILER_MSVC
+ } else {
+ ::SetEnvironmentVariableA(name.c_str(), value.c_str());
+#ifndef COMPILER_MSVC
+ setenv(name.c_str(), value.c_str(), 1);
+#endif // not COMPILER_MSVC
+ }
}
void UnsetEnv(const string& name) { SetEnv(name, ""); }
@@ -1680,11 +1698,9 @@ void DetectBashOrDie() {
string bash = LocateBash();
uint64_t end = blaze::GetMillisecondsMonotonic();
- debug_log("BAZEL_SH detection took %lu msec, found %s", end - start,
- bash.c_str());
+ debug_log("BAZEL_SH detection took %lu msec", end - start);
if (!bash.empty()) {
- // Set process environment variable.
blaze::SetEnv("BAZEL_SH", bash);
} else {
printf(