[clang-tools-extra] [include-cleaner] Add --fail-on-changes option (PR #140123)
Daan De Meyer via cfe-commits
cfe-commits at lists.llvm.org
Thu May 15 12:09:00 PDT 2025
https://github.com/DaanDeMeyer created https://github.com/llvm/llvm-project/pull/140123
When integrating clang-include-cleaner into a test suite, it's useful to have it exit with a nonzero exit status when there are suggested changes to includes so let's add --fail-on-changes to make that possible.
>From 6f2a50adf7dc1d559421e83ad9605db96ead6fa6 Mon Sep 17 00:00:00 2001
From: Daan De Meyer <daan.j.demeyer at gmail.com>
Date: Thu, 15 May 2025 21:07:46 +0200
Subject: [PATCH] [include-cleaner] Add --fail-on-changes option
When integrating clang-include-cleaner into a test suite, it's useful
to have it exit with a nonzero exit status when there are suggested
changes to includes so let's add --fail-on-changes to make that possible.
---
clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
index 372ab5fa2706e..47e1400d8ccb2 100644
--- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -115,6 +115,11 @@ cl::opt<bool> DisableRemove{
cl::init(false),
cl::cat(IncludeCleaner),
};
+cl::opt<bool> FailOnChanges{
+ "fail-on-changes",
+ cl::desc("Exit with a non-zero exit code if changes are suggested"),
+ cl::cat(IncludeCleaner),
+};
std::atomic<unsigned> Errors = ATOMIC_VAR_INIT(0);
@@ -410,5 +415,5 @@ int main(int argc, const char **argv) {
}
}
}
- return ErrorCode || Errors != 0;
+ return ErrorCode || Errors != 0 || (FailOnChanges && Factory.editedFiles().size() != 0);
}
More information about the cfe-commits
mailing list