Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[include-cleaner] Add --fail-on-changes option #140123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from

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);
 }

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.
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.