Skip to content

Ignore exit code of clang-format-diff #35

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 4 commits into
base: master
Choose a base branch
from

Conversation

ptomato
Copy link
Contributor

@ptomato ptomato commented Jul 28, 2024

Adapt to breaking change in clang-format-diff 18.x. The PR also includes a few unrelated cleanups.

Closes: #33

ptomato added 4 commits July 28, 2024 11:36
This helps debug what is happening when a git command fails in a test.
Newer versions of git don't allow this by default. Specify the
appropriate config option on the command line to allow it.
Starting with 18.x, clang-format-diff exits with a nonzero exit code if
there was a diff to be applied. This breaks the apply-format script
because it will exit without printing the diff. Instead, ignore the exit
code and proceed to print the diff.

Closes: barisione#33
@ptomato
Copy link
Contributor Author

ptomato commented Jul 28, 2024

Note, clang-format-diff 18.x has another regression: llvm/llvm-project#86776 This causes the test_two_files tests to fail, but it is unrelated to this change. Hopefully they will backport the fix soon.

otaviolima

This comment was marked as off-topic.

> "$patch_dest" \
|| exit 1
> "$patch_dest"
Copy link
Contributor

@gareth-rees gareth-rees Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes sense to ignore all exit codes. From version 18, clang-format-diff exits with status 1 if there are diffs, but other statuses are possible, for example, if there is an invalid command-line option then the exit status is 2:

$ /usr/share/clang/clang-format-18/clang-format-diff.py --no-such-option
usage: clang-format-diff.py [-h] [-i] [-p NUM] [-regex PATTERN] [-iregex PATTERN] [-sort-includes]
                            [-v] [-style STYLE] [-fallback-style FALLBACK_STYLE] [-binary BINARY]
clang-format-diff.py: error: unrecognized arguments: --no-such-option
$ echo $?
2

So we ought to follow the clang-format-diff pipeline with something like:

[ $? -gt 1 ] && exit $?

Comment on lines -71 to +75
return subprocess.check_output(args, **kwargs)
try:
return subprocess.check_output(args, **kwargs)
except subprocess.CalledProcessError as exc:
exc.add_note(exc.output)
raise exc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems to be unrelated to the clang-format-diff exit status. I suggest making separate PR(s) for this and the other changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New clang-format-diff returns a non-zero status code when diffs exist leading apply-format to fail
3 participants