Yun Peng | 09dd8c0 | 2017-07-21 15:57:05 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include <sstream> |
| 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
| 19 | #include "src/tools/launcher/bash_launcher.h" |
| 20 | #include "src/tools/launcher/util/launcher_util.h" |
| 21 | |
| 22 | namespace bazel { |
| 23 | namespace launcher { |
| 24 | |
| 25 | using std::ostringstream; |
| 26 | using std::string; |
| 27 | using std::vector; |
| 28 | |
Yun Peng | 54c5c5c | 2017-08-24 17:40:22 +0200 | [diff] [blame] | 29 | static constexpr const char* BASH_BIN_PATH = "bash_bin_path"; |
| 30 | |
Yun Peng | 09dd8c0 | 2017-07-21 15:57:05 +0200 | [diff] [blame] | 31 | ExitCode BashBinaryLauncher::Launch() { |
| 32 | string bash_binary = this->GetLaunchInfoByKey(BASH_BIN_PATH); |
| 33 | // If specified bash binary path doesn't exist, then fall back to |
| 34 | // bash.exe and hope it's in PATH. |
Laszlo Csomor | 837e1b3 | 2017-08-03 10:50:29 +0200 | [diff] [blame] | 35 | if (!DoesFilePathExist(bash_binary.c_str())) { |
Yun Peng | 09dd8c0 | 2017-07-21 15:57:05 +0200 | [diff] [blame] | 36 | bash_binary = "bash.exe"; |
| 37 | } |
| 38 | |
| 39 | vector<string> origin_args = this->GetCommandlineArguments(); |
| 40 | ostringstream bash_command; |
Yun Peng | e6d2077 | 2017-08-18 15:40:54 +0200 | [diff] [blame] | 41 | string bash_main_file = GetBinaryPathWithoutExtension(origin_args[0]); |
Yun Peng | 09dd8c0 | 2017-07-21 15:57:05 +0200 | [diff] [blame] | 42 | bash_command << GetEscapedArgument(bash_main_file); |
| 43 | for (int i = 1; i < origin_args.size(); i++) { |
| 44 | bash_command << ' '; |
| 45 | bash_command << GetEscapedArgument(origin_args[i]); |
| 46 | } |
| 47 | |
| 48 | vector<string> args; |
| 49 | args.push_back("-c"); |
| 50 | args.push_back(bash_command.str()); |
| 51 | return this->LaunchProcess(bash_binary, args); |
| 52 | } |
| 53 | |
| 54 | } // namespace launcher |
| 55 | } // namespace bazel |