[clang-tools-extra] 212f245 - [include-cleaner] rename enabled flags to `disable-*` (#132991)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 1 04:21:53 PDT 2025
Author: Mohamed Emad
Date: 2025-05-01T07:21:50-04:00
New Revision: 212f2456fcde822fad37bfa4e69ced1a51a4c19d
URL: https://github.com/llvm/llvm-project/commit/212f2456fcde822fad37bfa4e69ced1a51a4c19d
DIFF: https://github.com/llvm/llvm-project/commit/212f2456fcde822fad37bfa4e69ced1a51a4c19d.diff
LOG: [include-cleaner] rename enabled flags to `disable-*` (#132991)
Closes #132983
Added:
Modified:
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/include-cleaner/test/tool.cpp
clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 8f61839af2c80..579fca54924d5 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -88,6 +88,14 @@ Improvements to clang-doc
Improvements to clang-query
---------------------------
+Improvements to include-cleaner
+-------------------------------
+- Deprecated the ``-insert`` and ``-remove`` command line options, and added
+ the ``-disable-remove`` and ``-disable-insert`` command line options as
+ replacements. The previous command line options were confusing because they
+ did not imply the default state of the option (which is inserts and removes
+ being enabled). The new options are easier to understand the semantics of.
+
Improvements to clang-tidy
--------------------------
diff --git a/clang-tools-extra/include-cleaner/test/tool.cpp b/clang-tools-extra/include-cleaner/test/tool.cpp
index d72d2317ce2b1..b0a47b5ef0a14 100644
--- a/clang-tools-extra/include-cleaner/test/tool.cpp
+++ b/clang-tools-extra/include-cleaner/test/tool.cpp
@@ -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"
@@ -58,3 +58,16 @@ int x = foo();
// RUN: FileCheck --match-full-lines --check-prefix=EDIT3 %s < %t.cpp
// EDIT3: #include "foo.h"
// EDIT3-NOT: {{^}}#include "foobar.h"{{$}}
+
+// RUN: clang-include-cleaner -insert=false -print=changes %s -- -I%S/Inputs/ 2>&1 | \
+// RUN: FileCheck --check-prefix=DEPRECATED-INSERT %s
+// 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.
+
+// RUN: clang-include-cleaner -remove=false -print=changes %s -- -I%S/Inputs/ 2>&1 | \
+// RUN: FileCheck --check-prefix=DEPRECATED-REMOVE %s
+// 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.
+
+// RUN: clang-include-cleaner -insert=false -remove=false -print=changes %s -- -I%S/Inputs/ 2>&1 | \
+// RUN: FileCheck --check-prefix=DEPRECATED-BOTH %s
+// 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.
+// 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.
diff --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
index 1d9458ffc4d32..33490de9b0f6c 100644
--- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -90,19 +90,31 @@ 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"),
+ cl::desc(
+ "Allow header insertions (deprecated. Use -disable-insert instead)"),
cl::init(true),
cl::cat(IncludeCleaner),
};
cl::opt<bool> Remove{
"remove",
- cl::desc("Allow header removals"),
+ cl::desc("Allow header removals (deprecated. Use -disable-remove instead)"),
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);
@@ -183,9 +195,26 @@ class Action : public clang::ASTFrontendAction {
auto Results =
analyze(AST.Roots, PP.MacroReferences, PP.Includes, &PI,
getCompilerInstance().getPreprocessor(), HeaderFilter);
- if (!Insert)
+
+ if (!Insert) {
+ llvm::errs()
+ << "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.\n";
+ }
+
+ if (!Remove) {
+ llvm::errs()
+ << "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.\n";
+ }
+
+ if (!Insert || DisableInsert)
Results.Missing.clear();
- if (!Remove)
+ if (!Remove || DisableRemove)
Results.Unused.clear();
std::string Final = fixIncludes(Results, AbsPath, Code, getStyle(AbsPath));
More information about the cfe-commits
mailing list