Skip to content

Commit

Permalink
[CI][format] Explicitly pass extensions to git-clang-format (take 2)
Browse files Browse the repository at this point in the history
This is a second attempt to land 7620fe0, which was reverted in 9572388
because it caused formatting not to be enforced for several patches.
  • Loading branch information
ldionne committed Jul 10, 2024
1 parent af21bc1 commit 5f90a74
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-code-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
# Create an empty comments file so the pr-write job doesn't fail.
run: |
echo "[]" > comments &&
python ./code-format-tools/llvm/utils/git/code-format-helper.py \
python ./llvm/utils/git/code-format-helper.py \
--write-comment-to-file \
--token ${{ secrets.GITHUB_TOKEN }} \
--issue-number $GITHUB_PR_NUMBER \
Expand Down
3 changes: 2 additions & 1 deletion libcxx/include/vector
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,8 @@ public:
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT {
size_type __old_size = size();
__clear();
__annotate_shrink(__old_size);
__annotate_shrink
(__old_size);
}

_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz);
Expand Down
16 changes: 15 additions & 1 deletion llvm/utils/git/code-format-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,23 @@ def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str
if not cpp_files:
return None

cf_cmd = [self.clang_fmt_path, "--diff"]
cf_cmd = [self.clang_fmt_path, "--verbose", "--diff"]

if args.start_rev and args.end_rev:
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

Expand All @@ -225,6 +236,9 @@ def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str
proc = subprocess.run(cf_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
sys.stdout.write(proc.stderr.decode("utf-8"))

print("LDIONNE: return code of cmd was {}".format(proc.returncode))
print("LDIONNE: output of cmd was:\n{}".format(proc.stdout.decode("utf-8")))

if proc.returncode != 0:
# formatting needed, or the command otherwise failed
if args.verbose:
Expand Down

0 comments on commit 5f90a74

Please sign in to comment.