Skip to content

[include-cleaner] Always keep non-self-contained files #65499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ TEST(IncludeCleaner, StdlibUnused) {
template <typename> class vector {};
}
)cpp";
TU.AdditionalFiles["list"] = "#include <bits>";
TU.AdditionalFiles["queue"] = "#include <bits>";
TU.AdditionalFiles["vector"] = "#include <bits>";
TU.AdditionalFiles["string"] = "#include <bits>";
TU.AdditionalFiles["list"] = guard("#include <bits>");
TU.AdditionalFiles["queue"] = guard("#include <bits>");
TU.AdditionalFiles["vector"] = guard("#include <bits>");
TU.AdditionalFiles["string"] = guard("#include <bits>");
TU.ExtraArgs = {"-isystem", testRoot()};
auto AST = TU.build();
IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/include-cleaner/lib/Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ bool PragmaIncludes::isPrivate(const FileEntry *FE) const {
}

bool PragmaIncludes::shouldKeep(const FileEntry *FE) const {
return ShouldKeep.contains(FE->getUniqueID());
return ShouldKeep.contains(FE->getUniqueID()) ||
NonSelfContainedFiles.contains(FE->getUniqueID());
}

namespace {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class PragmaIncludeTest : public ::testing::Test {

void createEmptyFiles(llvm::ArrayRef<StringRef> FileNames) {
for (llvm::StringRef File : FileNames)
Inputs.ExtraFiles[File] = "";
Inputs.ExtraFiles[File] = "#pragma once";
}
};

Expand Down
16 changes: 9 additions & 7 deletions clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
const char *PostCode = "\n";

std::vector<ClangTidyError> Errors;
EXPECT_EQ(PostCode, runCheckOnCode<IncludeCleanerCheck>(
PreCode, &Errors, "file.cpp", std::nullopt,
ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
EXPECT_EQ(PostCode,
runCheckOnCode<IncludeCleanerCheck>(
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
{{"bar.h", "#pragma once"}, {"vector", "#pragma once"}}));
}

TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
Expand All @@ -76,10 +77,11 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
PostCode,
runCheckOnCode<IncludeCleanerCheck>(
PreCode, &Errors, "file.cpp", std::nullopt, Opts,
{{"bar.h", ""},
{"vector", ""},
{appendPathFileSystemIndependent({"foo", "qux.h"}), ""},
{appendPathFileSystemIndependent({"baz", "qux", "qux.h"}), ""}}));
{{"bar.h", "#pragma once"},
{"vector", "#pragma once"},
{appendPathFileSystemIndependent({"foo", "qux.h"}), "#pragma once"},
{appendPathFileSystemIndependent({"baz", "qux", "qux.h"}),
"#pragma once"}}));
}

TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
Expand Down