static void ExecuteTemplightCommand(Driver &TheDriver, DiagnosticsEngine &Diags, Compilation &C, Command &J, const char* Argv0, SmallVector<std::pair<int, const Command *>, 4>& FailingCommands) { // Since commandLineFitsWithinSystemLimits() may underestimate system's capacity // if the tool does not support response files, there is a chance/ that things // will just work without a response file, so we silently just skip it. if ( J.getCreator().getResponseFilesSupport() != Tool::RF_None && llvm::sys::commandLineFitsWithinSystemLimits( StringRef(J.getCreator().getName()), J.getArguments()) ) { std::string TmpName = TheDriver.GetTemporaryPath("response", "txt"); J.setResponseFile(C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()))); } if ( StringRef(J.getCreator().getName()) == "clang" ) { // Initialize a compiler invocation object from the clang (-cc1) arguments. const ArgStringList &cc_arguments = J.getArguments(); const char** args_start = const_cast<const char**>(cc_arguments.data()); const char** args_end = args_start + cc_arguments.size(); std::unique_ptr<CompilerInstance> Clang(new CompilerInstance()); int Res = !CompilerInvocation::CreateFromArgs( Clang->getInvocation(), args_start, args_end, Diags); if(Res) FailingCommands.push_back(std::make_pair(Res, &J)); Clang->getFrontendOpts().DisableFree = false; // Infer the builtin include path if unspecified. void *GetExecutablePathVP = (void *)(intptr_t) GetExecutablePath; if (Clang->getHeaderSearchOpts().UseBuiltinIncludes && Clang->getHeaderSearchOpts().ResourceDir.empty()) Clang->getHeaderSearchOpts().ResourceDir = CompilerInvocation::GetResourcesPath(Argv0, GetExecutablePathVP); // Create the compilers actual diagnostics engine. Clang->createDiagnostics(); if (!Clang->hasDiagnostics()) { FailingCommands.push_back(std::make_pair(1, &J)); return; } LocalOutputFilename = ""; // Let the filename be created from options or output file name. std::string TemplightOutFile = TemplightAction::CreateOutputFilename( Clang.get(), "", InstProfiler, OutputToStdOut, MemoryProfile); // Check if templight filename is in a temporary path: llvm::SmallString<128> TDir; llvm::sys::path::system_temp_directory(true, TDir); if ( TDir.equals(llvm::sys::path::parent_path(llvm::StringRef(TemplightOutFile))) ) { C.addTempFile(TemplightOutFile.c_str()); TempOutputFiles.push_back(TemplightOutFile); } // Execute the frontend actions. Res = ExecuteTemplightInvocation(Clang.get()); if(Res) FailingCommands.push_back(std::make_pair(Res, &J)); } else { const Command *FailingCommand = nullptr; if (int Res = C.ExecuteCommand(J, FailingCommand)) FailingCommands.push_back(std::make_pair(Res, FailingCommand)); } }