From: Haojian Wu Date: Mon, 5 Nov 2018 13:42:05 +0000 (+0000) Subject: [Tooling] Add "-filter" option to AllTUsExecution X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0904be59ee84c9617f4d50878e03a734ed84ef1f;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@346131 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Tooling/AllTUsExecution.h b/include/clang/Tooling/AllTUsExecution.h index ee3843398e..94bf01632f 100644 --- a/include/clang/Tooling/AllTUsExecution.h +++ b/include/clang/Tooling/AllTUsExecution.h @@ -72,6 +72,8 @@ private: unsigned ThreadCount; }; +extern llvm::cl::opt Filter; + } // end namespace tooling } // end namespace clang diff --git a/lib/Tooling/AllTUsExecution.cpp b/lib/Tooling/AllTUsExecution.cpp index 0f56bbf13f..5da21e03bc 100644 --- a/lib/Tooling/AllTUsExecution.cpp +++ b/lib/Tooling/AllTUsExecution.cpp @@ -53,6 +53,12 @@ private: } // namespace +llvm::cl::opt + 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 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 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 { diff --git a/unittests/Tooling/ExecutionTest.cpp b/unittests/Tooling/ExecutionTest.cpp index e5dc98d228..785ec7c2bc 100644 --- a/unittests/Tooling/ExecutionTest.cpp +++ b/unittests/Tooling/ExecutionTest.cpp @@ -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()); + FixedCompilationDatabaseWithFiles Compilations( + ".", {"a.cc", "b.cc", "c.cc", "ignore.cc"}, std::vector()); 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( 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) {