Skip to content

Conversation

@DaanDeMeyer
Copy link
Contributor

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.

@llvmbot
Copy link
Member

llvmbot commented May 15, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Daan De Meyer (DaanDeMeyer)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/140123.diff

1 Files Affected:

  • (modified) clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp (+6-1)
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);
 }

@github-actions
Copy link

github-actions bot commented May 15, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

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.
@DaanDeMeyer
Copy link
Contributor Author

I just found misc-include-cleaner in clang-tidy which is a way better fit for this so let me close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants