blob: 765c05752d8f3a12a9785085305bfd304ef2351f [file] [log] [blame]
Nick Lewycky6da90772010-12-31 17:31:54 +00001//===--- Job.cpp - Command to Execute -------------------------------------===//
Daniel Dunbar313c2912009-03-13 23:36:33 +00002//
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
Mehdi Amini9670f842016-07-18 19:02:11 +000010#include "clang/Driver/Job.h"
Justin Bognerd3371d82015-07-17 03:35:54 +000011#include "InputInfo.h"
Hans Wennborgc5afd062014-02-18 21:42:51 +000012#include "clang/Driver/Driver.h"
13#include "clang/Driver/DriverDiagnostic.h"
Hans Wennborgc5afd062014-02-18 21:42:51 +000014#include "clang/Driver/Tool.h"
15#include "clang/Driver/ToolChain.h"
Reid Kleckner0290c9c2014-09-15 17:45:39 +000016#include "llvm/ADT/ArrayRef.h"
Alexander Kornienko1e531952017-09-13 17:45:51 +000017#include "llvm/ADT/Optional.h"
Chad Rosierbe10f982011-08-02 17:58:04 +000018#include "llvm/ADT/STLExtras.h"
Mehdi Amini9670f842016-07-18 19:02:11 +000019#include "llvm/ADT/SmallString.h"
Hans Wennborgb212b342013-09-12 18:23:34 +000020#include "llvm/ADT/StringRef.h"
Reid Kleckner0290c9c2014-09-15 17:45:39 +000021#include "llvm/ADT/StringSet.h"
Hans Wennborgb212b342013-09-12 18:23:34 +000022#include "llvm/ADT/StringSwitch.h"
Bruno Cardoso Lopese3a0aef2016-12-09 02:22:47 +000023#include "llvm/Support/FileSystem.h"
Mehdi Amini9670f842016-07-18 19:02:11 +000024#include "llvm/Support/Path.h"
Hans Wennborge8677ef2013-09-12 18:35:08 +000025#include "llvm/Support/Program.h"
Hans Wennborgb212b342013-09-12 18:23:34 +000026#include "llvm/Support/raw_ostream.h"
Daniel Dunbar313c2912009-03-13 23:36:33 +000027#include <cassert>
28using namespace clang::driver;
Hans Wennborgb212b342013-09-12 18:23:34 +000029using llvm::raw_ostream;
30using llvm::StringRef;
Reid Kleckner0290c9c2014-09-15 17:45:39 +000031using llvm::ArrayRef;
Daniel Dunbar313c2912009-03-13 23:36:33 +000032
Justin Bogner94817612015-07-02 22:52:04 +000033Command::Command(const Action &Source, const Tool &Creator,
Justin Bognerd3371d82015-07-17 03:35:54 +000034 const char *Executable, const ArgStringList &Arguments,
35 ArrayRef<InputInfo> Inputs)
Justin Bogner0cd92482015-07-02 22:52:08 +000036 : Source(Source), Creator(Creator), Executable(Executable),
Justin Bognerd3371d82015-07-17 03:35:54 +000037 Arguments(Arguments), ResponseFile(nullptr) {
38 for (const auto &II : Inputs)
39 if (II.isFilename())
40 InputFilenames.push_back(II.getFilename());
41}
Daniel Dunbar313c2912009-03-13 23:36:33 +000042
Bruno Cardoso Lopese3a0aef2016-12-09 02:22:47 +000043/// @brief Check if the compiler flag in question should be skipped when
44/// emitting a reproducer. Also track how many arguments it has and if the
45/// option is some kind of include path.
46static bool skipArgs(const char *Flag, bool HaveCrashVFS, int &SkipNum,
47 bool &IsInclude) {
48 SkipNum = 2;
Hans Wennborgb212b342013-09-12 18:23:34 +000049 // These flags are all of the form -Flag <Arg> and are treated as two
50 // arguments. Therefore, we need to skip the flag and the next argument.
Bruno Cardoso Lopese3a0aef2016-12-09 02:22:47 +000051 bool ShouldSkip = llvm::StringSwitch<bool>(Flag)
Bruno Cardoso Lopesb810b022016-04-04 20:26:57 +000052 .Cases("-MF", "-MT", "-MQ", "-serialize-diagnostic-file", true)
Aaron Ballman6c60ed52017-05-01 13:05:04 +000053 .Cases("-o", "-dependency-file", true)
Bruno Cardoso Lopes7aff2bb2016-12-12 19:28:25 +000054 .Cases("-fdebug-compilation-dir", "-diagnostic-log-file", true)
Justin Bogner61c0e432014-06-22 20:35:10 +000055 .Cases("-dwarf-debug-flags", "-ivfsoverlay", true)
Hans Wennborgb212b342013-09-12 18:23:34 +000056 .Default(false);
Bruno Cardoso Lopese3a0aef2016-12-09 02:22:47 +000057 if (ShouldSkip)
58 return true;
Hans Wennborgb212b342013-09-12 18:23:34 +000059
Bruno Cardoso Lopese3a0aef2016-12-09 02:22:47 +000060 // Some include flags shouldn't be skipped if we have a crash VFS
61 IsInclude = llvm::StringSwitch<bool>(Flag)
62 .Cases("-include", "-header-include-file", true)
63 .Cases("-idirafter", "-internal-isystem", "-iwithprefix", true)
64 .Cases("-internal-externc-isystem", "-iprefix", true)
65 .Cases("-iwithprefixbefore", "-isystem", "-iquote", true)
66 .Cases("-isysroot", "-I", "-F", "-resource-dir", true)
Erich Keane6c483592017-12-11 18:14:51 +000067 .Cases("-iframework", "-include-pch", true)
Bruno Cardoso Lopese3a0aef2016-12-09 02:22:47 +000068 .Default(false);
69 if (IsInclude)
70 return HaveCrashVFS ? false : true;
Hans Wennborgb212b342013-09-12 18:23:34 +000071
72 // The remaining flags are treated as a single argument.
73
74 // These flags are all of the form -Flag and have no second argument.
Bruno Cardoso Lopese3a0aef2016-12-09 02:22:47 +000075 ShouldSkip = llvm::StringSwitch<bool>(Flag)
Richard Smithdaae9522017-10-20 00:25:07 +000076 .Cases("-M", "-MM", "-MG", "-MP", "-MD", true)
77 .Case("-MMD", true)
Hans Wennborgb212b342013-09-12 18:23:34 +000078 .Default(false);
79
80 // Match found.
Bruno Cardoso Lopese3a0aef2016-12-09 02:22:47 +000081 SkipNum = 1;
82 if (ShouldSkip)
83 return true;
Hans Wennborgb212b342013-09-12 18:23:34 +000084
85 // These flags are treated as a single argument (e.g., -F<Dir>).
86 StringRef FlagRef(Flag);
Bruno Cardoso Lopese3a0aef2016-12-09 02:22:47 +000087 IsInclude = FlagRef.startswith("-F") || FlagRef.startswith("-I");
88 if (IsInclude)
89 return HaveCrashVFS ? false : true;
90 if (FlagRef.startswith("-fmodules-cache-path="))
91 return true;
Hans Wennborgb212b342013-09-12 18:23:34 +000092
Bruno Cardoso Lopese3a0aef2016-12-09 02:22:47 +000093 SkipNum = 0;
94 return false;
Hans Wennborgb212b342013-09-12 18:23:34 +000095}
96
Mehdi Amini5bf825b2016-10-08 01:38:43 +000097void Command::printArg(raw_ostream &OS, StringRef Arg, bool Quote) {
98 const bool Escape = Arg.find_first_of("\"\\$") != StringRef::npos;
Hans Wennborgb212b342013-09-12 18:23:34 +000099
100 if (!Quote && !Escape) {
101 OS << Arg;
102 return;
103 }
104
105 // Quote and escape. This isn't really complete, but good enough.
106 OS << '"';
Mehdi Amini5bf825b2016-10-08 01:38:43 +0000107 for (const char c : Arg) {
Hans Wennborgb212b342013-09-12 18:23:34 +0000108 if (c == '"' || c == '\\' || c == '$')
109 OS << '\\';
110 OS << c;
111 }
112 OS << '"';
113}
114
Reid Kleckner0290c9c2014-09-15 17:45:39 +0000115void Command::writeResponseFile(raw_ostream &OS) const {
116 // In a file list, we only write the set of inputs to the response file
117 if (Creator.getResponseFilesSupport() == Tool::RF_FileList) {
118 for (const char *Arg : InputFileList) {
119 OS << Arg << '\n';
120 }
121 return;
122 }
123
Reid Klecknere2d03442015-07-15 22:42:37 +0000124 // In regular response files, we send all arguments to the response file.
125 // Wrapping all arguments in double quotes ensures that both Unix tools and
126 // Windows tools understand the response file.
Reid Kleckner0290c9c2014-09-15 17:45:39 +0000127 for (const char *Arg : Arguments) {
128 OS << '"';
129
130 for (; *Arg != '\0'; Arg++) {
131 if (*Arg == '\"' || *Arg == '\\') {
132 OS << '\\';
133 }
134 OS << *Arg;
135 }
136
137 OS << "\" ";
138 }
139}
140
141void Command::buildArgvForResponseFile(
142 llvm::SmallVectorImpl<const char *> &Out) const {
143 // When not a file list, all arguments are sent to the response file.
144 // This leaves us to set the argv to a single parameter, requesting the tool
145 // to read the response file.
146 if (Creator.getResponseFilesSupport() != Tool::RF_FileList) {
147 Out.push_back(Executable);
148 Out.push_back(ResponseFileFlag.c_str());
149 return;
150 }
151
152 llvm::StringSet<> Inputs;
153 for (const char *InputName : InputFileList)
154 Inputs.insert(InputName);
155 Out.push_back(Executable);
156 // In a file list, build args vector ignoring parameters that will go in the
157 // response file (elements of the InputFileList vector)
158 bool FirstInput = true;
159 for (const char *Arg : Arguments) {
160 if (Inputs.count(Arg) == 0) {
161 Out.push_back(Arg);
162 } else if (FirstInput) {
163 FirstInput = false;
164 Out.push_back(Creator.getResponseFileFlag());
165 Out.push_back(ResponseFile);
166 }
167 }
168}
169
Bruno Cardoso Lopese3a0aef2016-12-09 02:22:47 +0000170/// @brief Rewrite relative include-like flag paths to absolute ones.
171static void
172rewriteIncludes(const llvm::ArrayRef<const char *> &Args, size_t Idx,
173 size_t NumArgs,
174 llvm::SmallVectorImpl<llvm::SmallString<128>> &IncFlags) {
175 using namespace llvm;
176 using namespace sys;
177 auto getAbsPath = [](StringRef InInc, SmallVectorImpl<char> &OutInc) -> bool {
178 if (path::is_absolute(InInc)) // Nothing to do here...
179 return false;
180 std::error_code EC = fs::current_path(OutInc);
181 if (EC)
182 return false;
183 path::append(OutInc, InInc);
184 return true;
185 };
186
187 SmallString<128> NewInc;
188 if (NumArgs == 1) {
189 StringRef FlagRef(Args[Idx + NumArgs - 1]);
190 assert((FlagRef.startswith("-F") || FlagRef.startswith("-I")) &&
191 "Expecting -I or -F");
192 StringRef Inc = FlagRef.slice(2, StringRef::npos);
193 if (getAbsPath(Inc, NewInc)) {
194 SmallString<128> NewArg(FlagRef.slice(0, 2));
195 NewArg += NewInc;
196 IncFlags.push_back(std::move(NewArg));
197 }
198 return;
199 }
200
201 assert(NumArgs == 2 && "Not expecting more than two arguments");
202 StringRef Inc(Args[Idx + NumArgs - 1]);
203 if (!getAbsPath(Inc, NewInc))
204 return;
205 IncFlags.push_back(SmallString<128>(Args[Idx]));
206 IncFlags.push_back(std::move(NewInc));
207}
208
Hans Wennborgb212b342013-09-12 18:23:34 +0000209void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
Justin Bogner25645152014-10-21 17:24:44 +0000210 CrashReportInfo *CrashInfo) const {
Reid Kleckner822434d2014-08-05 20:49:12 +0000211 // Always quote the exe.
Reid Kleckner4f1fc352014-08-07 00:05:00 +0000212 OS << ' ';
Justin Bognered9cbe02015-07-09 06:58:31 +0000213 printArg(OS, Executable, /*Quote=*/true);
Hans Wennborgb212b342013-09-12 18:23:34 +0000214
Reid Kleckner0290c9c2014-09-15 17:45:39 +0000215 llvm::ArrayRef<const char *> Args = Arguments;
216 llvm::SmallVector<const char *, 128> ArgsRespFile;
217 if (ResponseFile != nullptr) {
218 buildArgvForResponseFile(ArgsRespFile);
219 Args = ArrayRef<const char *>(ArgsRespFile).slice(1); // no executable name
220 }
221
Justin Bogner0cb14752015-03-12 00:52:56 +0000222 bool HaveCrashVFS = CrashInfo && !CrashInfo->VFSPath.empty();
Reid Kleckner0290c9c2014-09-15 17:45:39 +0000223 for (size_t i = 0, e = Args.size(); i < e; ++i) {
224 const char *const Arg = Args[i];
Hans Wennborgb212b342013-09-12 18:23:34 +0000225
Justin Bogner25645152014-10-21 17:24:44 +0000226 if (CrashInfo) {
Bruno Cardoso Lopese3a0aef2016-12-09 02:22:47 +0000227 int NumArgs = 0;
228 bool IsInclude = false;
229 if (skipArgs(Arg, HaveCrashVFS, NumArgs, IsInclude)) {
230 i += NumArgs - 1;
Hans Wennborgb212b342013-09-12 18:23:34 +0000231 continue;
Justin Bognerd3371d82015-07-17 03:35:54 +0000232 }
Bruno Cardoso Lopese3a0aef2016-12-09 02:22:47 +0000233
234 // Relative includes need to be expanded to absolute paths.
235 if (HaveCrashVFS && IsInclude) {
236 SmallVector<SmallString<128>, 2> NewIncFlags;
237 rewriteIncludes(Args, i, NumArgs, NewIncFlags);
238 if (!NewIncFlags.empty()) {
239 for (auto &F : NewIncFlags) {
240 OS << ' ';
241 printArg(OS, F.c_str(), Quote);
242 }
243 i += NumArgs - 1;
244 continue;
245 }
246 }
247
Justin Bognerd3371d82015-07-17 03:35:54 +0000248 auto Found = std::find_if(InputFilenames.begin(), InputFilenames.end(),
249 [&Arg](StringRef IF) { return IF == Arg; });
250 if (Found != InputFilenames.end() &&
251 (i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
Justin Bogner25645152014-10-21 17:24:44 +0000252 // Replace the input file name with the crashinfo's file name.
253 OS << ' ';
254 StringRef ShortName = llvm::sys::path::filename(CrashInfo->Filename);
Malcolm Parsonsf76f6502016-11-02 10:39:27 +0000255 printArg(OS, ShortName.str(), Quote);
Justin Bogner25645152014-10-21 17:24:44 +0000256 continue;
Hans Wennborgb212b342013-09-12 18:23:34 +0000257 }
258 }
259
260 OS << ' ';
Justin Bognered9cbe02015-07-09 06:58:31 +0000261 printArg(OS, Arg, Quote);
Hans Wennborgb212b342013-09-12 18:23:34 +0000262 }
Reid Kleckner0290c9c2014-09-15 17:45:39 +0000263
Justin Bogner0cb14752015-03-12 00:52:56 +0000264 if (CrashInfo && HaveCrashVFS) {
Justin Bogner25645152014-10-21 17:24:44 +0000265 OS << ' ';
Justin Bognered9cbe02015-07-09 06:58:31 +0000266 printArg(OS, "-ivfsoverlay", Quote);
Justin Bogner25645152014-10-21 17:24:44 +0000267 OS << ' ';
Malcolm Parsonsf76f6502016-11-02 10:39:27 +0000268 printArg(OS, CrashInfo->VFSPath.str(), Quote);
Bruno Cardoso Lopesf854b042016-04-01 17:39:08 +0000269
Bruno Cardoso Lopes1c108722016-12-09 03:11:48 +0000270 // The leftover modules from the crash are stored in
271 // <name>.cache/vfs/modules
272 // Leave it untouched for pcm inspection and provide a clean/empty dir
273 // path to contain the future generated module cache:
274 // <name>.cache/vfs/repro-modules
Bruno Cardoso Lopesf854b042016-04-01 17:39:08 +0000275 SmallString<128> RelModCacheDir = llvm::sys::path::parent_path(
276 llvm::sys::path::parent_path(CrashInfo->VFSPath));
Bruno Cardoso Lopes1c108722016-12-09 03:11:48 +0000277 llvm::sys::path::append(RelModCacheDir, "repro-modules");
Bruno Cardoso Lopesf854b042016-04-01 17:39:08 +0000278
279 std::string ModCachePath = "-fmodules-cache-path=";
280 ModCachePath.append(RelModCacheDir.c_str());
281
282 OS << ' ';
Malcolm Parsonsf76f6502016-11-02 10:39:27 +0000283 printArg(OS, ModCachePath, Quote);
Justin Bogner25645152014-10-21 17:24:44 +0000284 }
285
Reid Kleckner0290c9c2014-09-15 17:45:39 +0000286 if (ResponseFile != nullptr) {
287 OS << "\n Arguments passed via response file:\n";
288 writeResponseFile(OS);
289 // Avoiding duplicated newline terminator, since FileLists are
290 // newline-separated.
291 if (Creator.getResponseFilesSupport() != Tool::RF_FileList)
292 OS << "\n";
293 OS << " (end of response file)";
294 }
295
Hans Wennborgb212b342013-09-12 18:23:34 +0000296 OS << Terminator;
297}
298
Reid Kleckner0290c9c2014-09-15 17:45:39 +0000299void Command::setResponseFile(const char *FileName) {
300 ResponseFile = FileName;
301 ResponseFileFlag = Creator.getResponseFileFlag();
302 ResponseFileFlag += FileName;
303}
304
Zachary Turnera0f96be2017-03-17 16:24:34 +0000305void Command::setEnvironment(llvm::ArrayRef<const char *> NewEnvironment) {
306 Environment.reserve(NewEnvironment.size() + 1);
307 Environment.assign(NewEnvironment.begin(), NewEnvironment.end());
308 Environment.push_back(nullptr);
309}
310
Alexander Kornienko1e531952017-09-13 17:45:51 +0000311int Command::Execute(ArrayRef<llvm::Optional<StringRef>> Redirects,
Alexander Kornienko9707aa72017-09-13 17:03:58 +0000312 std::string *ErrMsg, bool *ExecutionFailed) const {
Hans Wennborge8677ef2013-09-12 18:35:08 +0000313 SmallVector<const char*, 128> Argv;
Reid Kleckner0290c9c2014-09-15 17:45:39 +0000314
Zachary Turnera0f96be2017-03-17 16:24:34 +0000315 const char **Envp;
316 if (Environment.empty()) {
317 Envp = nullptr;
318 } else {
319 assert(Environment.back() == nullptr &&
320 "Environment vector should be null-terminated by now");
321 Envp = const_cast<const char **>(Environment.data());
322 }
323
Reid Kleckner0290c9c2014-09-15 17:45:39 +0000324 if (ResponseFile == nullptr) {
325 Argv.push_back(Executable);
Benjamin Kramerf9890422015-02-17 16:48:30 +0000326 Argv.append(Arguments.begin(), Arguments.end());
Reid Kleckner0290c9c2014-09-15 17:45:39 +0000327 Argv.push_back(nullptr);
328
Zachary Turnera0f96be2017-03-17 16:24:34 +0000329 return llvm::sys::ExecuteAndWait(
330 Executable, Argv.data(), Envp, Redirects, /*secondsToWait*/ 0,
331 /*memoryLimit*/ 0, ErrMsg, ExecutionFailed);
Reid Kleckner0290c9c2014-09-15 17:45:39 +0000332 }
333
334 // We need to put arguments in a response file (command is too large)
335 // Open stream to store the response file contents
336 std::string RespContents;
337 llvm::raw_string_ostream SS(RespContents);
338
339 // Write file contents and build the Argv vector
340 writeResponseFile(SS);
341 buildArgvForResponseFile(Argv);
Craig Topper92fc2df2014-05-17 16:56:41 +0000342 Argv.push_back(nullptr);
Reid Kleckner0290c9c2014-09-15 17:45:39 +0000343 SS.flush();
344
345 // Save the response file in the appropriate encoding
346 if (std::error_code EC = writeFileWithEncoding(
347 ResponseFile, RespContents, Creator.getResponseFileEncoding())) {
348 if (ErrMsg)
349 *ErrMsg = EC.message();
350 if (ExecutionFailed)
351 *ExecutionFailed = true;
352 return -1;
353 }
Hans Wennborge8677ef2013-09-12 18:35:08 +0000354
Zachary Turnera0f96be2017-03-17 16:24:34 +0000355 return llvm::sys::ExecuteAndWait(Executable, Argv.data(), Envp, Redirects,
356 /*secondsToWait*/ 0,
Hans Wennborge8677ef2013-09-12 18:35:08 +0000357 /*memoryLimit*/ 0, ErrMsg, ExecutionFailed);
358}
359
Hans Wennborg87cfa712013-09-19 20:32:16 +0000360FallbackCommand::FallbackCommand(const Action &Source_, const Tool &Creator_,
361 const char *Executable_,
362 const ArgStringList &Arguments_,
Justin Bognerd3371d82015-07-17 03:35:54 +0000363 ArrayRef<InputInfo> Inputs,
David Blaikiec11bf802014-09-04 16:04:28 +0000364 std::unique_ptr<Command> Fallback_)
Justin Bognerd3371d82015-07-17 03:35:54 +0000365 : Command(Source_, Creator_, Executable_, Arguments_, Inputs),
David Blaikiec11bf802014-09-04 16:04:28 +0000366 Fallback(std::move(Fallback_)) {}
Hans Wennborg87cfa712013-09-19 20:32:16 +0000367
368void FallbackCommand::Print(raw_ostream &OS, const char *Terminator,
Justin Bogner25645152014-10-21 17:24:44 +0000369 bool Quote, CrashReportInfo *CrashInfo) const {
370 Command::Print(OS, "", Quote, CrashInfo);
Hans Wennborg87cfa712013-09-19 20:32:16 +0000371 OS << " ||";
Justin Bogner25645152014-10-21 17:24:44 +0000372 Fallback->Print(OS, Terminator, Quote, CrashInfo);
Hans Wennborg87cfa712013-09-19 20:32:16 +0000373}
374
375static bool ShouldFallback(int ExitCode) {
376 // FIXME: We really just want to fall back for internal errors, such
377 // as when some symbol cannot be mangled, when we should be able to
378 // parse something but can't, etc.
379 return ExitCode != 0;
380}
381
Alexander Kornienko1e531952017-09-13 17:45:51 +0000382int FallbackCommand::Execute(ArrayRef<llvm::Optional<StringRef>> Redirects,
Alexander Kornienko9707aa72017-09-13 17:03:58 +0000383 std::string *ErrMsg, bool *ExecutionFailed) const {
Hans Wennborg87cfa712013-09-19 20:32:16 +0000384 int PrimaryStatus = Command::Execute(Redirects, ErrMsg, ExecutionFailed);
385 if (!ShouldFallback(PrimaryStatus))
386 return PrimaryStatus;
387
388 // Clear ExecutionFailed and ErrMsg before falling back.
389 if (ErrMsg)
390 ErrMsg->clear();
391 if (ExecutionFailed)
392 *ExecutionFailed = false;
393
Hans Wennborgc5afd062014-02-18 21:42:51 +0000394 const Driver &D = getCreator().getToolChain().getDriver();
Hans Wennborg897a69b2014-02-19 02:10:19 +0000395 D.Diag(diag::warn_drv_invoking_fallback) << Fallback->getExecutable();
Hans Wennborgc5afd062014-02-18 21:42:51 +0000396
Hans Wennborg87cfa712013-09-19 20:32:16 +0000397 int SecondaryStatus = Fallback->Execute(Redirects, ErrMsg, ExecutionFailed);
398 return SecondaryStatus;
399}
400
Nico Weber2ca4be92016-03-01 23:16:44 +0000401ForceSuccessCommand::ForceSuccessCommand(const Action &Source_,
402 const Tool &Creator_,
403 const char *Executable_,
404 const ArgStringList &Arguments_,
405 ArrayRef<InputInfo> Inputs)
406 : Command(Source_, Creator_, Executable_, Arguments_, Inputs) {}
407
408void ForceSuccessCommand::Print(raw_ostream &OS, const char *Terminator,
409 bool Quote, CrashReportInfo *CrashInfo) const {
410 Command::Print(OS, "", Quote, CrashInfo);
411 OS << " || (exit 0)" << Terminator;
412}
413
Alexander Kornienko1e531952017-09-13 17:45:51 +0000414int ForceSuccessCommand::Execute(ArrayRef<llvm::Optional<StringRef>> Redirects,
Nico Weber2ca4be92016-03-01 23:16:44 +0000415 std::string *ErrMsg,
416 bool *ExecutionFailed) const {
417 int Status = Command::Execute(Redirects, ErrMsg, ExecutionFailed);
418 (void)Status;
419 if (ExecutionFailed)
420 *ExecutionFailed = false;
421 return 0;
422}
423
Hans Wennborgb212b342013-09-12 18:23:34 +0000424void JobList::Print(raw_ostream &OS, const char *Terminator, bool Quote,
Justin Bogner25645152014-10-21 17:24:44 +0000425 CrashReportInfo *CrashInfo) const {
Justin Bogneraab97922014-10-03 01:04:53 +0000426 for (const auto &Job : *this)
Justin Bogner25645152014-10-21 17:24:44 +0000427 Job.Print(OS, Terminator, Quote, CrashInfo);
Hans Wennborgb212b342013-09-12 18:23:34 +0000428}
429
David Blaikiec11bf802014-09-04 16:04:28 +0000430void JobList::clear() { Jobs.clear(); }