Skip to content
Merged
4 changes: 2 additions & 2 deletions clang-tools-extra/include-cleaner/test/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ int x = foo();
// CHANGE: - "foobar.h"
// CHANGE-NEXT: + "foo.h"

// RUN: clang-include-cleaner -remove=0 -print=changes %s -- -I%S/Inputs/ | FileCheck --check-prefix=INSERT %s
// RUN: clang-include-cleaner -disable-remove -print=changes %s -- -I%S/Inputs/ | FileCheck --check-prefix=INSERT %s
// INSERT-NOT: - "foobar.h"
// INSERT: + "foo.h"

// RUN: clang-include-cleaner -insert=0 -print=changes %s -- -I%S/Inputs/ | FileCheck --check-prefix=REMOVE %s
// RUN: clang-include-cleaner -disable-insert -print=changes %s -- -I%S/Inputs/ | FileCheck --check-prefix=REMOVE %s
// REMOVE: - "foobar.h"
// REMOVE-NOT: + "foo.h"

Expand Down
17 changes: 14 additions & 3 deletions clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ cl::opt<bool> Edit{
cl::desc("Apply edits to analyzed source files"),
cl::cat(IncludeCleaner),
};

cl::opt<bool> Insert{
"insert",
cl::desc("Allow header insertions"),
Expand All @@ -103,6 +102,18 @@ cl::opt<bool> Remove{
cl::init(true),
cl::cat(IncludeCleaner),
};
cl::opt<bool> DisableInsert{
"disable-insert",
cl::desc("Disable header insertions"),
cl::init(false),
cl::cat(IncludeCleaner),
};
cl::opt<bool> DisableRemove{
"disable-remove",
cl::desc("Disable header removals"),
cl::init(false),
cl::cat(IncludeCleaner),
};

std::atomic<unsigned> Errors = ATOMIC_VAR_INIT(0);

Expand Down Expand Up @@ -183,9 +194,9 @@ class Action : public clang::ASTFrontendAction {
auto Results =
analyze(AST.Roots, PP.MacroReferences, PP.Includes, &PI,
getCompilerInstance().getPreprocessor(), HeaderFilter);
if (!Insert)
if (!Insert || DisableInsert)
Results.Missing.clear();
if (!Remove)
if (!Remove || DisableRemove)
Results.Unused.clear();
std::string Final = fixIncludes(Results, AbsPath, Code, getStyle(AbsPath));

Expand Down
Loading