diff options
author | pcloudy <pcloudy@google.com> | 2018-08-10 02:44:07 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-08-10 02:46:23 -0700 |
commit | 7aaa34a1ff518146dd972810445a3d8ced93aa27 (patch) | |
tree | 7281b476c1211e39c92f2d5cc3ccb18e601a3cf2 /src/tools/launcher/bash_launcher.cc | |
parent | ee0ad1a79f52b0e17177cf30d1019740a2832009 (diff) |
Windows, Bash launcher: Make sure bash bin tool directory is in PATH
If bash_bin_path exists, we add it's directory to PATH to make bash bin tools available.
If bash_bin_path doesn't exist, there are two cases:
1. bash.exe is in PATH, and that means bash bin tools should also be in PATH.
2. bash.exe isn't in PATH, the launcher will fail with "The system cannot find the file
specified." error.
RELNOTES: None
PiperOrigin-RevId: 208182717
Diffstat (limited to 'src/tools/launcher/bash_launcher.cc')
-rw-r--r-- | src/tools/launcher/bash_launcher.cc | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/tools/launcher/bash_launcher.cc b/src/tools/launcher/bash_launcher.cc index cd714abc38..3115c813f0 100644 --- a/src/tools/launcher/bash_launcher.cc +++ b/src/tools/launcher/bash_launcher.cc @@ -30,9 +30,15 @@ static constexpr const char* BASH_BIN_PATH = "bash_bin_path"; ExitCode BashBinaryLauncher::Launch() { wstring bash_binary = this->GetLaunchInfoByKey(BASH_BIN_PATH); - // If specified bash binary path doesn't exist, then fall back to - // bash.exe and hope it's in PATH. - if (!DoesFilePathExist(bash_binary.c_str())) { + if (DoesFilePathExist(bash_binary.c_str())) { + wstring bash_bin_dir = GetParentDirFromPath(bash_binary); + wstring path_env; + GetEnv(L"PATH", &path_env); + path_env = bash_bin_dir + L";" + path_env; + SetEnv(L"PATH", path_env); + } else { + // If specified bash binary path doesn't exist, then fall back to + // bash.exe and hope it's in PATH. bash_binary = L"bash.exe"; } |