diff options
author | 2017-09-14 11:11:48 +0200 | |
---|---|---|
committer | 2017-09-14 18:47:41 +0200 | |
commit | 213a52a29ac445781f0cd55d1909eecce0f29fd5 (patch) | |
tree | f68efc90e07da94fee8365464afe5b569a5cb0e3 /src | |
parent | 1a538e330825f1ef528cc0a9b4d5caf44b76f7f8 (diff) |
Windows: Adding default --python_path
On Windows, Bazel client will try to find python.exe in $PATH.
If succeed, then we pretend to add a --python_path option in the least
important bazelrc file.
Fixed https://github.com/bazelbuild/bazel/issues/3717
Change-Id: I8d97b0895f024d8d236f3b4b39f91c41d947a5fa
PiperOrigin-RevId: 168659085
Diffstat (limited to 'src')
-rw-r--r-- | src/main/cpp/blaze_util_platform.h | 6 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_posix.cc | 4 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_windows.cc | 30 | ||||
-rw-r--r-- | src/main/cpp/option_processor.cc | 2 |
4 files changed, 32 insertions, 10 deletions
diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h index a40ce95939..212c1bc0c6 100644 --- a/src/main/cpp/blaze_util_platform.h +++ b/src/main/cpp/blaze_util_platform.h @@ -236,6 +236,12 @@ bool UnlimitResources(); void DetectBashOrDie(); +// This function has no effect on Unix platforms. +// On Windows, this function looks into PATH to find python.exe, if python +// binary is found then add +// --default_override=0:build=--python_path=<python/path> into options. +void EnsurePythonPathOption(std::vector<std::string>* options); + } // namespace blaze #endif // BAZEL_SRC_MAIN_CPP_BLAZE_UTIL_PLATFORM_H_ diff --git a/src/main/cpp/blaze_util_posix.cc b/src/main/cpp/blaze_util_posix.cc index a53b9316d4..5a4d74857f 100644 --- a/src/main/cpp/blaze_util_posix.cc +++ b/src/main/cpp/blaze_util_posix.cc @@ -782,4 +782,8 @@ void DetectBashOrDie() { // do nothing. } +void EnsurePythonPathOption(vector<string>* options) { + // do nothing. +} + } // namespace blaze. diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc index 7e779bb808..d3be4c566c 100644 --- a/src/main/cpp/blaze_util_windows.cc +++ b/src/main/cpp/blaze_util_windows.cc @@ -1307,7 +1307,7 @@ static string GetBashFromGitOnWin() { return bash_exe; } -static string GetBashFromPath() { +static string GetBinaryFromPath(const string& binary_name) { char found[MAX_PATH]; string path_list = blaze::GetEnv("PATH"); @@ -1324,14 +1324,14 @@ static string GetBashFromPath() { if (path.size() > 1 && path[0] == '"' && path[path.size() - 1] == '"') { path = path.substr(1, path.size() - 2); } - if (SearchPathA(path.c_str(), // _In_opt_ LPCTSTR lpPath, - "bash.exe", // _In_ LPCTSTR lpFileName, - 0, // LPCTSTR lpExtension, - sizeof(found), // DWORD nBufferLength, - found, // _Out_ LPTSTR lpBuffer, - 0 // _Out_opt_ LPTSTR *lpFilePart + if (SearchPathA(path.c_str(), // _In_opt_ LPCTSTR lpPath, + binary_name.c_str(), // _In_ LPCTSTR lpFileName, + 0, // LPCTSTR lpExtension, + sizeof(found), // DWORD nBufferLength, + found, // _Out_ LPTSTR lpBuffer, + 0 // _Out_opt_ LPTSTR *lpFilePart )) { - debug_log("bash.exe found on PATH: %s", found); + debug_log("%s found on PATH: %s", binary_name.c_str(), found); return string(found); } if (end == string::npos) { @@ -1340,7 +1340,7 @@ static string GetBashFromPath() { start = end + 1; } while (true); - debug_log("bash.exe not found on PATH"); + debug_log("%s not found on PATH", binary_name.c_str()); return string(); } @@ -1355,7 +1355,7 @@ static string LocateBash() { return git_on_win_bash; } - return GetBashFromPath(); + return GetBinaryFromPath("bash.exe"); } void DetectBashOrDie() { @@ -1388,4 +1388,14 @@ void DetectBashOrDie() { } } +void EnsurePythonPathOption(std::vector<string>* options) { + string python_path = GetBinaryFromPath("python.exe"); + if (!python_path.empty()) { + // Provide python path as coming from the least important rc file. + std::replace(python_path.begin(), python_path.end(), '\\', '/'); + options->push_back(string("--default_override=0:build=--python_path=") + + python_path); + } +} + } // namespace blaze diff --git a/src/main/cpp/option_processor.cc b/src/main/cpp/option_processor.cc index 170103c3eb..a7b52d8d83 100644 --- a/src/main/cpp/option_processor.cc +++ b/src/main/cpp/option_processor.cc @@ -509,6 +509,8 @@ std::vector<std::string> OptionProcessor::GetBlazercAndEnvCommandArgs( "--default_override=0:common=--terminal_columns=" + ToString(GetTerminalColumns())}; + EnsurePythonPathOption(&result); + // Push the options mapping .blazerc numbers to filenames. for (const RcFile* blazerc : blazercs) { result.push_back("--rc_source=" + blaze::ConvertPath(blazerc->Filename())); |