aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2016-07-15 08:38:38 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-07-15 13:31:47 +0000
commit44fa4c7c24c578459fa582557ede577d24ac8ef1 (patch)
tree80973d241bf4ae5e50aca2550fa235fc25784ffb /src/main
parent49a65368c918b815f30aa3c412a9b7e5f83d8b3f (diff)
Fixed repository.which() on Windows
Also removed previous workaround in cc_configure.bzl -- Change-Id: I6dcd039fc5e18af8f2d21969641d6bbd05c8badc Reviewed-on: https://bazel-review.googlesource.com/#/c/4034 MOS_MIGRATED_REVID=127518922
Diffstat (limited to 'src/main')
-rw-r--r--src/main/cpp/blaze_util_mingw.cc19
-rw-r--r--src/main/cpp/blaze_util_platform.h6
-rw-r--r--src/main/cpp/blaze_util_posix.cc2
-rw-r--r--src/main/cpp/option_processor.cc12
4 files changed, 38 insertions, 1 deletions
diff --git a/src/main/cpp/blaze_util_mingw.cc b/src/main/cpp/blaze_util_mingw.cc
index 6f0df5456b..7dd3b935be 100644
--- a/src/main/cpp/blaze_util_mingw.cc
+++ b/src/main/cpp/blaze_util_mingw.cc
@@ -510,6 +510,10 @@ void ExecuteProgram(
string ListSeparator() { return ";"; }
string ConvertPath(const string& path) {
+ // If the path looks like %USERPROFILE%/foo/bar, don't convert.
+ if (path.empty() || path[0] == '%') {
+ return path;
+ }
char* wpath = static_cast<char*>(cygwin_create_path(
CCP_POSIX_TO_WIN_A, static_cast<const void*>(path.c_str())));
string result(wpath);
@@ -517,6 +521,21 @@ string ConvertPath(const string& path) {
return result;
}
+// Convert a Unix path list to Windows path list
+string ConvertPathList(const string& path_list) {
+ string w_list = "";
+ int start = 0;
+ int pos;
+ while ((pos = path_list.find(":", start)) != string::npos) {
+ w_list += ConvertPath(path_list.substr(start, pos - start)) + ";";
+ start = pos + 1;
+ }
+ if (start < path_list.size()) {
+ w_list += ConvertPath(path_list.substr(start));
+ }
+ return w_list;
+}
+
string ConvertPathToPosix(const string& win_path) {
char* posix_path = static_cast<char*>(cygwin_create_path(
CCP_WIN_A_TO_POSIX, static_cast<const void*>(win_path.c_str())));
diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h
index 71c7a84530..c6e1d700a9 100644
--- a/src/main/cpp/blaze_util_platform.h
+++ b/src/main/cpp/blaze_util_platform.h
@@ -84,6 +84,12 @@ string RunProgram(const string& exe, const std::vector<string>& args_vector);
// is Windows path.
std::string ConvertPath(const std::string& path);
+// Convert a path list from Bazel internal form to underlying OS form.
+// On Unixes this is an identity operation.
+// On Windows, Bazel internal form is cygwin path list, and underlying OS form
+// is Windows path list.
+std::string ConvertPathList(const std::string& path_list);
+
// Return a string used to separate paths in a list.
std::string ListSeparator();
diff --git a/src/main/cpp/blaze_util_posix.cc b/src/main/cpp/blaze_util_posix.cc
index bc06712152..12498c4f9a 100644
--- a/src/main/cpp/blaze_util_posix.cc
+++ b/src/main/cpp/blaze_util_posix.cc
@@ -64,6 +64,8 @@ void ExecuteProgram(const string &exe, const vector<string> &args_vector) {
std::string ConvertPath(const std::string &path) { return path; }
+std::string ConvertPathList(const std::string& path_list) { return path_list; }
+
std::string ListSeparator() { return ":"; }
bool SymlinkDirectories(const string &target, const string &link) {
diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc
index 3e2f662212..6079ebf79f 100644
--- a/src/main/cpp/option_processor.cc
+++ b/src/main/cpp/option_processor.cc
@@ -460,7 +460,17 @@ void OptionProcessor::AddRcfileArgsAndOptions(bool batch, const string& cwd) {
command_arguments_.push_back("--ignore_client_env");
} else {
for (char** env = environ; *env != NULL; env++) {
- command_arguments_.push_back("--client_env=" + string(*env));
+ string env_str(*env);
+ int pos = env_str.find("=");
+ if (pos != string::npos) {
+ string name = env_str.substr(0, pos);
+ if (name == "PATH" || name == "TMP") {
+ string value = env_str.substr(pos + 1);
+ value = ConvertPathList(value);
+ env_str = name + "=" + value;
+ }
+ }
+ command_arguments_.push_back("--client_env=" + env_str);
}
}
command_arguments_.push_back("--client_cwd=" + blaze::ConvertPath(cwd));