#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
#include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
#include "clang/Tooling/JSONCompilationDatabase.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/LLVMDriver.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ThreadPool.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/Timer.h"
#include "llvm/TargetParser/Host.h"
#include <mutex>
#include <optional>
#include <thread>
#include "Opts.inc"
usingnamespaceclang;
usingnamespacetooling::dependencies;
namespace {
usingnamespacellvm::opt;
enum ID { … };
#define PREFIX …
#include "Opts.inc"
#undef PREFIX
const llvm::opt::OptTable::Info InfoTable[] = …;
class ScanDepsOptTable : public llvm::opt::GenericOptTable { … };
enum ResourceDirRecipeKind { … };
static std::string OutputFileName = …;
static ScanningMode ScanMode = …;
static ScanningOutputFormat Format = …;
static ScanningOptimizations OptimizeArgs;
static std::string ModuleFilesDir;
static bool EagerLoadModules;
static unsigned NumThreads = …;
static std::string CompilationDB;
static std::string ModuleName;
static std::vector<std::string> ModuleDepTargets;
static bool DeprecatedDriverCommand;
static ResourceDirRecipeKind ResourceDirRecipe;
static bool Verbose;
static bool PrintTiming;
static llvm::BumpPtrAllocator Alloc;
static llvm::StringSaver Saver{ … };
static std::vector<const char *> CommandLine;
#ifndef NDEBUG
static constexpr bool DoRoundTripDefault = true;
#else
static constexpr bool DoRoundTripDefault = …;
#endif
static bool RoundTripArgs = …;
static void ParseArgs(int argc, char **argv) { … }
class SharedStream { … };
class ResourceDirectoryCache { … };
}
static bool
handleMakeDependencyToolResult(const std::string &Input,
llvm::Expected<std::string> &MaybeFile,
SharedStream &OS, SharedStream &Errs) { … }
template <typename Container>
static auto toJSONStrings(llvm::json::OStream &JOS, Container &&Strings) { … }
static auto toJSONSorted(llvm::json::OStream &JOS,
const llvm::StringSet<> &Set) { … }
static auto toJSONSorted(llvm::json::OStream &JOS, std::vector<ModuleID> V) { … }
static auto toJSONSorted(llvm::json::OStream &JOS,
SmallVector<Module::LinkLibrary, 2> LinkLibs) { … }
class FullDeps { … };
static bool handleTranslationUnitResult(
StringRef Input, llvm::Expected<TranslationUnitDeps> &MaybeTUDeps,
FullDeps &FD, size_t InputIndex, SharedStream &OS, SharedStream &Errs) { … }
static bool handleModuleResult(
StringRef ModuleName, llvm::Expected<ModuleDepsGraph> &MaybeModuleGraph,
FullDeps &FD, size_t InputIndex, SharedStream &OS, SharedStream &Errs) { … }
class P1689Deps { … };
static bool
handleP1689DependencyToolResult(const std::string &Input,
llvm::Expected<P1689Rule> &MaybeRule,
P1689Deps &PD, SharedStream &Errs) { … }
static std::string constructPCMPath(ModuleID MID, StringRef OutputDir) { … }
static std::string lookupModuleOutput(const ModuleID &MID, ModuleOutputKind MOK,
StringRef OutputDir) { … }
static std::string getModuleCachePath(ArrayRef<std::string> Args) { … }
static std::unique_ptr<tooling::CompilationDatabase>
getCompilationDatabase(int argc, char **argv, std::string &ErrorMessage) { … }
int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) { … }