Index: include/clang/Tooling/AllTUsExecution.h =================================================================== --- include/clang/Tooling/AllTUsExecution.h +++ include/clang/Tooling/AllTUsExecution.h @@ -30,8 +30,11 @@ /// Init with \p CompilationDatabase. /// This uses \p ThreadCount threads to exececute the actions on all files in /// parallel. If \p ThreadCount is 0, this uses `llvm::hardware_concurrency`. + /// Only processes files in \p Files. However, if \p Files is empty, will + /// process all the files in the compilation database. AllTUsToolExecutor(const CompilationDatabase &Compilations, unsigned ThreadCount, + std::vector Files = {}, std::shared_ptr PCHContainerOps = std::make_shared()); @@ -66,6 +69,9 @@ // Used to store the parser when the executor is initialized with parser. llvm::Optional OptionsParser; const CompilationDatabase &Compilations; + /// A list of files executor should run on. When empty, runs over all the + /// files in the compilation database. + std::vector Files; std::unique_ptr Results; ExecutionContext Context; llvm::StringMap OverlayFiles; Index: lib/Tooling/AllTUsExecution.cpp =================================================================== --- lib/Tooling/AllTUsExecution.cpp +++ lib/Tooling/AllTUsExecution.cpp @@ -55,15 +55,18 @@ AllTUsToolExecutor::AllTUsToolExecutor( const CompilationDatabase &Compilations, unsigned ThreadCount, + std::vector Files, std::shared_ptr PCHContainerOps) - : Compilations(Compilations), Results(new ThreadSafeToolResults), - Context(Results.get()), ThreadCount(ThreadCount) {} + : Compilations(Compilations), Files(std::move(Files)), + Results(new ThreadSafeToolResults), Context(Results.get()), + ThreadCount(ThreadCount) {} AllTUsToolExecutor::AllTUsToolExecutor( CommonOptionsParser Options, unsigned ThreadCount, std::shared_ptr PCHContainerOps) : OptionsParser(std::move(Options)), Compilations(OptionsParser->getCompilations()), + Files(OptionsParser->getSourcePathList()), Results(new ThreadSafeToolResults), Context(Results.get()), ThreadCount(ThreadCount) {} @@ -90,7 +93,8 @@ llvm::errs() << Msg.str() << "\n"; }; - auto Files = Compilations.getAllFiles(); + std::vector Files = + !this->Files.empty() ? this->Files : Compilations.getAllFiles(); // Add a counter to track the progress. const std::string TotalNumStr = std::to_string(Files.size()); unsigned Counter = 0;