[PATCH] D54092: [Tooling] Add "-filter" option to AllTUsExecution

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 5 05:44:27 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rC346131: [Tooling] Add "-filter" option to AllTUsExecution (authored by hokein, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54092?vs=172574&id=172575#toc

Repository:
  rC Clang

https://reviews.llvm.org/D54092

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


Index: unittests/Tooling/ExecutionTest.cpp
===================================================================
--- unittests/Tooling/ExecutionTest.cpp
+++ unittests/Tooling/ExecutionTest.cpp
@@ -248,19 +248,22 @@
 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())));
   ASSERT_TRUE(!Err);
   EXPECT_THAT(
       Executor.getToolResults()->AllKVResults(),
       ::testing::UnorderedElementsAre(Named("x"), Named("y"), Named("z")));
+  Filter.setValue(".*"); // reset to default value.
 }
 
 TEST(AllTUsToolTest, ManyFiles) {
Index: include/clang/Tooling/AllTUsExecution.h
===================================================================
--- include/clang/Tooling/AllTUsExecution.h
+++ include/clang/Tooling/AllTUsExecution.h
@@ -72,6 +72,8 @@
   unsigned ThreadCount;
 };
 
+extern llvm::cl::opt<std::string> Filter;
+
 } // end namespace tooling
 } // end namespace clang
 
Index: lib/Tooling/AllTUsExecution.cpp
===================================================================
--- lib/Tooling/AllTUsExecution.cpp
+++ lib/Tooling/AllTUsExecution.cpp
@@ -53,6 +53,12 @@
 
 } // 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::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 @@
 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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54092.172575.patch
Type: text/x-patch
Size: 3137 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181105/57b77234/attachment.bin>


More information about the cfe-commits mailing list