Home | History | Annotate | Line # | Download | only in Driver
      1      1.1  joerg //===- Job.cpp - Command to Execute ---------------------------------------===//
      2      1.1  joerg //
      3      1.1  joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      4      1.1  joerg // See https://llvm.org/LICENSE.txt for license information.
      5      1.1  joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      6      1.1  joerg //
      7      1.1  joerg //===----------------------------------------------------------------------===//
      8      1.1  joerg 
      9      1.1  joerg #include "clang/Driver/Job.h"
     10      1.1  joerg #include "InputInfo.h"
     11      1.1  joerg #include "clang/Basic/LLVM.h"
     12      1.1  joerg #include "clang/Driver/Driver.h"
     13      1.1  joerg #include "clang/Driver/DriverDiagnostic.h"
     14      1.1  joerg #include "clang/Driver/Tool.h"
     15      1.1  joerg #include "clang/Driver/ToolChain.h"
     16      1.1  joerg #include "llvm/ADT/ArrayRef.h"
     17      1.1  joerg #include "llvm/ADT/SmallString.h"
     18      1.1  joerg #include "llvm/ADT/SmallVector.h"
     19      1.1  joerg #include "llvm/ADT/StringRef.h"
     20      1.1  joerg #include "llvm/ADT/StringSet.h"
     21      1.1  joerg #include "llvm/ADT/StringSwitch.h"
     22  1.1.1.2  joerg #include "llvm/Support/CrashRecoveryContext.h"
     23      1.1  joerg #include "llvm/Support/FileSystem.h"
     24      1.1  joerg #include "llvm/Support/Path.h"
     25  1.1.1.2  joerg #include "llvm/Support/PrettyStackTrace.h"
     26      1.1  joerg #include "llvm/Support/Program.h"
     27      1.1  joerg #include "llvm/Support/raw_ostream.h"
     28      1.1  joerg #include <algorithm>
     29      1.1  joerg #include <cassert>
     30      1.1  joerg #include <cstddef>
     31      1.1  joerg #include <string>
     32      1.1  joerg #include <system_error>
     33      1.1  joerg #include <utility>
     34      1.1  joerg 
     35      1.1  joerg using namespace clang;
     36      1.1  joerg using namespace driver;
     37      1.1  joerg 
     38      1.1  joerg Command::Command(const Action &Source, const Tool &Creator,
     39  1.1.1.2  joerg                  ResponseFileSupport ResponseSupport, const char *Executable,
     40      1.1  joerg                  const llvm::opt::ArgStringList &Arguments,
     41  1.1.1.2  joerg                  ArrayRef<InputInfo> Inputs, ArrayRef<InputInfo> Outputs)
     42  1.1.1.2  joerg     : Source(Source), Creator(Creator), ResponseSupport(ResponseSupport),
     43  1.1.1.2  joerg       Executable(Executable), Arguments(Arguments) {
     44      1.1  joerg   for (const auto &II : Inputs)
     45      1.1  joerg     if (II.isFilename())
     46      1.1  joerg       InputFilenames.push_back(II.getFilename());
     47  1.1.1.2  joerg   for (const auto &II : Outputs)
     48  1.1.1.2  joerg     if (II.isFilename())
     49  1.1.1.2  joerg       OutputFilenames.push_back(II.getFilename());
     50      1.1  joerg }
     51      1.1  joerg 
     52      1.1  joerg /// Check if the compiler flag in question should be skipped when
     53      1.1  joerg /// emitting a reproducer. Also track how many arguments it has and if the
     54      1.1  joerg /// option is some kind of include path.
     55      1.1  joerg static bool skipArgs(const char *Flag, bool HaveCrashVFS, int &SkipNum,
     56      1.1  joerg                      bool &IsInclude) {
     57      1.1  joerg   SkipNum = 2;
     58      1.1  joerg   // These flags are all of the form -Flag <Arg> and are treated as two
     59      1.1  joerg   // arguments.  Therefore, we need to skip the flag and the next argument.
     60      1.1  joerg   bool ShouldSkip = llvm::StringSwitch<bool>(Flag)
     61      1.1  joerg     .Cases("-MF", "-MT", "-MQ", "-serialize-diagnostic-file", true)
     62      1.1  joerg     .Cases("-o", "-dependency-file", true)
     63      1.1  joerg     .Cases("-fdebug-compilation-dir", "-diagnostic-log-file", true)
     64      1.1  joerg     .Cases("-dwarf-debug-flags", "-ivfsoverlay", true)
     65      1.1  joerg     .Default(false);
     66      1.1  joerg   if (ShouldSkip)
     67      1.1  joerg     return true;
     68      1.1  joerg 
     69      1.1  joerg   // Some include flags shouldn't be skipped if we have a crash VFS
     70      1.1  joerg   IsInclude = llvm::StringSwitch<bool>(Flag)
     71      1.1  joerg     .Cases("-include", "-header-include-file", true)
     72      1.1  joerg     .Cases("-idirafter", "-internal-isystem", "-iwithprefix", true)
     73      1.1  joerg     .Cases("-internal-externc-isystem", "-iprefix", true)
     74      1.1  joerg     .Cases("-iwithprefixbefore", "-isystem", "-iquote", true)
     75      1.1  joerg     .Cases("-isysroot", "-I", "-F", "-resource-dir", true)
     76      1.1  joerg     .Cases("-iframework", "-include-pch", true)
     77      1.1  joerg     .Default(false);
     78      1.1  joerg   if (IsInclude)
     79      1.1  joerg     return !HaveCrashVFS;
     80      1.1  joerg 
     81      1.1  joerg   // The remaining flags are treated as a single argument.
     82      1.1  joerg 
     83      1.1  joerg   // These flags are all of the form -Flag and have no second argument.
     84      1.1  joerg   ShouldSkip = llvm::StringSwitch<bool>(Flag)
     85      1.1  joerg     .Cases("-M", "-MM", "-MG", "-MP", "-MD", true)
     86      1.1  joerg     .Case("-MMD", true)
     87      1.1  joerg     .Default(false);
     88      1.1  joerg 
     89      1.1  joerg   // Match found.
     90      1.1  joerg   SkipNum = 1;
     91      1.1  joerg   if (ShouldSkip)
     92      1.1  joerg     return true;
     93      1.1  joerg 
     94      1.1  joerg   // These flags are treated as a single argument (e.g., -F<Dir>).
     95      1.1  joerg   StringRef FlagRef(Flag);
     96      1.1  joerg   IsInclude = FlagRef.startswith("-F") || FlagRef.startswith("-I");
     97      1.1  joerg   if (IsInclude)
     98      1.1  joerg     return !HaveCrashVFS;
     99      1.1  joerg   if (FlagRef.startswith("-fmodules-cache-path="))
    100      1.1  joerg     return true;
    101      1.1  joerg 
    102      1.1  joerg   SkipNum = 0;
    103      1.1  joerg   return false;
    104      1.1  joerg }
    105      1.1  joerg 
    106      1.1  joerg void Command::writeResponseFile(raw_ostream &OS) const {
    107      1.1  joerg   // In a file list, we only write the set of inputs to the response file
    108  1.1.1.2  joerg   if (ResponseSupport.ResponseKind == ResponseFileSupport::RF_FileList) {
    109      1.1  joerg     for (const auto *Arg : InputFileList) {
    110      1.1  joerg       OS << Arg << '\n';
    111      1.1  joerg     }
    112      1.1  joerg     return;
    113      1.1  joerg   }
    114      1.1  joerg 
    115      1.1  joerg   // In regular response files, we send all arguments to the response file.
    116      1.1  joerg   // Wrapping all arguments in double quotes ensures that both Unix tools and
    117      1.1  joerg   // Windows tools understand the response file.
    118      1.1  joerg   for (const auto *Arg : Arguments) {
    119      1.1  joerg     OS << '"';
    120      1.1  joerg 
    121      1.1  joerg     for (; *Arg != '\0'; Arg++) {
    122      1.1  joerg       if (*Arg == '\"' || *Arg == '\\') {
    123      1.1  joerg         OS << '\\';
    124      1.1  joerg       }
    125      1.1  joerg       OS << *Arg;
    126      1.1  joerg     }
    127      1.1  joerg 
    128      1.1  joerg     OS << "\" ";
    129      1.1  joerg   }
    130      1.1  joerg }
    131      1.1  joerg 
    132      1.1  joerg void Command::buildArgvForResponseFile(
    133      1.1  joerg     llvm::SmallVectorImpl<const char *> &Out) const {
    134      1.1  joerg   // When not a file list, all arguments are sent to the response file.
    135      1.1  joerg   // This leaves us to set the argv to a single parameter, requesting the tool
    136      1.1  joerg   // to read the response file.
    137  1.1.1.2  joerg   if (ResponseSupport.ResponseKind != ResponseFileSupport::RF_FileList) {
    138      1.1  joerg     Out.push_back(Executable);
    139      1.1  joerg     Out.push_back(ResponseFileFlag.c_str());
    140      1.1  joerg     return;
    141      1.1  joerg   }
    142      1.1  joerg 
    143      1.1  joerg   llvm::StringSet<> Inputs;
    144      1.1  joerg   for (const auto *InputName : InputFileList)
    145      1.1  joerg     Inputs.insert(InputName);
    146      1.1  joerg   Out.push_back(Executable);
    147      1.1  joerg   // In a file list, build args vector ignoring parameters that will go in the
    148      1.1  joerg   // response file (elements of the InputFileList vector)
    149      1.1  joerg   bool FirstInput = true;
    150      1.1  joerg   for (const auto *Arg : Arguments) {
    151      1.1  joerg     if (Inputs.count(Arg) == 0) {
    152      1.1  joerg       Out.push_back(Arg);
    153      1.1  joerg     } else if (FirstInput) {
    154      1.1  joerg       FirstInput = false;
    155  1.1.1.2  joerg       Out.push_back(ResponseSupport.ResponseFlag);
    156      1.1  joerg       Out.push_back(ResponseFile);
    157      1.1  joerg     }
    158      1.1  joerg   }
    159      1.1  joerg }
    160      1.1  joerg 
    161      1.1  joerg /// Rewrite relative include-like flag paths to absolute ones.
    162      1.1  joerg static void
    163      1.1  joerg rewriteIncludes(const llvm::ArrayRef<const char *> &Args, size_t Idx,
    164      1.1  joerg                 size_t NumArgs,
    165      1.1  joerg                 llvm::SmallVectorImpl<llvm::SmallString<128>> &IncFlags) {
    166      1.1  joerg   using namespace llvm;
    167      1.1  joerg   using namespace sys;
    168      1.1  joerg 
    169      1.1  joerg   auto getAbsPath = [](StringRef InInc, SmallVectorImpl<char> &OutInc) -> bool {
    170      1.1  joerg     if (path::is_absolute(InInc)) // Nothing to do here...
    171      1.1  joerg       return false;
    172      1.1  joerg     std::error_code EC = fs::current_path(OutInc);
    173      1.1  joerg     if (EC)
    174      1.1  joerg       return false;
    175      1.1  joerg     path::append(OutInc, InInc);
    176      1.1  joerg     return true;
    177      1.1  joerg   };
    178      1.1  joerg 
    179      1.1  joerg   SmallString<128> NewInc;
    180      1.1  joerg   if (NumArgs == 1) {
    181      1.1  joerg     StringRef FlagRef(Args[Idx + NumArgs - 1]);
    182      1.1  joerg     assert((FlagRef.startswith("-F") || FlagRef.startswith("-I")) &&
    183      1.1  joerg             "Expecting -I or -F");
    184      1.1  joerg     StringRef Inc = FlagRef.slice(2, StringRef::npos);
    185      1.1  joerg     if (getAbsPath(Inc, NewInc)) {
    186      1.1  joerg       SmallString<128> NewArg(FlagRef.slice(0, 2));
    187      1.1  joerg       NewArg += NewInc;
    188      1.1  joerg       IncFlags.push_back(std::move(NewArg));
    189      1.1  joerg     }
    190      1.1  joerg     return;
    191      1.1  joerg   }
    192      1.1  joerg 
    193      1.1  joerg   assert(NumArgs == 2 && "Not expecting more than two arguments");
    194      1.1  joerg   StringRef Inc(Args[Idx + NumArgs - 1]);
    195      1.1  joerg   if (!getAbsPath(Inc, NewInc))
    196      1.1  joerg     return;
    197      1.1  joerg   IncFlags.push_back(SmallString<128>(Args[Idx]));
    198      1.1  joerg   IncFlags.push_back(std::move(NewInc));
    199      1.1  joerg }
    200      1.1  joerg 
    201      1.1  joerg void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
    202      1.1  joerg                     CrashReportInfo *CrashInfo) const {
    203      1.1  joerg   // Always quote the exe.
    204      1.1  joerg   OS << ' ';
    205  1.1.1.2  joerg   llvm::sys::printArg(OS, Executable, /*Quote=*/true);
    206      1.1  joerg 
    207      1.1  joerg   ArrayRef<const char *> Args = Arguments;
    208      1.1  joerg   SmallVector<const char *, 128> ArgsRespFile;
    209      1.1  joerg   if (ResponseFile != nullptr) {
    210      1.1  joerg     buildArgvForResponseFile(ArgsRespFile);
    211      1.1  joerg     Args = ArrayRef<const char *>(ArgsRespFile).slice(1); // no executable name
    212      1.1  joerg   }
    213      1.1  joerg 
    214      1.1  joerg   bool HaveCrashVFS = CrashInfo && !CrashInfo->VFSPath.empty();
    215      1.1  joerg   for (size_t i = 0, e = Args.size(); i < e; ++i) {
    216      1.1  joerg     const char *const Arg = Args[i];
    217      1.1  joerg 
    218      1.1  joerg     if (CrashInfo) {
    219      1.1  joerg       int NumArgs = 0;
    220      1.1  joerg       bool IsInclude = false;
    221      1.1  joerg       if (skipArgs(Arg, HaveCrashVFS, NumArgs, IsInclude)) {
    222      1.1  joerg         i += NumArgs - 1;
    223      1.1  joerg         continue;
    224      1.1  joerg       }
    225      1.1  joerg 
    226      1.1  joerg       // Relative includes need to be expanded to absolute paths.
    227      1.1  joerg       if (HaveCrashVFS && IsInclude) {
    228      1.1  joerg         SmallVector<SmallString<128>, 2> NewIncFlags;
    229      1.1  joerg         rewriteIncludes(Args, i, NumArgs, NewIncFlags);
    230      1.1  joerg         if (!NewIncFlags.empty()) {
    231      1.1  joerg           for (auto &F : NewIncFlags) {
    232      1.1  joerg             OS << ' ';
    233  1.1.1.2  joerg             llvm::sys::printArg(OS, F.c_str(), Quote);
    234      1.1  joerg           }
    235      1.1  joerg           i += NumArgs - 1;
    236      1.1  joerg           continue;
    237      1.1  joerg         }
    238      1.1  joerg       }
    239      1.1  joerg 
    240      1.1  joerg       auto Found = llvm::find_if(InputFilenames,
    241      1.1  joerg                                  [&Arg](StringRef IF) { return IF == Arg; });
    242      1.1  joerg       if (Found != InputFilenames.end() &&
    243      1.1  joerg           (i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
    244      1.1  joerg         // Replace the input file name with the crashinfo's file name.
    245      1.1  joerg         OS << ' ';
    246      1.1  joerg         StringRef ShortName = llvm::sys::path::filename(CrashInfo->Filename);
    247  1.1.1.2  joerg         llvm::sys::printArg(OS, ShortName.str(), Quote);
    248      1.1  joerg         continue;
    249      1.1  joerg       }
    250      1.1  joerg     }
    251      1.1  joerg 
    252      1.1  joerg     OS << ' ';
    253  1.1.1.2  joerg     llvm::sys::printArg(OS, Arg, Quote);
    254      1.1  joerg   }
    255      1.1  joerg 
    256      1.1  joerg   if (CrashInfo && HaveCrashVFS) {
    257      1.1  joerg     OS << ' ';
    258  1.1.1.2  joerg     llvm::sys::printArg(OS, "-ivfsoverlay", Quote);
    259      1.1  joerg     OS << ' ';
    260  1.1.1.2  joerg     llvm::sys::printArg(OS, CrashInfo->VFSPath.str(), Quote);
    261      1.1  joerg 
    262      1.1  joerg     // The leftover modules from the crash are stored in
    263      1.1  joerg     //  <name>.cache/vfs/modules
    264      1.1  joerg     // Leave it untouched for pcm inspection and provide a clean/empty dir
    265      1.1  joerg     // path to contain the future generated module cache:
    266      1.1  joerg     //  <name>.cache/vfs/repro-modules
    267      1.1  joerg     SmallString<128> RelModCacheDir = llvm::sys::path::parent_path(
    268      1.1  joerg         llvm::sys::path::parent_path(CrashInfo->VFSPath));
    269      1.1  joerg     llvm::sys::path::append(RelModCacheDir, "repro-modules");
    270      1.1  joerg 
    271      1.1  joerg     std::string ModCachePath = "-fmodules-cache-path=";
    272      1.1  joerg     ModCachePath.append(RelModCacheDir.c_str());
    273      1.1  joerg 
    274      1.1  joerg     OS << ' ';
    275  1.1.1.2  joerg     llvm::sys::printArg(OS, ModCachePath, Quote);
    276      1.1  joerg   }
    277      1.1  joerg 
    278      1.1  joerg   if (ResponseFile != nullptr) {
    279      1.1  joerg     OS << "\n Arguments passed via response file:\n";
    280      1.1  joerg     writeResponseFile(OS);
    281      1.1  joerg     // Avoiding duplicated newline terminator, since FileLists are
    282      1.1  joerg     // newline-separated.
    283  1.1.1.2  joerg     if (ResponseSupport.ResponseKind != ResponseFileSupport::RF_FileList)
    284      1.1  joerg       OS << "\n";
    285      1.1  joerg     OS << " (end of response file)";
    286      1.1  joerg   }
    287      1.1  joerg 
    288      1.1  joerg   OS << Terminator;
    289      1.1  joerg }
    290      1.1  joerg 
    291      1.1  joerg void Command::setResponseFile(const char *FileName) {
    292      1.1  joerg   ResponseFile = FileName;
    293  1.1.1.2  joerg   ResponseFileFlag = ResponseSupport.ResponseFlag;
    294      1.1  joerg   ResponseFileFlag += FileName;
    295      1.1  joerg }
    296      1.1  joerg 
    297      1.1  joerg void Command::setEnvironment(llvm::ArrayRef<const char *> NewEnvironment) {
    298      1.1  joerg   Environment.reserve(NewEnvironment.size() + 1);
    299      1.1  joerg   Environment.assign(NewEnvironment.begin(), NewEnvironment.end());
    300      1.1  joerg   Environment.push_back(nullptr);
    301      1.1  joerg }
    302      1.1  joerg 
    303  1.1.1.2  joerg void Command::PrintFileNames() const {
    304      1.1  joerg   if (PrintInputFilenames) {
    305      1.1  joerg     for (const char *Arg : InputFilenames)
    306      1.1  joerg       llvm::outs() << llvm::sys::path::filename(Arg) << "\n";
    307      1.1  joerg     llvm::outs().flush();
    308      1.1  joerg   }
    309  1.1.1.2  joerg }
    310      1.1  joerg 
    311  1.1.1.2  joerg int Command::Execute(ArrayRef<llvm::Optional<StringRef>> Redirects,
    312  1.1.1.2  joerg                      std::string *ErrMsg, bool *ExecutionFailed) const {
    313  1.1.1.2  joerg   PrintFileNames();
    314      1.1  joerg 
    315  1.1.1.2  joerg   SmallVector<const char *, 128> Argv;
    316      1.1  joerg   if (ResponseFile == nullptr) {
    317      1.1  joerg     Argv.push_back(Executable);
    318      1.1  joerg     Argv.append(Arguments.begin(), Arguments.end());
    319      1.1  joerg     Argv.push_back(nullptr);
    320  1.1.1.2  joerg   } else {
    321  1.1.1.2  joerg     // If the command is too large, we need to put arguments in a response file.
    322  1.1.1.2  joerg     std::string RespContents;
    323  1.1.1.2  joerg     llvm::raw_string_ostream SS(RespContents);
    324  1.1.1.2  joerg 
    325  1.1.1.2  joerg     // Write file contents and build the Argv vector
    326  1.1.1.2  joerg     writeResponseFile(SS);
    327  1.1.1.2  joerg     buildArgvForResponseFile(Argv);
    328  1.1.1.2  joerg     Argv.push_back(nullptr);
    329  1.1.1.2  joerg     SS.flush();
    330      1.1  joerg 
    331  1.1.1.2  joerg     // Save the response file in the appropriate encoding
    332  1.1.1.2  joerg     if (std::error_code EC = writeFileWithEncoding(
    333  1.1.1.2  joerg             ResponseFile, RespContents, ResponseSupport.ResponseEncoding)) {
    334  1.1.1.2  joerg       if (ErrMsg)
    335  1.1.1.2  joerg         *ErrMsg = EC.message();
    336  1.1.1.2  joerg       if (ExecutionFailed)
    337  1.1.1.2  joerg         *ExecutionFailed = true;
    338  1.1.1.2  joerg       // Return -1 by convention (see llvm/include/llvm/Support/Program.h) to
    339  1.1.1.2  joerg       // indicate the requested executable cannot be started.
    340  1.1.1.2  joerg       return -1;
    341  1.1.1.2  joerg     }
    342      1.1  joerg   }
    343      1.1  joerg 
    344  1.1.1.2  joerg   Optional<ArrayRef<StringRef>> Env;
    345  1.1.1.2  joerg   std::vector<StringRef> ArgvVectorStorage;
    346  1.1.1.2  joerg   if (!Environment.empty()) {
    347  1.1.1.2  joerg     assert(Environment.back() == nullptr &&
    348  1.1.1.2  joerg            "Environment vector should be null-terminated by now");
    349  1.1.1.2  joerg     ArgvVectorStorage = llvm::toStringRefArray(Environment.data());
    350  1.1.1.2  joerg     Env = makeArrayRef(ArgvVectorStorage);
    351      1.1  joerg   }
    352      1.1  joerg 
    353      1.1  joerg   auto Args = llvm::toStringRefArray(Argv.data());
    354      1.1  joerg   return llvm::sys::ExecuteAndWait(Executable, Args, Env, Redirects,
    355  1.1.1.2  joerg                                    /*secondsToWait*/ 0, /*memoryLimit*/ 0,
    356  1.1.1.2  joerg                                    ErrMsg, ExecutionFailed, &ProcStat);
    357      1.1  joerg }
    358      1.1  joerg 
    359  1.1.1.2  joerg CC1Command::CC1Command(const Action &Source, const Tool &Creator,
    360  1.1.1.2  joerg                        ResponseFileSupport ResponseSupport,
    361  1.1.1.2  joerg                        const char *Executable,
    362  1.1.1.2  joerg                        const llvm::opt::ArgStringList &Arguments,
    363  1.1.1.2  joerg                        ArrayRef<InputInfo> Inputs, ArrayRef<InputInfo> Outputs)
    364  1.1.1.2  joerg     : Command(Source, Creator, ResponseSupport, Executable, Arguments, Inputs,
    365  1.1.1.2  joerg               Outputs) {
    366  1.1.1.2  joerg   InProcess = true;
    367  1.1.1.2  joerg }
    368  1.1.1.2  joerg 
    369  1.1.1.2  joerg void CC1Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
    370  1.1.1.2  joerg                        CrashReportInfo *CrashInfo) const {
    371  1.1.1.2  joerg   if (InProcess)
    372  1.1.1.2  joerg     OS << " (in-process)\n";
    373  1.1.1.2  joerg   Command::Print(OS, Terminator, Quote, CrashInfo);
    374  1.1.1.2  joerg }
    375  1.1.1.2  joerg 
    376  1.1.1.2  joerg int CC1Command::Execute(ArrayRef<llvm::Optional<StringRef>> Redirects,
    377  1.1.1.2  joerg                         std::string *ErrMsg, bool *ExecutionFailed) const {
    378  1.1.1.2  joerg   // FIXME: Currently, if there're more than one job, we disable
    379  1.1.1.2  joerg   // -fintegrate-cc1. If we're no longer a integrated-cc1 job, fallback to
    380  1.1.1.2  joerg   // out-of-process execution. See discussion in https://reviews.llvm.org/D74447
    381  1.1.1.2  joerg   if (!InProcess)
    382  1.1.1.2  joerg     return Command::Execute(Redirects, ErrMsg, ExecutionFailed);
    383  1.1.1.2  joerg 
    384  1.1.1.2  joerg   PrintFileNames();
    385  1.1.1.2  joerg 
    386  1.1.1.2  joerg   SmallVector<const char *, 128> Argv;
    387  1.1.1.2  joerg   Argv.push_back(getExecutable());
    388  1.1.1.2  joerg   Argv.append(getArguments().begin(), getArguments().end());
    389  1.1.1.2  joerg   Argv.push_back(nullptr);
    390      1.1  joerg 
    391  1.1.1.2  joerg   // This flag simply indicates that the program couldn't start, which isn't
    392  1.1.1.2  joerg   // applicable here.
    393      1.1  joerg   if (ExecutionFailed)
    394      1.1  joerg     *ExecutionFailed = false;
    395      1.1  joerg 
    396  1.1.1.2  joerg   llvm::CrashRecoveryContext CRC;
    397  1.1.1.2  joerg   CRC.DumpStackAndCleanupOnFailure = true;
    398  1.1.1.2  joerg 
    399  1.1.1.2  joerg   const void *PrettyState = llvm::SavePrettyStackState();
    400      1.1  joerg   const Driver &D = getCreator().getToolChain().getDriver();
    401      1.1  joerg 
    402  1.1.1.2  joerg   int R = 0;
    403  1.1.1.2  joerg   // Enter ExecuteCC1Tool() instead of starting up a new process
    404  1.1.1.2  joerg   if (!CRC.RunSafely([&]() { R = D.CC1Main(Argv); })) {
    405  1.1.1.2  joerg     llvm::RestorePrettyStackState(PrettyState);
    406  1.1.1.2  joerg     return CRC.RetCode;
    407  1.1.1.2  joerg   }
    408  1.1.1.2  joerg   return R;
    409  1.1.1.2  joerg }
    410  1.1.1.2  joerg 
    411  1.1.1.2  joerg void CC1Command::setEnvironment(llvm::ArrayRef<const char *> NewEnvironment) {
    412  1.1.1.2  joerg   // We don't support set a new environment when calling into ExecuteCC1Tool()
    413  1.1.1.2  joerg   llvm_unreachable(
    414  1.1.1.2  joerg       "The CC1Command doesn't support changing the environment vars!");
    415      1.1  joerg }
    416      1.1  joerg 
    417      1.1  joerg ForceSuccessCommand::ForceSuccessCommand(
    418  1.1.1.2  joerg     const Action &Source_, const Tool &Creator_,
    419  1.1.1.2  joerg     ResponseFileSupport ResponseSupport, const char *Executable_,
    420  1.1.1.2  joerg     const llvm::opt::ArgStringList &Arguments_, ArrayRef<InputInfo> Inputs,
    421  1.1.1.2  joerg     ArrayRef<InputInfo> Outputs)
    422  1.1.1.2  joerg     : Command(Source_, Creator_, ResponseSupport, Executable_, Arguments_,
    423  1.1.1.2  joerg               Inputs, Outputs) {}
    424      1.1  joerg 
    425      1.1  joerg void ForceSuccessCommand::Print(raw_ostream &OS, const char *Terminator,
    426      1.1  joerg                             bool Quote, CrashReportInfo *CrashInfo) const {
    427      1.1  joerg   Command::Print(OS, "", Quote, CrashInfo);
    428      1.1  joerg   OS << " || (exit 0)" << Terminator;
    429      1.1  joerg }
    430      1.1  joerg 
    431      1.1  joerg int ForceSuccessCommand::Execute(ArrayRef<llvm::Optional<StringRef>> Redirects,
    432      1.1  joerg                                  std::string *ErrMsg,
    433      1.1  joerg                                  bool *ExecutionFailed) const {
    434      1.1  joerg   int Status = Command::Execute(Redirects, ErrMsg, ExecutionFailed);
    435      1.1  joerg   (void)Status;
    436      1.1  joerg   if (ExecutionFailed)
    437      1.1  joerg     *ExecutionFailed = false;
    438      1.1  joerg   return 0;
    439      1.1  joerg }
    440      1.1  joerg 
    441      1.1  joerg void JobList::Print(raw_ostream &OS, const char *Terminator, bool Quote,
    442      1.1  joerg                     CrashReportInfo *CrashInfo) const {
    443      1.1  joerg   for (const auto &Job : *this)
    444      1.1  joerg     Job.Print(OS, Terminator, Quote, CrashInfo);
    445      1.1  joerg }
    446      1.1  joerg 
    447      1.1  joerg void JobList::clear() { Jobs.clear(); }
    448