Index: clang-tidy/ClangTidy.h =================================================================== --- clang-tidy/ClangTidy.h +++ clang-tidy/ClangTidy.h @@ -16,6 +16,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceManager.h" #include "clang/Tooling/Refactoring.h" +#include "clang/Tooling/Tooling.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/raw_ostream.h" #include @@ -225,9 +226,7 @@ /// \param Profile if provided, it enables check profile collection in /// MatchFinder, and will contain the result of the profile. void runClangTidy(clang::tidy::ClangTidyContext &Context, - const tooling::CompilationDatabase &Compilations, - ArrayRef InputFiles, - llvm::IntrusiveRefCntPtr BaseFS, + clang::tooling::ClangTool &Tool, ProfileData *Profile = nullptr); // FIXME: This interface will need to be significantly extended to be useful. @@ -238,7 +237,7 @@ /// clang-format configuration file is found, the given \P FormatStyle is used. void handleErrors(ClangTidyContext &Context, bool Fix, unsigned &WarningsAsErrorsCount, - llvm::IntrusiveRefCntPtr BaseFS); + clang::tooling::ClangTool &Tool); /// \brief Serializes replacements into YAML and writes them to the specified /// output stream. Index: clang-tidy/ClangTidy.cpp =================================================================== --- clang-tidy/ClangTidy.cpp +++ clang-tidy/ClangTidy.cpp @@ -38,7 +38,6 @@ #include "clang/Tooling/DiagnosticsYaml.h" #include "clang/Tooling/Refactoring.h" #include "clang/Tooling/ReplacementsYaml.h" -#include "clang/Tooling/Tooling.h" #include "llvm/Support/Process.h" #include "llvm/Support/Signals.h" #include @@ -89,9 +88,9 @@ class ErrorReporter { public: - ErrorReporter(ClangTidyContext &Context, bool ApplyFixes, - llvm::IntrusiveRefCntPtr BaseFS) - : Files(FileSystemOptions(), BaseFS), DiagOpts(new DiagnosticOptions()), + ErrorReporter(ClangTidyContext &Context, bool ApplyFixes, ClangTool &Tool) + : Files(FileSystemOptions(), Tool.getFiles().getVirtualFileSystem()), + DiagOpts(new DiagnosticOptions()), DiagPrinter(new TextDiagnosticPrinter(llvm::outs(), &*DiagOpts)), Diags(IntrusiveRefCntPtr(new DiagnosticIDs), &*DiagOpts, DiagPrinter), @@ -474,13 +473,8 @@ } void runClangTidy(clang::tidy::ClangTidyContext &Context, - const CompilationDatabase &Compilations, - ArrayRef InputFiles, - llvm::IntrusiveRefCntPtr BaseFS, + ClangTool &Tool, ProfileData *Profile) { - ClangTool Tool(Compilations, InputFiles, - std::make_shared(), BaseFS); - // Add extra arguments passed by the clang-tidy command-line. ArgumentsAdjuster PerFileExtraArgumentsInserter = [&Context](const CommandLineArguments &Args, StringRef Filename) { @@ -551,8 +545,8 @@ void handleErrors(ClangTidyContext &Context, bool Fix, unsigned &WarningsAsErrorsCount, - llvm::IntrusiveRefCntPtr BaseFS) { - ErrorReporter Reporter(Context, Fix, BaseFS); + ClangTool &Tool) { + ErrorReporter Reporter(Context, Fix, Tool); vfs::FileSystem &FileSystem = *Reporter.getSourceManager().getFileManager().getVirtualFileSystem(); auto InitialWorkingDir = FileSystem.getCurrentWorkingDirectory(); Index: clang-tidy/tool/CMakeLists.txt =================================================================== --- clang-tidy/tool/CMakeLists.txt +++ clang-tidy/tool/CMakeLists.txt @@ -16,6 +16,7 @@ clangAST clangASTMatchers clangBasic + clangFrontend clangTidy clangTidyAndroidModule clangTidyAbseilModule Index: clang-tidy/tool/ClangTidyMain.cpp =================================================================== --- clang-tidy/tool/ClangTidyMain.cpp +++ clang-tidy/tool/ClangTidyMain.cpp @@ -339,10 +339,8 @@ llvm::IntrusiveRefCntPtr getVfsOverlayFromFile(const std::string &OverlayFile) { - llvm::IntrusiveRefCntPtr OverlayFS( - new vfs::OverlayFileSystem(vfs::getRealFileSystem())); llvm::ErrorOr> Buffer = - OverlayFS->getBufferForFile(OverlayFile); + vfs::getRealFileSystem()->getBufferForFile(OverlayFile); if (!Buffer) { llvm::errs() << "Can't load virtual filesystem overlay file '" << OverlayFile << "': " << Buffer.getError().message() @@ -357,8 +355,7 @@ << OverlayFile << "'.\n"; return nullptr; } - OverlayFS->pushOverlay(FS); - return OverlayFS; + return FS; } static int clangTidyMain(int argc, const char **argv) { @@ -432,10 +429,10 @@ llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); return 1; } - llvm::IntrusiveRefCntPtr BaseFS( - VfsOverlay.empty() ? vfs::getRealFileSystem() + llvm::IntrusiveRefCntPtr VirtualFileSystem( + VfsOverlay.empty() ? nullptr : getVfsOverlayFromFile(VfsOverlay)); - if (!BaseFS) + if (!VfsOverlay.empty() && !VirtualFileSystem) return 1; ProfileData Profile; @@ -445,8 +442,10 @@ llvm::InitializeAllAsmParsers(); ClangTidyContext Context(std::move(OwningOptionsProvider)); - runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS, - EnableCheckProfile ? &Profile : nullptr); + ClangTool Tool(OptionsParser.getCompilations(), PathList, + std::make_shared(), + vfs::createOverlayOnRealFilesystem(VirtualFileSystem)); + runClangTidy(Context, Tool, EnableCheckProfile ? &Profile : nullptr); ArrayRef Errors = Context.getErrors(); bool FoundErrors = std::find_if(Errors.begin(), Errors.end(), [](const ClangTidyError &E) { @@ -459,7 +458,7 @@ // -fix-errors implies -fix. handleErrors(Context, (FixErrors || Fix) && !DisableFixes, WErrorCount, - BaseFS); + Tool); if (!ExportFixes.empty() && !Errors.empty()) { std::error_code EC;