Skip to content

Commit 212f245

Browse files
authored
[include-cleaner] rename enabled flags to disable-* (#132991)
Closes #132983
1 parent 21aa7b8 commit 212f245

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed

clang-tools-extra/docs/ReleaseNotes.rst

+8
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ Improvements to clang-doc
8888
Improvements to clang-query
8989
---------------------------
9090

91+
Improvements to include-cleaner
92+
-------------------------------
93+
- Deprecated the ``-insert`` and ``-remove`` command line options, and added
94+
the ``-disable-remove`` and ``-disable-insert`` command line options as
95+
replacements. The previous command line options were confusing because they
96+
did not imply the default state of the option (which is inserts and removes
97+
being enabled). The new options are easier to understand the semantics of.
98+
9199
Improvements to clang-tidy
92100
--------------------------
93101

clang-tools-extra/include-cleaner/test/tool.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ int x = foo();
66
// CHANGE: - "foobar.h"
77
// CHANGE-NEXT: + "foo.h"
88

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

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

@@ -58,3 +58,16 @@ int x = foo();
5858
// RUN: FileCheck --match-full-lines --check-prefix=EDIT3 %s < %t.cpp
5959
// EDIT3: #include "foo.h"
6060
// EDIT3-NOT: {{^}}#include "foobar.h"{{$}}
61+
62+
// RUN: clang-include-cleaner -insert=false -print=changes %s -- -I%S/Inputs/ 2>&1 | \
63+
// RUN: FileCheck --check-prefix=DEPRECATED-INSERT %s
64+
// DEPRECATED-INSERT: warning: '-insert=0' is deprecated in favor of '-disable-insert'. The old flag was confusing since it suggested that inserts were disabled by default, when they were actually enabled.
65+
66+
// RUN: clang-include-cleaner -remove=false -print=changes %s -- -I%S/Inputs/ 2>&1 | \
67+
// RUN: FileCheck --check-prefix=DEPRECATED-REMOVE %s
68+
// DEPRECATED-REMOVE: warning: '-remove=0' is deprecated in favor of '-disable-remove'. The old flag was confusing since it suggested that removes were disabled by default, when they were actually enabled.
69+
70+
// RUN: clang-include-cleaner -insert=false -remove=false -print=changes %s -- -I%S/Inputs/ 2>&1 | \
71+
// RUN: FileCheck --check-prefix=DEPRECATED-BOTH %s
72+
// DEPRECATED-BOTH: warning: '-insert=0' is deprecated in favor of '-disable-insert'. The old flag was confusing since it suggested that inserts were disabled by default, when they were actually enabled.
73+
// DEPRECATED-BOTH: warning: '-remove=0' is deprecated in favor of '-disable-remove'. The old flag was confusing since it suggested that removes were disabled by default, when they were actually enabled.

clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

+34-5
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,31 @@ cl::opt<bool> Edit{
9090
cl::desc("Apply edits to analyzed source files"),
9191
cl::cat(IncludeCleaner),
9292
};
93-
9493
cl::opt<bool> Insert{
9594
"insert",
96-
cl::desc("Allow header insertions"),
95+
cl::desc(
96+
"Allow header insertions (deprecated. Use -disable-insert instead)"),
9797
cl::init(true),
9898
cl::cat(IncludeCleaner),
9999
};
100100
cl::opt<bool> Remove{
101101
"remove",
102-
cl::desc("Allow header removals"),
102+
cl::desc("Allow header removals (deprecated. Use -disable-remove instead)"),
103103
cl::init(true),
104104
cl::cat(IncludeCleaner),
105105
};
106+
cl::opt<bool> DisableInsert{
107+
"disable-insert",
108+
cl::desc("Disable header insertions"),
109+
cl::init(false),
110+
cl::cat(IncludeCleaner),
111+
};
112+
cl::opt<bool> DisableRemove{
113+
"disable-remove",
114+
cl::desc("Disable header removals"),
115+
cl::init(false),
116+
cl::cat(IncludeCleaner),
117+
};
106118

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

@@ -183,9 +195,26 @@ class Action : public clang::ASTFrontendAction {
183195
auto Results =
184196
analyze(AST.Roots, PP.MacroReferences, PP.Includes, &PI,
185197
getCompilerInstance().getPreprocessor(), HeaderFilter);
186-
if (!Insert)
198+
199+
if (!Insert) {
200+
llvm::errs()
201+
<< "warning: '-insert=0' is deprecated in favor of "
202+
"'-disable-insert'. "
203+
"The old flag was confusing since it suggested that inserts "
204+
"were disabled by default, when they were actually enabled.\n";
205+
}
206+
207+
if (!Remove) {
208+
llvm::errs()
209+
<< "warning: '-remove=0' is deprecated in favor of "
210+
"'-disable-remove'. "
211+
"The old flag was confusing since it suggested that removes "
212+
"were disabled by default, when they were actually enabled.\n";
213+
}
214+
215+
if (!Insert || DisableInsert)
187216
Results.Missing.clear();
188-
if (!Remove)
217+
if (!Remove || DisableRemove)
189218
Results.Unused.clear();
190219
std::string Final = fixIncludes(Results, AbsPath, Code, getStyle(AbsPath));
191220

0 commit comments

Comments
 (0)