Author: hokein Date: Mon Nov 5 05:42:05 2018 New Revision: 346131 URL: http://llvm.org/viewvc/llvm-project?rev=346131&view=rev Log: [Tooling] Add "-filter" option to AllTUsExecution
Summary: We can run the tools on a subset files of compilation database. Reviewers: ioeric Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D54092 Modified: cfe/trunk/include/clang/Tooling/AllTUsExecution.h cfe/trunk/lib/Tooling/AllTUsExecution.cpp cfe/trunk/unittests/Tooling/ExecutionTest.cpp Modified: cfe/trunk/include/clang/Tooling/AllTUsExecution.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/AllTUsExecution.h?rev=346131&r1=346130&r2=346131&view=diff ============================================================================== --- cfe/trunk/include/clang/Tooling/AllTUsExecution.h (original) +++ cfe/trunk/include/clang/Tooling/AllTUsExecution.h Mon Nov 5 05:42:05 2018 @@ -72,6 +72,8 @@ private: unsigned ThreadCount; }; +extern llvm::cl::opt<std::string> Filter; + } // end namespace tooling } // end namespace clang Modified: cfe/trunk/lib/Tooling/AllTUsExecution.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/AllTUsExecution.cpp?rev=346131&r1=346130&r2=346131&view=diff ============================================================================== --- cfe/trunk/lib/Tooling/AllTUsExecution.cpp (original) +++ cfe/trunk/lib/Tooling/AllTUsExecution.cpp Mon Nov 5 05:42:05 2018 @@ -53,6 +53,12 @@ private: } // namespace +llvm::cl::opt<std::string> + Filter("filter", + llvm::cl::desc("Only process files that match this filter. " + "This flag only applies to all-TUs."), + llvm::cl::init(".*")); + AllTUsToolExecutor::AllTUsToolExecutor( const CompilationDatabase &Compilations, unsigned ThreadCount, std::shared_ptr<PCHContainerOperations> PCHContainerOps) @@ -110,7 +116,10 @@ llvm::Error AllTUsToolExecutor::execute( llvm::errs() << "Error while getting current working directory: " << EC.message() << "\n"; } + llvm::Regex RegexFilter(Filter); for (std::string File : Files) { + if (!RegexFilter.match(File)) + continue; Pool.async( [&](std::string Path) { Log("[" + std::to_string(Count()) + "/" + TotalNumStr + @@ -147,7 +156,8 @@ llvm::Error AllTUsToolExecutor::execute( static llvm::cl::opt<unsigned> ExecutorConcurrency( "execute-concurrency", llvm::cl::desc("The number of threads used to process all files in " - "parallel. Set to 0 for hardware concurrency."), + "parallel. Set to 0 for hardware concurrency. " + "This flag only applies to all-TUs."), llvm::cl::init(0)); class AllTUsToolExecutorPlugin : public ToolExecutorPlugin { Modified: cfe/trunk/unittests/Tooling/ExecutionTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/ExecutionTest.cpp?rev=346131&r1=346130&r2=346131&view=diff ============================================================================== --- cfe/trunk/unittests/Tooling/ExecutionTest.cpp (original) +++ cfe/trunk/unittests/Tooling/ExecutionTest.cpp Mon Nov 5 05:42:05 2018 @@ -248,12 +248,14 @@ private: MATCHER_P(Named, Name, "") { return arg.first == Name; } TEST(AllTUsToolTest, AFewFiles) { - FixedCompilationDatabaseWithFiles Compilations(".", {"a.cc", "b.cc", "c.cc"}, - std::vector<std::string>()); + FixedCompilationDatabaseWithFiles Compilations( + ".", {"a.cc", "b.cc", "c.cc", "ignore.cc"}, std::vector<std::string>()); AllTUsToolExecutor Executor(Compilations, /*ThreadCount=*/0); + Filter.setValue("[a-c].cc"); Executor.mapVirtualFile("a.cc", "void x() {}"); Executor.mapVirtualFile("b.cc", "void y() {}"); Executor.mapVirtualFile("c.cc", "void z() {}"); + Executor.mapVirtualFile("ignore.cc", "void d() {}"); auto Err = Executor.execute(std::unique_ptr<FrontendActionFactory>( new ReportResultActionFactory(Executor.getExecutionContext()))); @@ -261,6 +263,7 @@ TEST(AllTUsToolTest, AFewFiles) { EXPECT_THAT( Executor.getToolResults()->AllKVResults(), ::testing::UnorderedElementsAre(Named("x"), Named("y"), Named("z"))); + Filter.setValue(".*"); // reset to default value. } TEST(AllTUsToolTest, ManyFiles) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits