[llvm] [CI][format] Explicitly pass extensions to git-clang-format (take 2) (PR #98227)

Louis Dionne via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 9 14:32:43 PDT 2024


https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/98227

This is a second attempt to land 7620fe0, which was reverted in 9572388 because it caused formatting not to be enforced for several patches.

>From 0cf09f60e233ecdd158632f67c0c1f186d68a333 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 9 Jul 2024 17:28:55 -0400
Subject: [PATCH] [CI][format] Explicitly pass extensions to git-clang-format
 (take 2)

This is a second attempt to land 7620fe0, which was reverted in 9572388
because it caused formatting not to be enforced for several patches.
---
 llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp |  2 ++
 llvm/utils/git/code-format-helper.py        | 11 +++++++++++
 2 files changed, 13 insertions(+)

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
 



More information about the llvm-commits mailing list