Skip to content

Commit dab1326

Browse files
committed
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
1 parent 76f74d1 commit dab1326

File tree

2 files changed

+8
-30
lines changed

2 files changed

+8
-30
lines changed

clang/lib/Tooling/ArgumentsAdjusters.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ ArgumentsAdjuster getClangStripDependencyFileAdjuster() {
9898
StringRef Arg = Args[i];
9999
// All dependency-file options begin with -M. These include -MM,
100100
// -MF, -MG, -MP, -MT, -MQ, -MD, and -MMD.
101-
if (!Arg.startswith("-M") && !Arg.startswith("/showIncludes")) {
101+
if (!Arg.startswith("-M") && !Arg.startswith("/showIncludes") &&
102+
!Arg.startswith("-showIncludes")) {
102103
AdjustedArgs.push_back(Args[i]);
103104
continue;
104105
}

clang/unittests/Tooling/ToolingTest.cpp

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,11 @@ TEST(ClangToolTest, StripDependencyFileAdjuster) {
530530
EXPECT_TRUE(HasFlag("-w"));
531531
}
532532

533-
// Check getClangStripDependencyFileAdjuster strips /showIncludes
533+
// Check getClangStripDependencyFileAdjuster strips /showIncludes and variants
534534
TEST(ClangToolTest, StripDependencyFileAdjusterShowIncludes) {
535-
FixedCompilationDatabase Compilations("/", {"/showIncludes", "-c"});
535+
FixedCompilationDatabase Compilations(
536+
"/", {"/showIncludes", "/showIncludes:user", "-showIncludes",
537+
"-showIncludes:user", "-c"});
536538

537539
ClangTool Tool(Compilations, std::vector<std::string>(1, "/a.cc"));
538540
Tool.mapVirtualFile("/a.cc", "void a() {}");
@@ -555,34 +557,9 @@ TEST(ClangToolTest, StripDependencyFileAdjusterShowIncludes) {
555557
return llvm::find(FinalArgs, Flag) != FinalArgs.end();
556558
};
557559
EXPECT_FALSE(HasFlag("/showIncludes"));
558-
EXPECT_TRUE(HasFlag("-c"));
559-
}
560-
561-
// Check getClangStripDependencyFileAdjuster strips /showIncludes:user
562-
TEST(ClangToolTest, StripDependencyFileAdjusterShowIncludesUser) {
563-
FixedCompilationDatabase Compilations("/", {"/showIncludes:user", "-c"});
564-
565-
ClangTool Tool(Compilations, std::vector<std::string>(1, "/a.cc"));
566-
Tool.mapVirtualFile("/a.cc", "void a() {}");
567-
568-
std::unique_ptr<FrontendActionFactory> Action(
569-
newFrontendActionFactory<SyntaxOnlyAction>());
570-
571-
CommandLineArguments FinalArgs;
572-
ArgumentsAdjuster CheckFlagsAdjuster =
573-
[&FinalArgs](const CommandLineArguments &Args, StringRef /*unused*/) {
574-
FinalArgs = Args;
575-
return Args;
576-
};
577-
Tool.clearArgumentsAdjusters();
578-
Tool.appendArgumentsAdjuster(getClangStripDependencyFileAdjuster());
579-
Tool.appendArgumentsAdjuster(CheckFlagsAdjuster);
580-
Tool.run(Action.get());
581-
582-
auto HasFlag = [&FinalArgs](const std::string &Flag) {
583-
return llvm::find(FinalArgs, Flag) != FinalArgs.end();
584-
};
585560
EXPECT_FALSE(HasFlag("/showIncludes:user"));
561+
EXPECT_FALSE(HasFlag("-showIncludes"));
562+
EXPECT_FALSE(HasFlag("-showIncludes:user"));
586563
EXPECT_TRUE(HasFlag("-c"));
587564
}
588565

0 commit comments

Comments
 (0)