[PATCH] D78939: Strip -showIncludes in getClangStripDependencyFileAdjuster()

Arthur Eubanks via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 27 09:39:27 PDT 2020


aeubanks created this revision.
aeubanks added a reviewer: thakis.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Follow-up to https://reviews.llvm.org/D78836.

Also consolidate some test cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78939

Files:
  clang/lib/Tooling/ArgumentsAdjusters.cpp
  clang/unittests/Tooling/ToolingTest.cpp


Index: clang/unittests/Tooling/ToolingTest.cpp
===================================================================
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -530,9 +530,11 @@
   EXPECT_TRUE(HasFlag("-w"));
 }
 
-// Check getClangStripDependencyFileAdjuster strips /showIncludes
+// Check getClangStripDependencyFileAdjuster strips /showIncludes and variants
 TEST(ClangToolTest, StripDependencyFileAdjusterShowIncludes) {
-  FixedCompilationDatabase Compilations("/", {"/showIncludes", "-c"});
+  FixedCompilationDatabase Compilations(
+      "/", {"/showIncludes", "/showIncludes:user", "-showIncludes",
+            "-showIncludes:user", "-c"});
 
   ClangTool Tool(Compilations, std::vector<std::string>(1, "/a.cc"));
   Tool.mapVirtualFile("/a.cc", "void a() {}");
@@ -555,34 +557,9 @@
     return llvm::find(FinalArgs, Flag) != FinalArgs.end();
   };
   EXPECT_FALSE(HasFlag("/showIncludes"));
-  EXPECT_TRUE(HasFlag("-c"));
-}
-
-// Check getClangStripDependencyFileAdjuster strips /showIncludes:user
-TEST(ClangToolTest, StripDependencyFileAdjusterShowIncludesUser) {
-  FixedCompilationDatabase Compilations("/", {"/showIncludes:user", "-c"});
-
-  ClangTool Tool(Compilations, std::vector<std::string>(1, "/a.cc"));
-  Tool.mapVirtualFile("/a.cc", "void a() {}");
-
-  std::unique_ptr<FrontendActionFactory> Action(
-      newFrontendActionFactory<SyntaxOnlyAction>());
-
-  CommandLineArguments FinalArgs;
-  ArgumentsAdjuster CheckFlagsAdjuster =
-      [&FinalArgs](const CommandLineArguments &Args, StringRef /*unused*/) {
-        FinalArgs = Args;
-        return Args;
-      };
-  Tool.clearArgumentsAdjusters();
-  Tool.appendArgumentsAdjuster(getClangStripDependencyFileAdjuster());
-  Tool.appendArgumentsAdjuster(CheckFlagsAdjuster);
-  Tool.run(Action.get());
-
-  auto HasFlag = [&FinalArgs](const std::string &Flag) {
-    return llvm::find(FinalArgs, Flag) != FinalArgs.end();
-  };
   EXPECT_FALSE(HasFlag("/showIncludes:user"));
+  EXPECT_FALSE(HasFlag("-showIncludes"));
+  EXPECT_FALSE(HasFlag("-showIncludes:user"));
   EXPECT_TRUE(HasFlag("-c"));
 }
 
Index: clang/lib/Tooling/ArgumentsAdjusters.cpp
===================================================================
--- clang/lib/Tooling/ArgumentsAdjusters.cpp
+++ clang/lib/Tooling/ArgumentsAdjusters.cpp
@@ -98,7 +98,8 @@
       StringRef Arg = Args[i];
       // All dependency-file options begin with -M. These include -MM,
       // -MF, -MG, -MP, -MT, -MQ, -MD, and -MMD.
-      if (!Arg.startswith("-M") && !Arg.startswith("/showIncludes")) {
+      if (!Arg.startswith("-M") && !Arg.startswith("/showIncludes") &&
+          !Arg.startswith("-showIncludes")) {
         AdjustedArgs.push_back(Args[i]);
         continue;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78939.260353.patch
Type: text/x-patch
Size: 2771 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200427/b59585a1/attachment.bin>


More information about the cfe-commits mailing list