FileName.endswith(".mm");
StringRef FileStem = llvm::sys::path::stem(FileName);
bool FirstIncludeBlock = true;
+ bool MainIncludeFound = false;
// Create pre-compiled regular expressions for the #include categories.
SmallVector<llvm::Regex, 4> CategoryRegexs;
break;
}
}
- if (IsSource && Category > 0 && FirstIncludeBlock &&
- IncludeName.startswith("\"")) {
+ if (IsSource && !MainIncludeFound && Category > 0 &&
+ FirstIncludeBlock && IncludeName.startswith("\"")) {
StringRef HeaderStem =
llvm::sys::path::stem(IncludeName.drop_front(1).drop_back(1));
- if (FileStem.startswith(HeaderStem))
+ if (FileStem.startswith(HeaderStem)) {
Category = 0;
+ MainIncludeFound = true;
+ }
}
IncludesInBlock.push_back({IncludeName, Line, Prev, Category});
} else if (!IncludesInBlock.empty()) {
"#include \"c.h\"\n"
"#include \"b.h\"\n",
"a.cc"));
+
+ // Only recognize the first #include with a matching basename as main include.
+ EXPECT_EQ("#include \"a.h\"\n"
+ "#include \"b.h\"\n"
+ "#include \"c.h\"\n"
+ "#include \"llvm/a.h\"\n",
+ sort("#include \"b.h\"\n"
+ "#include \"a.h\"\n"
+ "#include \"c.h\"\n"
+ "#include \"llvm/a.h\"\n",
+ "a.cc"));
}
TEST_F(SortIncludesTest, NegativePriorities) {