From 44bbb0e3718302f61064948efb401988cb9df615 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Mon, 17 Jun 2024 10:08:38 -0400 Subject: [PATCH 1/2] [CI][format] Explicitly pass extensions to git-clang-format This 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 that tool as having an unrecognized extension. --- llvm/utils/git/code-format-helper.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/llvm/utils/git/code-format-helper.py b/llvm/utils/git/code-format-helper.py index f1207026704e8..48f44fd4431c0 100755 --- a/llvm/utils/git/code-format-helper.py +++ b/llvm/utils/git/code-format-helper.py @@ -216,6 +216,15 @@ 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 From b4fce70c494feb87501595e0b21a00d1f3ddf03d Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Mon, 17 Jun 2024 16:16:58 -0400 Subject: [PATCH 2/2] Darker --- llvm/utils/git/code-format-helper.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/utils/git/code-format-helper.py b/llvm/utils/git/code-format-helper.py index 48f44fd4431c0..d60d4131bc94b 100755 --- a/llvm/utils/git/code-format-helper.py +++ b/llvm/utils/git/code-format-helper.py @@ -221,7 +221,9 @@ def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str 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 + extensions.add( + ext.strip(".") + ) # Exclude periods since git-clang-format takes extensions without them cf_cmd.append("--extensions") cf_cmd.append("'{}'".format(",".join(extensions)))