Nick Lewycky | 3fdcc6f | 2010-12-31 17:31:54 +0000 | [diff] [blame] | 1 | //===--- Compilation.cpp - Compilation Task Implementation ----------------===// |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +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 | |
| 10 | #include "clang/Driver/Compilation.h" |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 11 | #include "clang/Driver/Action.h" |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 12 | #include "clang/Driver/ArgList.h" |
Daniel Dunbar | e530ad4 | 2009-03-18 22:16:03 +0000 | [diff] [blame] | 13 | #include "clang/Driver/Driver.h" |
| 14 | #include "clang/Driver/DriverDiagnostic.h" |
Daniel Dunbar | 265e9ef | 2009-11-19 04:25:22 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Options.h" |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 16 | #include "clang/Driver/ToolChain.h" |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" |
Chad Rosier | c91b41a | 2012-10-31 18:31:33 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringSwitch.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Program.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | e530ad4 | 2009-03-18 22:16:03 +0000 | [diff] [blame] | 21 | #include <errno.h> |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 22 | #include <sys/stat.h> |
Francois Pichet | 1c3199a | 2011-07-23 11:36:43 +0000 | [diff] [blame] | 23 | |
Daniel Dunbar | 1b3bb6e | 2009-03-04 20:49:20 +0000 | [diff] [blame] | 24 | using namespace clang::driver; |
Francois Pichet | 1c3199a | 2011-07-23 11:36:43 +0000 | [diff] [blame] | 25 | using namespace clang; |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 26 | |
Daniel Dunbar | 279c1db | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 27 | Compilation::Compilation(const Driver &D, const ToolChain &_DefaultToolChain, |
| 28 | InputArgList *_Args, DerivedArgList *_TranslatedArgs) |
| 29 | : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args), |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 30 | TranslatedArgs(_TranslatedArgs), Redirects(0) { |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 33 | Compilation::~Compilation() { |
Daniel Dunbar | 279c1db | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 34 | delete TranslatedArgs; |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 35 | delete Args; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 36 | |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 37 | // Free any derived arg lists. |
Daniel Dunbar | 4954018 | 2009-09-09 18:36:01 +0000 | [diff] [blame] | 38 | for (llvm::DenseMap<std::pair<const ToolChain*, const char*>, |
| 39 | DerivedArgList*>::iterator it = TCArgs.begin(), |
| 40 | ie = TCArgs.end(); it != ie; ++it) |
Daniel Dunbar | 279c1db | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 41 | if (it->second != TranslatedArgs) |
| 42 | delete it->second; |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 43 | |
| 44 | // Free the actions, if built. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 45 | for (ActionList::iterator it = Actions.begin(), ie = Actions.end(); |
Daniel Dunbar | 2154923 | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 46 | it != ie; ++it) |
| 47 | delete *it; |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 48 | |
| 49 | // Free redirections of stdout/stderr. |
| 50 | if (Redirects) { |
| 51 | delete Redirects[1]; |
| 52 | delete Redirects[2]; |
| 53 | delete [] Redirects; |
| 54 | } |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Daniel Dunbar | 4954018 | 2009-09-09 18:36:01 +0000 | [diff] [blame] | 57 | const DerivedArgList &Compilation::getArgsForToolChain(const ToolChain *TC, |
| 58 | const char *BoundArch) { |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 59 | if (!TC) |
| 60 | TC = &DefaultToolChain; |
| 61 | |
Daniel Dunbar | 4954018 | 2009-09-09 18:36:01 +0000 | [diff] [blame] | 62 | DerivedArgList *&Entry = TCArgs[std::make_pair(TC, BoundArch)]; |
Daniel Dunbar | 279c1db | 2010-06-11 22:00:26 +0000 | [diff] [blame] | 63 | if (!Entry) { |
| 64 | Entry = TC->TranslateArgs(*TranslatedArgs, BoundArch); |
| 65 | if (!Entry) |
| 66 | Entry = TranslatedArgs; |
| 67 | } |
Daniel Dunbar | 586dc23 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 68 | |
Daniel Dunbar | aa3e0d2 | 2009-03-18 05:58:45 +0000 | [diff] [blame] | 69 | return *Entry; |
Daniel Dunbar | 3ede8d0 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 72 | void Compilation::PrintJob(raw_ostream &OS, const Job &J, |
Daniel Dunbar | 49b98e7 | 2009-03-18 22:44:24 +0000 | [diff] [blame] | 73 | const char *Terminator, bool Quote) const { |
| 74 | if (const Command *C = dyn_cast<Command>(&J)) { |
Daniel Dunbar | 24b5560 | 2009-03-18 06:49:39 +0000 | [diff] [blame] | 75 | OS << " \"" << C->getExecutable() << '"'; |
| 76 | for (ArgStringList::const_iterator it = C->getArguments().begin(), |
Daniel Dunbar | 49b98e7 | 2009-03-18 22:44:24 +0000 | [diff] [blame] | 77 | ie = C->getArguments().end(); it != ie; ++it) { |
Daniel Dunbar | b86c5fc | 2010-03-20 08:01:53 +0000 | [diff] [blame] | 78 | OS << ' '; |
Benjamin Kramer | 5f22614 | 2011-10-06 22:53:35 +0000 | [diff] [blame] | 79 | if (!Quote && !std::strpbrk(*it, " \"\\$")) { |
Daniel Dunbar | b86c5fc | 2010-03-20 08:01:53 +0000 | [diff] [blame] | 80 | OS << *it; |
| 81 | continue; |
| 82 | } |
| 83 | |
| 84 | // Quote the argument and escape shell special characters; this isn't |
| 85 | // really complete but is good enough. |
| 86 | OS << '"'; |
| 87 | for (const char *s = *it; *s; ++s) { |
| 88 | if (*s == '"' || *s == '\\' || *s == '$') |
| 89 | OS << '\\'; |
| 90 | OS << *s; |
| 91 | } |
| 92 | OS << '"'; |
Daniel Dunbar | 49b98e7 | 2009-03-18 22:44:24 +0000 | [diff] [blame] | 93 | } |
Daniel Dunbar | 24b5560 | 2009-03-18 06:49:39 +0000 | [diff] [blame] | 94 | OS << Terminator; |
Daniel Dunbar | 24b5560 | 2009-03-18 06:49:39 +0000 | [diff] [blame] | 95 | } else { |
Daniel Dunbar | 49b98e7 | 2009-03-18 22:44:24 +0000 | [diff] [blame] | 96 | const JobList *Jobs = cast<JobList>(&J); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 97 | for (JobList::const_iterator |
Daniel Dunbar | 24b5560 | 2009-03-18 06:49:39 +0000 | [diff] [blame] | 98 | it = Jobs->begin(), ie = Jobs->end(); it != ie; ++it) |
Daniel Dunbar | 49b98e7 | 2009-03-18 22:44:24 +0000 | [diff] [blame] | 99 | PrintJob(OS, **it, Terminator, Quote); |
Daniel Dunbar | 24b5560 | 2009-03-18 06:49:39 +0000 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
Chad Rosier | c91b41a | 2012-10-31 18:31:33 +0000 | [diff] [blame] | 103 | static bool skipArg(const char *Flag, bool &SkipNextArg) { |
| 104 | StringRef FlagRef(Flag); |
| 105 | |
| 106 | // Assume we're going to see -Flag <Arg>. |
| 107 | SkipNextArg = true; |
| 108 | |
| 109 | // These flags are all of the form -Flag <Arg> and are treated as two |
| 110 | // arguments. Therefore, we need to skip the flag and the next argument. |
| 111 | bool Res = llvm::StringSwitch<bool>(Flag) |
| 112 | .Cases("-I", "-MF", "-MT", "-MQ", true) |
| 113 | .Cases("-o", "-coverage-file", "-dependency-file", true) |
Douglas Gregor | 250172a | 2013-02-07 22:59:12 +0000 | [diff] [blame] | 114 | .Cases("-fdebug-compilation-dir", "-idirafter", true) |
Chad Rosier | c91b41a | 2012-10-31 18:31:33 +0000 | [diff] [blame] | 115 | .Cases("-include", "-include-pch", "-internal-isystem", true) |
Chad Rosier | 1cd46de | 2012-10-31 21:08:30 +0000 | [diff] [blame] | 116 | .Cases("-internal-externc-isystem", "-iprefix", "-iwithprefix", true) |
Chad Rosier | c91b41a | 2012-10-31 18:31:33 +0000 | [diff] [blame] | 117 | .Cases("-iwithprefixbefore", "-isysroot", "-isystem", "-iquote", true) |
| 118 | .Cases("-resource-dir", "-serialize-diagnostic-file", true) |
| 119 | .Case("-dwarf-debug-flags", true) |
| 120 | .Default(false); |
| 121 | |
| 122 | // Match found. |
| 123 | if (Res) |
| 124 | return Res; |
| 125 | |
| 126 | // The remaining flags are treated as a single argument. |
| 127 | SkipNextArg = false; |
| 128 | |
| 129 | // These flags are all of the form -Flag and have no second argument. |
| 130 | Res = llvm::StringSwitch<bool>(Flag) |
| 131 | .Cases("-M", "-MM", "-MG", "-MP", "-MD", true) |
| 132 | .Case("-MMD", true) |
| 133 | .Default(false); |
| 134 | |
| 135 | // Match found. |
| 136 | if (Res) |
| 137 | return Res; |
| 138 | |
| 139 | // These flags are treated as a single argument (e.g., -F<Dir>). |
| 140 | if (FlagRef.startswith("-F") || FlagRef.startswith("-I")) |
| 141 | return true; |
| 142 | |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | static bool quoteNextArg(const char *flag) { |
| 147 | return llvm::StringSwitch<bool>(flag) |
| 148 | .Case("-D", true) |
| 149 | .Default(false); |
| 150 | } |
| 151 | |
| 152 | void Compilation::PrintDiagnosticJob(raw_ostream &OS, const Job &J) const { |
| 153 | if (const Command *C = dyn_cast<Command>(&J)) { |
| 154 | OS << C->getExecutable(); |
| 155 | unsigned QuoteNextArg = 0; |
| 156 | for (ArgStringList::const_iterator it = C->getArguments().begin(), |
| 157 | ie = C->getArguments().end(); it != ie; ++it) { |
| 158 | |
| 159 | bool SkipNext; |
| 160 | if (skipArg(*it, SkipNext)) { |
| 161 | if (SkipNext) ++it; |
| 162 | continue; |
| 163 | } |
| 164 | |
| 165 | if (!QuoteNextArg) |
| 166 | QuoteNextArg = quoteNextArg(*it) ? 2 : 0; |
| 167 | |
| 168 | OS << ' '; |
| 169 | |
| 170 | if (QuoteNextArg == 1) |
| 171 | OS << '"'; |
| 172 | |
| 173 | if (!std::strpbrk(*it, " \"\\$")) { |
| 174 | OS << *it; |
| 175 | } else { |
| 176 | // Quote the argument and escape shell special characters; this isn't |
| 177 | // really complete but is good enough. |
| 178 | OS << '"'; |
| 179 | for (const char *s = *it; *s; ++s) { |
| 180 | if (*s == '"' || *s == '\\' || *s == '$') |
| 181 | OS << '\\'; |
| 182 | OS << *s; |
| 183 | } |
| 184 | OS << '"'; |
| 185 | } |
| 186 | |
| 187 | if (QuoteNextArg) { |
| 188 | if (QuoteNextArg == 1) |
| 189 | OS << '"'; |
| 190 | --QuoteNextArg; |
| 191 | } |
| 192 | } |
| 193 | OS << '\n'; |
| 194 | } else { |
| 195 | const JobList *Jobs = cast<JobList>(&J); |
| 196 | for (JobList::const_iterator |
| 197 | it = Jobs->begin(), ie = Jobs->end(); it != ie; ++it) |
| 198 | PrintDiagnosticJob(OS, **it); |
| 199 | } |
| 200 | } |
| 201 | |
Chad Rosier | 9d71863 | 2013-01-24 19:14:47 +0000 | [diff] [blame] | 202 | bool Compilation::CleanupFile(const char *File, bool IssueErrors) const { |
| 203 | llvm::sys::Path P(File); |
| 204 | std::string Error; |
| 205 | |
| 206 | // Don't try to remove files which we don't have write access to (but may be |
| 207 | // able to remove), or non-regular files. Underlying tools may have |
| 208 | // intentionally not overwritten them. |
| 209 | if (!P.canWrite() || !P.isRegularFile()) |
| 210 | return true; |
| 211 | |
| 212 | if (P.eraseFromDisk(false, &Error)) { |
| 213 | // Failure is only failure if the file exists and is "regular". There is |
| 214 | // a race condition here due to the limited interface of |
| 215 | // llvm::sys::Path, we want to know if the removal gave ENOENT. |
| 216 | |
| 217 | // FIXME: Grumble, P.exists() is broken. PR3837. |
| 218 | struct stat buf; |
| 219 | if (::stat(P.c_str(), &buf) == 0 ? (buf.st_mode & S_IFMT) == S_IFREG : |
| 220 | (errno != ENOENT)) { |
| 221 | if (IssueErrors) |
| 222 | getDriver().Diag(clang::diag::err_drv_unable_to_remove_file) |
| 223 | << Error; |
| 224 | return false; |
| 225 | } |
| 226 | } |
| 227 | return true; |
| 228 | } |
| 229 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 230 | bool Compilation::CleanupFileList(const ArgStringList &Files, |
Daniel Dunbar | e530ad4 | 2009-03-18 22:16:03 +0000 | [diff] [blame] | 231 | bool IssueErrors) const { |
| 232 | bool Success = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 233 | for (ArgStringList::const_iterator |
Chad Rosier | 9d71863 | 2013-01-24 19:14:47 +0000 | [diff] [blame] | 234 | it = Files.begin(), ie = Files.end(); it != ie; ++it) |
| 235 | Success &= CleanupFile(*it, IssueErrors); |
| 236 | return Success; |
| 237 | } |
| 238 | |
| 239 | bool Compilation::CleanupFileMap(const ArgStringMap &Files, |
| 240 | const JobAction *JA, |
| 241 | bool IssueErrors) const { |
| 242 | bool Success = true; |
| 243 | for (ArgStringMap::const_iterator |
Daniel Dunbar | e530ad4 | 2009-03-18 22:16:03 +0000 | [diff] [blame] | 244 | it = Files.begin(), ie = Files.end(); it != ie; ++it) { |
Edward O'Callaghan | 56eec2b | 2009-11-24 15:23:21 +0000 | [diff] [blame] | 245 | |
Chad Rosier | 9d71863 | 2013-01-24 19:14:47 +0000 | [diff] [blame] | 246 | // If specified, only delete the files associated with the JobAction. |
| 247 | // Otherwise, delete all files in the map. |
| 248 | if (JA && it->first != JA) |
Daniel Dunbar | 8ac127a | 2011-04-25 20:43:05 +0000 | [diff] [blame] | 249 | continue; |
Chad Rosier | 9d71863 | 2013-01-24 19:14:47 +0000 | [diff] [blame] | 250 | Success &= CleanupFile(it->second, IssueErrors); |
Daniel Dunbar | e530ad4 | 2009-03-18 22:16:03 +0000 | [diff] [blame] | 251 | } |
Daniel Dunbar | e530ad4 | 2009-03-18 22:16:03 +0000 | [diff] [blame] | 252 | return Success; |
| 253 | } |
| 254 | |
Daniel Dunbar | 31c11eb | 2009-07-01 19:14:39 +0000 | [diff] [blame] | 255 | int Compilation::ExecuteCommand(const Command &C, |
| 256 | const Command *&FailingCommand) const { |
Daniel Dunbar | ceafbc8 | 2009-03-19 08:01:45 +0000 | [diff] [blame] | 257 | llvm::sys::Path Prog(C.getExecutable()); |
| 258 | const char **Argv = new const char*[C.getArguments().size() + 2]; |
| 259 | Argv[0] = C.getExecutable(); |
| 260 | std::copy(C.getArguments().begin(), C.getArguments().end(), Argv+1); |
| 261 | Argv[C.getArguments().size() + 1] = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 262 | |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 263 | if ((getDriver().CCCEcho || getDriver().CCPrintOptions || |
| 264 | getArgs().hasArg(options::OPT_v)) && !getDriver().CCGenDiagnostics) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 265 | raw_ostream *OS = &llvm::errs(); |
Daniel Dunbar | 4c00fcd | 2010-03-20 08:01:59 +0000 | [diff] [blame] | 266 | |
| 267 | // Follow gcc implementation of CC_PRINT_OPTIONS; we could also cache the |
| 268 | // output stream. |
| 269 | if (getDriver().CCPrintOptions && getDriver().CCPrintOptionsFilename) { |
| 270 | std::string Error; |
| 271 | OS = new llvm::raw_fd_ostream(getDriver().CCPrintOptionsFilename, |
| 272 | Error, |
| 273 | llvm::raw_fd_ostream::F_Append); |
| 274 | if (!Error.empty()) { |
| 275 | getDriver().Diag(clang::diag::err_drv_cc_print_options_failure) |
| 276 | << Error; |
| 277 | FailingCommand = &C; |
| 278 | delete OS; |
| 279 | return 1; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | if (getDriver().CCPrintOptions) |
| 284 | *OS << "[Logging clang options]"; |
| 285 | |
| 286 | PrintJob(*OS, C, "\n", /*Quote=*/getDriver().CCPrintOptions); |
| 287 | |
| 288 | if (OS != &llvm::errs()) |
| 289 | delete OS; |
| 290 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 291 | |
Daniel Dunbar | ceafbc8 | 2009-03-19 08:01:45 +0000 | [diff] [blame] | 292 | std::string Error; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | int Res = |
Daniel Dunbar | ceafbc8 | 2009-03-19 08:01:45 +0000 | [diff] [blame] | 294 | llvm::sys::Program::ExecuteAndWait(Prog, Argv, |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 295 | /*env*/0, Redirects, |
Daniel Dunbar | ceafbc8 | 2009-03-19 08:01:45 +0000 | [diff] [blame] | 296 | /*secondsToWait*/0, /*memoryLimit*/0, |
| 297 | &Error); |
| 298 | if (!Error.empty()) { |
| 299 | assert(Res && "Error string set with 0 result code!"); |
| 300 | getDriver().Diag(clang::diag::err_drv_command_failure) << Error; |
| 301 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 302 | |
Daniel Dunbar | 31c11eb | 2009-07-01 19:14:39 +0000 | [diff] [blame] | 303 | if (Res) |
| 304 | FailingCommand = &C; |
| 305 | |
Daniel Dunbar | ceafbc8 | 2009-03-19 08:01:45 +0000 | [diff] [blame] | 306 | delete[] Argv; |
| 307 | return Res; |
| 308 | } |
| 309 | |
Chad Rosier | 4c4df45 | 2013-02-27 18:46:04 +0000 | [diff] [blame^] | 310 | typedef SmallVectorImpl< std::pair<int, const Command *> > FailingCommandList; |
| 311 | |
| 312 | static bool ActionFailed(const Action *A, |
| 313 | const FailingCommandList &FailingCommands) { |
| 314 | |
| 315 | if (FailingCommands.empty()) |
| 316 | return false; |
| 317 | |
| 318 | for (FailingCommandList::const_iterator CI = FailingCommands.begin(), |
| 319 | CE = FailingCommands.end(); CI != CE; ++CI) |
| 320 | if (A == &(CI->second->getSource())) |
| 321 | return true; |
| 322 | |
| 323 | for (Action::const_iterator AI = A->begin(), AE = A->end(); AI != AE; ++AI) |
| 324 | if (ActionFailed(*AI, FailingCommands)) |
| 325 | return true; |
| 326 | |
| 327 | return false; |
| 328 | } |
| 329 | |
| 330 | static bool InputsOk(const Command &C, |
| 331 | const FailingCommandList &FailingCommands) { |
| 332 | return !ActionFailed(&C.getSource(), FailingCommands); |
| 333 | } |
| 334 | |
Chad Rosier | a16355c | 2013-01-29 20:15:05 +0000 | [diff] [blame] | 335 | void Compilation::ExecuteJob(const Job &J, |
Chad Rosier | 4c4df45 | 2013-02-27 18:46:04 +0000 | [diff] [blame^] | 336 | FailingCommandList &FailingCommands) const { |
Daniel Dunbar | 49b98e7 | 2009-03-18 22:44:24 +0000 | [diff] [blame] | 337 | if (const Command *C = dyn_cast<Command>(&J)) { |
Chad Rosier | 4c4df45 | 2013-02-27 18:46:04 +0000 | [diff] [blame^] | 338 | if (!InputsOk(*C, FailingCommands)) |
| 339 | return; |
Chad Rosier | a16355c | 2013-01-29 20:15:05 +0000 | [diff] [blame] | 340 | const Command *FailingCommand = 0; |
| 341 | if (int Res = ExecuteCommand(*C, FailingCommand)) |
| 342 | FailingCommands.push_back(std::make_pair(Res, FailingCommand)); |
Daniel Dunbar | 49b98e7 | 2009-03-18 22:44:24 +0000 | [diff] [blame] | 343 | } else { |
| 344 | const JobList *Jobs = cast<JobList>(&J); |
Chad Rosier | a16355c | 2013-01-29 20:15:05 +0000 | [diff] [blame] | 345 | for (JobList::const_iterator it = Jobs->begin(), ie = Jobs->end(); |
| 346 | it != ie; ++it) |
| 347 | ExecuteJob(**it, FailingCommands); |
Daniel Dunbar | 49b98e7 | 2009-03-18 22:44:24 +0000 | [diff] [blame] | 348 | } |
| 349 | } |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 350 | |
Dmitri Gribenko | c4a7790 | 2012-11-15 14:28:07 +0000 | [diff] [blame] | 351 | void Compilation::initCompilationForDiagnostics() { |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 352 | // Free actions and jobs. |
| 353 | DeleteContainerPointers(Actions); |
| 354 | Jobs.clear(); |
| 355 | |
| 356 | // Clear temporary/results file lists. |
| 357 | TempFiles.clear(); |
| 358 | ResultFiles.clear(); |
Chad Rosier | 8425a54 | 2013-01-29 23:57:10 +0000 | [diff] [blame] | 359 | FailureResultFiles.clear(); |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 360 | |
| 361 | // Remove any user specified output. Claim any unclaimed arguments, so as |
| 362 | // to avoid emitting warnings about unused args. |
Peter Collingbourne | 54db68b | 2011-11-06 00:40:05 +0000 | [diff] [blame] | 363 | OptSpecifier OutputOpts[] = { options::OPT_o, options::OPT_MD, |
| 364 | options::OPT_MMD }; |
Chad Rosier | f9e156c | 2012-05-03 21:25:34 +0000 | [diff] [blame] | 365 | for (unsigned i = 0, e = llvm::array_lengthof(OutputOpts); i != e; ++i) { |
Peter Collingbourne | 54db68b | 2011-11-06 00:40:05 +0000 | [diff] [blame] | 366 | if (TranslatedArgs->hasArg(OutputOpts[i])) |
| 367 | TranslatedArgs->eraseArg(OutputOpts[i]); |
| 368 | } |
Chad Rosier | 2b81910 | 2011-08-02 17:58:04 +0000 | [diff] [blame] | 369 | TranslatedArgs->ClaimAllArgs(); |
| 370 | |
| 371 | // Redirect stdout/stderr to /dev/null. |
| 372 | Redirects = new const llvm::sys::Path*[3](); |
| 373 | Redirects[1] = new const llvm::sys::Path(); |
| 374 | Redirects[2] = new const llvm::sys::Path(); |
| 375 | } |
Sebastian Pop | 4762a2d | 2012-04-16 04:16:43 +0000 | [diff] [blame] | 376 | |
Dmitri Gribenko | c4a7790 | 2012-11-15 14:28:07 +0000 | [diff] [blame] | 377 | StringRef Compilation::getSysRoot() const { |
Sebastian Pop | 4762a2d | 2012-04-16 04:16:43 +0000 | [diff] [blame] | 378 | return getDriver().SysRoot; |
| 379 | } |