-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[CI][format] Explicitly pass extensions to git-clang-format (take 2) #98227
Conversation
@llvm/pr-subscribers-libcxx @llvm/pr-subscribers-mlgo Author: Louis Dionne (ldionne) ChangesThis is a second attempt to land 7620fe0, which was reverted in 9572388 because it caused formatting not to be enforced for several patches. Full diff: https://github.com/llvm/llvm-project/pull/98227.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
index 7f90457d720b4..536984e6c9a5a 100644
--- a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
+++ b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
@@ -10,6 +10,8 @@
//
//===----------------------------------------------------------------------===//
+// This line should never get through the formatting job clang-format please format this into something that is actually reasonable.
+
#include "AllocationOrder.h"
#include "RegAllocEvictionAdvisor.h"
#include "RegAllocGreedy.h"
diff --git a/llvm/utils/git/code-format-helper.py b/llvm/utils/git/code-format-helper.py
index f1207026704e8..d60d4131bc94b 100755
--- a/llvm/utils/git/code-format-helper.py
+++ b/llvm/utils/git/code-format-helper.py
@@ -216,6 +216,17 @@ def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str
cf_cmd.append(args.start_rev)
cf_cmd.append(args.end_rev)
+ # Gather the extension of all modified files and pass them explicitly to git-clang-format.
+ # This prevents git-clang-format from applying its own filtering rules on top of ours.
+ extensions = set()
+ for file in cpp_files:
+ _, ext = os.path.splitext(file)
+ extensions.add(
+ ext.strip(".")
+ ) # Exclude periods since git-clang-format takes extensions without them
+ cf_cmd.append("--extensions")
+ cf_cmd.append("'{}'".format(",".join(extensions)))
+
cf_cmd.append("--")
cf_cmd += cpp_files
|
This PR is not ready for review, I'm trying to investigate why the CI doesn't detect format breakage. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
One other thing to note (if you aren't already aware) is that the python scripts are pulled in from
|
@boomanaiden154 I think I found the issue. I was passing I think removing the quoting should do it. I do need to test that the right thing happens when I have a file with no extension, especially when the only modified file is one without an extension (e.g. |
2bfe6c5
to
5f90a74
Compare
This is a second attempt to land 7620fe0, which was reverted in 9572388 because it caused formatting not to be enforced for several patches.
5f90a74
to
8330366
Compare
OK, sorry for the multiple updates here but I think this should be good to go. I tested with:
and they all seemed to work now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I'll try and keep an eye on this over the next couple days after this lands to see if something drastically changes, but if the basics work, we should be good.
At some point I would like proper testing for the CI infrastructure, but haven't figured out how to do pieces of it. Hopefully I can spend some time on that soon.
…lvm#98227) This patch ensures that the CI script controls which file extensions are considered instead of letting git-clang-format apply its own filtering rules. In particular, this properly handles libc++ extension-less headers which were passed to git-clang-format, but then dropped by the tool as having an unrecognized extension. This is a second attempt to land 7620fe0, which was reverted in 9572388 because it caused formatting not to be enforced for several patches. The problem was that we'd incorrectly pass the extensions with additional quoting to git-clang-format. The incorrect quoting has been removed in this version of the patch.
This patch ensures that the CI script controls which file extensions are
considered instead of letting git-clang-format apply its own filtering
rules. In particular, this properly handles libc++ extension-less headers
which were passed to git-clang-format, but then dropped by the tool as
having an unrecognized extension.
This is a second attempt to land 7620fe0, which was reverted in 9572388
because it caused formatting not to be enforced for several patches. The
problem was that we'd incorrectly pass the extensions with additional quoting
to git-clang-format. The incorrect quoting has been removed in this version
of the patch.