[clang] dab1326 - Strip -showIncludes in getClangStripDependencyFileAdjuster()
Arthur Eubanks via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 27 11:20:37 PDT 2020
Author: Arthur Eubanks
Date: 2020-04-27T11:20:08-07:00
New Revision: dab1326a5ae32ffd2dc277027e1ae68d8b5124d5
URL: https://github.com/llvm/llvm-project/commit/dab1326a5ae32ffd2dc277027e1ae68d8b5124d5
DIFF: https://github.com/llvm/llvm-project/commit/dab1326a5ae32ffd2dc277027e1ae68d8b5124d5.diff
LOG: Strip -showIncludes in getClangStripDependencyFileAdjuster()
Summary:
Follow-up to https://reviews.llvm.org/D78836.
Also consolidate some test cases.
Reviewers: thakis
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D78939
Added:
Modified:
clang/lib/Tooling/ArgumentsAdjusters.cpp
clang/unittests/Tooling/ToolingTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Tooling/ArgumentsAdjusters.cpp b/clang/lib/Tooling/ArgumentsAdjusters.cpp
index d8cd11efedd2..a857b57fbf7b 100644
--- a/clang/lib/Tooling/ArgumentsAdjusters.cpp
+++ b/clang/lib/Tooling/ArgumentsAdjusters.cpp
@@ -98,7 +98,8 @@ ArgumentsAdjuster getClangStripDependencyFileAdjuster() {
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;
}
diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp
index 782b3f6a2b44..5bd2864b5ba1 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -530,9 +530,11 @@ TEST(ClangToolTest, StripDependencyFileAdjuster) {
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 @@ TEST(ClangToolTest, StripDependencyFileAdjusterShowIncludes) {
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"));
}
More information about the cfe-commits
mailing list