Nick Lewycky | 6da9077 | 2010-12-31 17:31:54 +0000 | [diff] [blame] | 1 | //===--- Job.cpp - Command to Execute -------------------------------------===// |
Daniel Dunbar | 313c291 | 2009-03-13 23:36:33 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Justin Bogner | d3371d8 | 2015-07-17 03:35:54 +0000 | [diff] [blame] | 10 | #include "InputInfo.h" |
Hans Wennborg | c5afd06 | 2014-02-18 21:42:51 +0000 | [diff] [blame] | 11 | #include "clang/Driver/Driver.h" |
| 12 | #include "clang/Driver/DriverDiagnostic.h" |
Daniel Dunbar | 313c291 | 2009-03-13 23:36:33 +0000 | [diff] [blame] | 13 | #include "clang/Driver/Job.h" |
Hans Wennborg | c5afd06 | 2014-02-18 21:42:51 +0000 | [diff] [blame] | 14 | #include "clang/Driver/Tool.h" |
| 15 | #include "clang/Driver/ToolChain.h" |
Reid Kleckner | 0290c9c | 2014-09-15 17:45:39 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/ArrayRef.h" |
Chad Rosier | be10f98 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringRef.h" |
Reid Kleckner | 0290c9c | 2014-09-15 17:45:39 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringSet.h" |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringSwitch.h" |
Bruno Cardoso Lopes | f854b04 | 2016-04-01 17:39:08 +0000 | [diff] [blame] | 21 | #include "llvm/Support/FileSystem.h" |
Hans Wennborg | e8677ef | 2013-09-12 18:35:08 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Program.h" |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 23 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | 313c291 | 2009-03-13 23:36:33 +0000 | [diff] [blame] | 24 | #include <cassert> |
| 25 | using namespace clang::driver; |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 26 | using llvm::raw_ostream; |
| 27 | using llvm::StringRef; |
Reid Kleckner | 0290c9c | 2014-09-15 17:45:39 +0000 | [diff] [blame] | 28 | using llvm::ArrayRef; |
Daniel Dunbar | 313c291 | 2009-03-13 23:36:33 +0000 | [diff] [blame] | 29 | |
Justin Bogner | 9481761 | 2015-07-02 22:52:04 +0000 | [diff] [blame] | 30 | Command::Command(const Action &Source, const Tool &Creator, |
Justin Bogner | d3371d8 | 2015-07-17 03:35:54 +0000 | [diff] [blame] | 31 | const char *Executable, const ArgStringList &Arguments, |
| 32 | ArrayRef<InputInfo> Inputs) |
Justin Bogner | 0cd9248 | 2015-07-02 22:52:08 +0000 | [diff] [blame] | 33 | : Source(Source), Creator(Creator), Executable(Executable), |
Justin Bogner | d3371d8 | 2015-07-17 03:35:54 +0000 | [diff] [blame] | 34 | Arguments(Arguments), ResponseFile(nullptr) { |
| 35 | for (const auto &II : Inputs) |
| 36 | if (II.isFilename()) |
| 37 | InputFilenames.push_back(II.getFilename()); |
| 38 | } |
Daniel Dunbar | 313c291 | 2009-03-13 23:36:33 +0000 | [diff] [blame] | 39 | |
Justin Bogner | 0cb1475 | 2015-03-12 00:52:56 +0000 | [diff] [blame] | 40 | static int skipArgs(const char *Flag, bool HaveCrashVFS) { |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 41 | // These flags are all of the form -Flag <Arg> and are treated as two |
| 42 | // arguments. Therefore, we need to skip the flag and the next argument. |
| 43 | bool Res = llvm::StringSwitch<bool>(Flag) |
Bruno Cardoso Lopes | b810b02 | 2016-04-04 20:26:57 +0000 | [diff] [blame^] | 44 | .Cases("-MF", "-MT", "-MQ", "-serialize-diagnostic-file", true) |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 45 | .Cases("-o", "-coverage-file", "-dependency-file", true) |
| 46 | .Cases("-fdebug-compilation-dir", "-idirafter", true) |
| 47 | .Cases("-include", "-include-pch", "-internal-isystem", true) |
| 48 | .Cases("-internal-externc-isystem", "-iprefix", "-iwithprefix", true) |
Justin Bogner | 0cb1475 | 2015-03-12 00:52:56 +0000 | [diff] [blame] | 49 | .Cases("-iwithprefixbefore", "-isystem", "-iquote", true) |
Justin Bogner | 61c0e43 | 2014-06-22 20:35:10 +0000 | [diff] [blame] | 50 | .Cases("-dwarf-debug-flags", "-ivfsoverlay", true) |
Justin Bogner | e03437c | 2015-08-05 23:49:44 +0000 | [diff] [blame] | 51 | .Cases("-header-include-file", "-diagnostic-log-file", true) |
Justin Bogner | 0cb1475 | 2015-03-12 00:52:56 +0000 | [diff] [blame] | 52 | // Some include flags shouldn't be skipped if we have a crash VFS |
Bruno Cardoso Lopes | b810b02 | 2016-04-04 20:26:57 +0000 | [diff] [blame^] | 53 | .Cases("-isysroot", "-I", "-F", "-resource-dir", !HaveCrashVFS) |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 54 | .Default(false); |
| 55 | |
| 56 | // Match found. |
| 57 | if (Res) |
| 58 | return 2; |
| 59 | |
| 60 | // The remaining flags are treated as a single argument. |
| 61 | |
| 62 | // These flags are all of the form -Flag and have no second argument. |
| 63 | Res = llvm::StringSwitch<bool>(Flag) |
| 64 | .Cases("-M", "-MM", "-MG", "-MP", "-MD", true) |
| 65 | .Case("-MMD", true) |
| 66 | .Default(false); |
| 67 | |
| 68 | // Match found. |
| 69 | if (Res) |
| 70 | return 1; |
| 71 | |
| 72 | // These flags are treated as a single argument (e.g., -F<Dir>). |
| 73 | StringRef FlagRef(Flag); |
Bruno Cardoso Lopes | b810b02 | 2016-04-04 20:26:57 +0000 | [diff] [blame^] | 74 | if ((!HaveCrashVFS && |
| 75 | (FlagRef.startswith("-F") || FlagRef.startswith("-I"))) || |
Justin Bogner | f893a65 | 2014-04-22 21:30:17 +0000 | [diff] [blame] | 76 | FlagRef.startswith("-fmodules-cache-path=")) |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 77 | return 1; |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
Justin Bogner | ed9cbe0 | 2015-07-09 06:58:31 +0000 | [diff] [blame] | 82 | void Command::printArg(raw_ostream &OS, const char *Arg, bool Quote) { |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 83 | const bool Escape = std::strpbrk(Arg, "\"\\$"); |
| 84 | |
| 85 | if (!Quote && !Escape) { |
| 86 | OS << Arg; |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | // Quote and escape. This isn't really complete, but good enough. |
| 91 | OS << '"'; |
| 92 | while (const char c = *Arg++) { |
| 93 | if (c == '"' || c == '\\' || c == '$') |
| 94 | OS << '\\'; |
| 95 | OS << c; |
| 96 | } |
| 97 | OS << '"'; |
| 98 | } |
| 99 | |
Reid Kleckner | 0290c9c | 2014-09-15 17:45:39 +0000 | [diff] [blame] | 100 | void Command::writeResponseFile(raw_ostream &OS) const { |
| 101 | // In a file list, we only write the set of inputs to the response file |
| 102 | if (Creator.getResponseFilesSupport() == Tool::RF_FileList) { |
| 103 | for (const char *Arg : InputFileList) { |
| 104 | OS << Arg << '\n'; |
| 105 | } |
| 106 | return; |
| 107 | } |
| 108 | |
Reid Kleckner | e2d0344 | 2015-07-15 22:42:37 +0000 | [diff] [blame] | 109 | // In regular response files, we send all arguments to the response file. |
| 110 | // Wrapping all arguments in double quotes ensures that both Unix tools and |
| 111 | // Windows tools understand the response file. |
Reid Kleckner | 0290c9c | 2014-09-15 17:45:39 +0000 | [diff] [blame] | 112 | for (const char *Arg : Arguments) { |
| 113 | OS << '"'; |
| 114 | |
| 115 | for (; *Arg != '\0'; Arg++) { |
| 116 | if (*Arg == '\"' || *Arg == '\\') { |
| 117 | OS << '\\'; |
| 118 | } |
| 119 | OS << *Arg; |
| 120 | } |
| 121 | |
| 122 | OS << "\" "; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | void Command::buildArgvForResponseFile( |
| 127 | llvm::SmallVectorImpl<const char *> &Out) const { |
| 128 | // When not a file list, all arguments are sent to the response file. |
| 129 | // This leaves us to set the argv to a single parameter, requesting the tool |
| 130 | // to read the response file. |
| 131 | if (Creator.getResponseFilesSupport() != Tool::RF_FileList) { |
| 132 | Out.push_back(Executable); |
| 133 | Out.push_back(ResponseFileFlag.c_str()); |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | llvm::StringSet<> Inputs; |
| 138 | for (const char *InputName : InputFileList) |
| 139 | Inputs.insert(InputName); |
| 140 | Out.push_back(Executable); |
| 141 | // In a file list, build args vector ignoring parameters that will go in the |
| 142 | // response file (elements of the InputFileList vector) |
| 143 | bool FirstInput = true; |
| 144 | for (const char *Arg : Arguments) { |
| 145 | if (Inputs.count(Arg) == 0) { |
| 146 | Out.push_back(Arg); |
| 147 | } else if (FirstInput) { |
| 148 | FirstInput = false; |
| 149 | Out.push_back(Creator.getResponseFileFlag()); |
| 150 | Out.push_back(ResponseFile); |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 155 | void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote, |
Justin Bogner | 2564515 | 2014-10-21 17:24:44 +0000 | [diff] [blame] | 156 | CrashReportInfo *CrashInfo) const { |
Reid Kleckner | 822434d | 2014-08-05 20:49:12 +0000 | [diff] [blame] | 157 | // Always quote the exe. |
Reid Kleckner | 4f1fc35 | 2014-08-07 00:05:00 +0000 | [diff] [blame] | 158 | OS << ' '; |
Justin Bogner | ed9cbe0 | 2015-07-09 06:58:31 +0000 | [diff] [blame] | 159 | printArg(OS, Executable, /*Quote=*/true); |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 160 | |
Reid Kleckner | 0290c9c | 2014-09-15 17:45:39 +0000 | [diff] [blame] | 161 | llvm::ArrayRef<const char *> Args = Arguments; |
| 162 | llvm::SmallVector<const char *, 128> ArgsRespFile; |
| 163 | if (ResponseFile != nullptr) { |
| 164 | buildArgvForResponseFile(ArgsRespFile); |
| 165 | Args = ArrayRef<const char *>(ArgsRespFile).slice(1); // no executable name |
| 166 | } |
| 167 | |
Justin Bogner | 0cb1475 | 2015-03-12 00:52:56 +0000 | [diff] [blame] | 168 | bool HaveCrashVFS = CrashInfo && !CrashInfo->VFSPath.empty(); |
Reid Kleckner | 0290c9c | 2014-09-15 17:45:39 +0000 | [diff] [blame] | 169 | for (size_t i = 0, e = Args.size(); i < e; ++i) { |
| 170 | const char *const Arg = Args[i]; |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 171 | |
Justin Bogner | 2564515 | 2014-10-21 17:24:44 +0000 | [diff] [blame] | 172 | if (CrashInfo) { |
Justin Bogner | 0cb1475 | 2015-03-12 00:52:56 +0000 | [diff] [blame] | 173 | if (int Skip = skipArgs(Arg, HaveCrashVFS)) { |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 174 | i += Skip - 1; |
| 175 | continue; |
Justin Bogner | d3371d8 | 2015-07-17 03:35:54 +0000 | [diff] [blame] | 176 | } |
| 177 | auto Found = std::find_if(InputFilenames.begin(), InputFilenames.end(), |
| 178 | [&Arg](StringRef IF) { return IF == Arg; }); |
| 179 | if (Found != InputFilenames.end() && |
| 180 | (i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) { |
Justin Bogner | 2564515 | 2014-10-21 17:24:44 +0000 | [diff] [blame] | 181 | // Replace the input file name with the crashinfo's file name. |
| 182 | OS << ' '; |
| 183 | StringRef ShortName = llvm::sys::path::filename(CrashInfo->Filename); |
Justin Bogner | ed9cbe0 | 2015-07-09 06:58:31 +0000 | [diff] [blame] | 184 | printArg(OS, ShortName.str().c_str(), Quote); |
Justin Bogner | 2564515 | 2014-10-21 17:24:44 +0000 | [diff] [blame] | 185 | continue; |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
| 189 | OS << ' '; |
Justin Bogner | ed9cbe0 | 2015-07-09 06:58:31 +0000 | [diff] [blame] | 190 | printArg(OS, Arg, Quote); |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 191 | } |
Reid Kleckner | 0290c9c | 2014-09-15 17:45:39 +0000 | [diff] [blame] | 192 | |
Justin Bogner | 0cb1475 | 2015-03-12 00:52:56 +0000 | [diff] [blame] | 193 | if (CrashInfo && HaveCrashVFS) { |
Justin Bogner | 2564515 | 2014-10-21 17:24:44 +0000 | [diff] [blame] | 194 | OS << ' '; |
Justin Bogner | ed9cbe0 | 2015-07-09 06:58:31 +0000 | [diff] [blame] | 195 | printArg(OS, "-ivfsoverlay", Quote); |
Justin Bogner | 2564515 | 2014-10-21 17:24:44 +0000 | [diff] [blame] | 196 | OS << ' '; |
Justin Bogner | ed9cbe0 | 2015-07-09 06:58:31 +0000 | [diff] [blame] | 197 | printArg(OS, CrashInfo->VFSPath.str().c_str(), Quote); |
Bruno Cardoso Lopes | f854b04 | 2016-04-01 17:39:08 +0000 | [diff] [blame] | 198 | |
| 199 | // Insert -fmodules-cache-path and use the relative module directory |
| 200 | // <name>.cache/vfs/modules where we already dumped the modules. |
| 201 | SmallString<128> RelModCacheDir = llvm::sys::path::parent_path( |
| 202 | llvm::sys::path::parent_path(CrashInfo->VFSPath)); |
| 203 | llvm::sys::path::append(RelModCacheDir, "modules"); |
| 204 | |
| 205 | std::string ModCachePath = "-fmodules-cache-path="; |
| 206 | ModCachePath.append(RelModCacheDir.c_str()); |
| 207 | |
| 208 | OS << ' '; |
| 209 | printArg(OS, ModCachePath.c_str(), Quote); |
Justin Bogner | 2564515 | 2014-10-21 17:24:44 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Reid Kleckner | 0290c9c | 2014-09-15 17:45:39 +0000 | [diff] [blame] | 212 | if (ResponseFile != nullptr) { |
| 213 | OS << "\n Arguments passed via response file:\n"; |
| 214 | writeResponseFile(OS); |
| 215 | // Avoiding duplicated newline terminator, since FileLists are |
| 216 | // newline-separated. |
| 217 | if (Creator.getResponseFilesSupport() != Tool::RF_FileList) |
| 218 | OS << "\n"; |
| 219 | OS << " (end of response file)"; |
| 220 | } |
| 221 | |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 222 | OS << Terminator; |
| 223 | } |
| 224 | |
Reid Kleckner | 0290c9c | 2014-09-15 17:45:39 +0000 | [diff] [blame] | 225 | void Command::setResponseFile(const char *FileName) { |
| 226 | ResponseFile = FileName; |
| 227 | ResponseFileFlag = Creator.getResponseFileFlag(); |
| 228 | ResponseFileFlag += FileName; |
| 229 | } |
| 230 | |
Hans Wennborg | e693e84 | 2013-09-18 00:41:15 +0000 | [diff] [blame] | 231 | int Command::Execute(const StringRef **Redirects, std::string *ErrMsg, |
Hans Wennborg | e8677ef | 2013-09-12 18:35:08 +0000 | [diff] [blame] | 232 | bool *ExecutionFailed) const { |
| 233 | SmallVector<const char*, 128> Argv; |
Reid Kleckner | 0290c9c | 2014-09-15 17:45:39 +0000 | [diff] [blame] | 234 | |
| 235 | if (ResponseFile == nullptr) { |
| 236 | Argv.push_back(Executable); |
Benjamin Kramer | f989042 | 2015-02-17 16:48:30 +0000 | [diff] [blame] | 237 | Argv.append(Arguments.begin(), Arguments.end()); |
Reid Kleckner | 0290c9c | 2014-09-15 17:45:39 +0000 | [diff] [blame] | 238 | Argv.push_back(nullptr); |
| 239 | |
| 240 | return llvm::sys::ExecuteAndWait(Executable, Argv.data(), /*env*/ nullptr, |
| 241 | Redirects, /*secondsToWait*/ 0, |
| 242 | /*memoryLimit*/ 0, ErrMsg, |
| 243 | ExecutionFailed); |
| 244 | } |
| 245 | |
| 246 | // We need to put arguments in a response file (command is too large) |
| 247 | // Open stream to store the response file contents |
| 248 | std::string RespContents; |
| 249 | llvm::raw_string_ostream SS(RespContents); |
| 250 | |
| 251 | // Write file contents and build the Argv vector |
| 252 | writeResponseFile(SS); |
| 253 | buildArgvForResponseFile(Argv); |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 254 | Argv.push_back(nullptr); |
Reid Kleckner | 0290c9c | 2014-09-15 17:45:39 +0000 | [diff] [blame] | 255 | SS.flush(); |
| 256 | |
| 257 | // Save the response file in the appropriate encoding |
| 258 | if (std::error_code EC = writeFileWithEncoding( |
| 259 | ResponseFile, RespContents, Creator.getResponseFileEncoding())) { |
| 260 | if (ErrMsg) |
| 261 | *ErrMsg = EC.message(); |
| 262 | if (ExecutionFailed) |
| 263 | *ExecutionFailed = true; |
| 264 | return -1; |
| 265 | } |
Hans Wennborg | e8677ef | 2013-09-12 18:35:08 +0000 | [diff] [blame] | 266 | |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 267 | return llvm::sys::ExecuteAndWait(Executable, Argv.data(), /*env*/ nullptr, |
Hans Wennborg | e8677ef | 2013-09-12 18:35:08 +0000 | [diff] [blame] | 268 | Redirects, /*secondsToWait*/ 0, |
| 269 | /*memoryLimit*/ 0, ErrMsg, ExecutionFailed); |
| 270 | } |
| 271 | |
Hans Wennborg | 87cfa71 | 2013-09-19 20:32:16 +0000 | [diff] [blame] | 272 | FallbackCommand::FallbackCommand(const Action &Source_, const Tool &Creator_, |
| 273 | const char *Executable_, |
| 274 | const ArgStringList &Arguments_, |
Justin Bogner | d3371d8 | 2015-07-17 03:35:54 +0000 | [diff] [blame] | 275 | ArrayRef<InputInfo> Inputs, |
David Blaikie | c11bf80 | 2014-09-04 16:04:28 +0000 | [diff] [blame] | 276 | std::unique_ptr<Command> Fallback_) |
Justin Bogner | d3371d8 | 2015-07-17 03:35:54 +0000 | [diff] [blame] | 277 | : Command(Source_, Creator_, Executable_, Arguments_, Inputs), |
David Blaikie | c11bf80 | 2014-09-04 16:04:28 +0000 | [diff] [blame] | 278 | Fallback(std::move(Fallback_)) {} |
Hans Wennborg | 87cfa71 | 2013-09-19 20:32:16 +0000 | [diff] [blame] | 279 | |
| 280 | void FallbackCommand::Print(raw_ostream &OS, const char *Terminator, |
Justin Bogner | 2564515 | 2014-10-21 17:24:44 +0000 | [diff] [blame] | 281 | bool Quote, CrashReportInfo *CrashInfo) const { |
| 282 | Command::Print(OS, "", Quote, CrashInfo); |
Hans Wennborg | 87cfa71 | 2013-09-19 20:32:16 +0000 | [diff] [blame] | 283 | OS << " ||"; |
Justin Bogner | 2564515 | 2014-10-21 17:24:44 +0000 | [diff] [blame] | 284 | Fallback->Print(OS, Terminator, Quote, CrashInfo); |
Hans Wennborg | 87cfa71 | 2013-09-19 20:32:16 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | static bool ShouldFallback(int ExitCode) { |
| 288 | // FIXME: We really just want to fall back for internal errors, such |
| 289 | // as when some symbol cannot be mangled, when we should be able to |
| 290 | // parse something but can't, etc. |
| 291 | return ExitCode != 0; |
| 292 | } |
| 293 | |
| 294 | int FallbackCommand::Execute(const StringRef **Redirects, std::string *ErrMsg, |
| 295 | bool *ExecutionFailed) const { |
| 296 | int PrimaryStatus = Command::Execute(Redirects, ErrMsg, ExecutionFailed); |
| 297 | if (!ShouldFallback(PrimaryStatus)) |
| 298 | return PrimaryStatus; |
| 299 | |
| 300 | // Clear ExecutionFailed and ErrMsg before falling back. |
| 301 | if (ErrMsg) |
| 302 | ErrMsg->clear(); |
| 303 | if (ExecutionFailed) |
| 304 | *ExecutionFailed = false; |
| 305 | |
Hans Wennborg | c5afd06 | 2014-02-18 21:42:51 +0000 | [diff] [blame] | 306 | const Driver &D = getCreator().getToolChain().getDriver(); |
Hans Wennborg | 897a69b | 2014-02-19 02:10:19 +0000 | [diff] [blame] | 307 | D.Diag(diag::warn_drv_invoking_fallback) << Fallback->getExecutable(); |
Hans Wennborg | c5afd06 | 2014-02-18 21:42:51 +0000 | [diff] [blame] | 308 | |
Hans Wennborg | 87cfa71 | 2013-09-19 20:32:16 +0000 | [diff] [blame] | 309 | int SecondaryStatus = Fallback->Execute(Redirects, ErrMsg, ExecutionFailed); |
| 310 | return SecondaryStatus; |
| 311 | } |
| 312 | |
Nico Weber | 2ca4be9 | 2016-03-01 23:16:44 +0000 | [diff] [blame] | 313 | ForceSuccessCommand::ForceSuccessCommand(const Action &Source_, |
| 314 | const Tool &Creator_, |
| 315 | const char *Executable_, |
| 316 | const ArgStringList &Arguments_, |
| 317 | ArrayRef<InputInfo> Inputs) |
| 318 | : Command(Source_, Creator_, Executable_, Arguments_, Inputs) {} |
| 319 | |
| 320 | void ForceSuccessCommand::Print(raw_ostream &OS, const char *Terminator, |
| 321 | bool Quote, CrashReportInfo *CrashInfo) const { |
| 322 | Command::Print(OS, "", Quote, CrashInfo); |
| 323 | OS << " || (exit 0)" << Terminator; |
| 324 | } |
| 325 | |
| 326 | int ForceSuccessCommand::Execute(const StringRef **Redirects, |
| 327 | std::string *ErrMsg, |
| 328 | bool *ExecutionFailed) const { |
| 329 | int Status = Command::Execute(Redirects, ErrMsg, ExecutionFailed); |
| 330 | (void)Status; |
| 331 | if (ExecutionFailed) |
| 332 | *ExecutionFailed = false; |
| 333 | return 0; |
| 334 | } |
| 335 | |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 336 | void JobList::Print(raw_ostream &OS, const char *Terminator, bool Quote, |
Justin Bogner | 2564515 | 2014-10-21 17:24:44 +0000 | [diff] [blame] | 337 | CrashReportInfo *CrashInfo) const { |
Justin Bogner | aab9792 | 2014-10-03 01:04:53 +0000 | [diff] [blame] | 338 | for (const auto &Job : *this) |
Justin Bogner | 2564515 | 2014-10-21 17:24:44 +0000 | [diff] [blame] | 339 | Job.Print(OS, Terminator, Quote, CrashInfo); |
Hans Wennborg | b212b34 | 2013-09-12 18:23:34 +0000 | [diff] [blame] | 340 | } |
| 341 | |
David Blaikie | c11bf80 | 2014-09-04 16:04:28 +0000 | [diff] [blame] | 342 | void JobList::clear() { Jobs.clear(); } |