[clang-tools-extra] [include-cleaner] rename enabled flags to `disable-*` (PR #132991)
Mohamed Emad via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 17 23:59:42 PDT 2025
https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/132991
>From c476948593a80ed31765cdd711a626e4e03930ab Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Tue, 25 Mar 2025 22:56:51 +0200
Subject: [PATCH 1/2] [include-cleaner] rename enabled flags to `disable-*`
---
.../include-cleaner/test/tool.cpp | 4 ++--
.../include-cleaner/tool/IncludeCleaner.cpp | 20 +++++++++----------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/clang-tools-extra/include-cleaner/test/tool.cpp b/clang-tools-extra/include-cleaner/test/tool.cpp
index d72d2317ce2b1..8b723a5bf40e2 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"
diff --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
index 1d9458ffc4d32..472611073f732 100644
--- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -91,16 +91,16 @@ cl::opt<bool> Edit{
cl::cat(IncludeCleaner),
};
-cl::opt<bool> Insert{
- "insert",
- cl::desc("Allow header insertions"),
- cl::init(true),
+cl::opt<bool> DisableInsert{
+ "disable-insert",
+ cl::desc("DIsable header insertions"),
+ cl::init(false),
cl::cat(IncludeCleaner),
};
-cl::opt<bool> Remove{
- "remove",
- cl::desc("Allow header removals"),
- cl::init(true),
+cl::opt<bool> DisableRemove{
+ "disable-remove",
+ cl::desc("Disable header removals"),
+ cl::init(false),
cl::cat(IncludeCleaner),
};
@@ -183,9 +183,9 @@ class Action : public clang::ASTFrontendAction {
auto Results =
analyze(AST.Roots, PP.MacroReferences, PP.Includes, &PI,
getCompilerInstance().getPreprocessor(), HeaderFilter);
- if (!Insert)
+ if (DisableInsert)
Results.Missing.clear();
- if (!Remove)
+ if (DisableRemove)
Results.Unused.clear();
std::string Final = fixIncludes(Results, AbsPath, Code, getStyle(AbsPath));
>From e2f78ab69f656313fc87b004506abc1deb096189 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Fri, 18 Apr 2025 08:59:03 +0200
Subject: [PATCH 2/2] [include-cleaner] return `--remove` and `--insert` to be
in deprecation period
---
.../include-cleaner/tool/IncludeCleaner.cpp | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
index 472611073f732..7a07d09ce277d 100644
--- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -90,10 +90,21 @@ 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::init(true),
+ cl::cat(IncludeCleaner),
+};
+cl::opt<bool> Remove{
+ "remove",
+ cl::desc("Allow header removals"),
+ cl::init(true),
+ cl::cat(IncludeCleaner),
+};
cl::opt<bool> DisableInsert{
"disable-insert",
- cl::desc("DIsable header insertions"),
+ cl::desc("Disable header insertions"),
cl::init(false),
cl::cat(IncludeCleaner),
};
@@ -183,9 +194,9 @@ class Action : public clang::ASTFrontendAction {
auto Results =
analyze(AST.Roots, PP.MacroReferences, PP.Includes, &PI,
getCompilerInstance().getPreprocessor(), HeaderFilter);
- if (DisableInsert)
+ if (!Insert || DisableInsert)
Results.Missing.clear();
- if (DisableRemove)
+ if (!Remove || DisableRemove)
Results.Unused.clear();
std::string Final = fixIncludes(Results, AbsPath, Code, getStyle(AbsPath));
More information about the cfe-commits
mailing list