]> granicus.if.org Git - clang/commitdiff
[Tooling] Add "-filter" option to AllTUsExecution
authorHaojian Wu <hokein@google.com>
Mon, 5 Nov 2018 13:42:05 +0000 (13:42 +0000)
committerHaojian Wu <hokein@google.com>
Mon, 5 Nov 2018 13:42:05 +0000 (13:42 +0000)
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

include/clang/Tooling/AllTUsExecution.h
lib/Tooling/AllTUsExecution.cpp
unittests/Tooling/ExecutionTest.cpp

index ee3843398ed4101871be61faf5ff416f8d2d8cfb..94bf01632fb4557bfffd72c8c00b8be3419f42be 100644 (file)
@@ -72,6 +72,8 @@ private:
   unsigned ThreadCount;
 };
 
+extern llvm::cl::opt<std::string> Filter;
+
 } // end namespace tooling
 } // end namespace clang
 
index 0f56bbf13f79f446b1d7608daf54a8aba3eebb2c..5da21e03bcd5ddb247ce2d42fac9500c9eb3be7f 100644 (file)
@@ -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 {
index e5dc98d228d9308025d0a838590b6147e0dd8a65..785ec7c2bc67234e1ddd45a723087e448b4b8408 100644 (file)
@@ -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) {