Skip to content
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

Enforce clang-format on the entire code base. #3679

Merged
merged 4 commits into from
Nov 18, 2022
Merged

Conversation

fruffy
Copy link
Collaborator

@fruffy fruffy commented Nov 9, 2022

This PR enforces clang-format on the entire P4C code base. This is a one-and-done procedure since we already have an automated script There are pros and cons to this approach.
Pros:

  • Once this is done the entire code base will have an consistent style that can be tweaked with a simple config file.
  • Style can be checked on every PR, which reduces the amount of effort needed for manual style comments.
  • clang-format is aligned with cpplint and will automatically fix cpplint complaints

Cons:

  • This PR definitely will pollute git history and it will make it harder to git blame specific sections of the code going forward.
  • Any potential clones/forks of P4C will have a hell of a time trying to resolve merge conflicts.

Note that the ir folder is not checked yet. The reason is that the includes there are set up in a very specific manner. I have a PR that fixes this, which I can merge in case this PR is approved.

@fruffy fruffy force-pushed the fruffy/clang-format branch 5 times, most recently from cf67ba7 to e7668bf Compare November 11, 2022 21:55
@fruffy fruffy marked this pull request as ready for review November 12, 2022 17:09
@davidbolvansky
Copy link
Contributor

davidbolvansky commented Nov 13, 2022

This PR definitely will pollute git history and it will make it harder to git blame specific sections of the code going forward.

Well, not a huge problem in practice with .git-blame-ignore-revs. If you use docker images to develop p4c, this "issue" is easy to fully work around, as you need to run git config blame.ignoreRevsFile .git-blame-ignore-revs and done.

https://www.stefanjudis.com/today-i-learned/how-to-exclude-commits-from-git-blame/

@fruffy
Copy link
Collaborator Author

fruffy commented Nov 13, 2022

This PR definitely will pollute git history and it will make it harder to git blame specific sections of the code going forward.

Well, not a huge problem in practice with .git-blame-ignore-revs. If you use docker images to develop p4c, this "issue" is easy to fully work around, as you need to run git config blame.ignoreRevsFile .git-blame-ignore-revs and done.

https://www.stefanjudis.com/today-i-learned/how-to-exclude-commits-from-git-blame/

Oh interesting, I did not know about this. So should we add this file after we have merged this PR? With the appropriate commit ID.

@davidbolvansky
Copy link
Contributor

Yes, +1

@fruffy fruffy requested a review from mihaibudiu November 16, 2022 18:02
@mihaibudiu
Copy link
Contributor

It's not a good use of human time to review this kind of change.
If you guarantee it's equivalent that's good enough.
But you have to automate this going forward, otherwise we'll have again at some point a similar PR.

@fruffy
Copy link
Collaborator Author

fruffy commented Nov 17, 2022

It's not a good use of human time to review this kind of change. If you guarantee it's equivalent that's good enough. But you have to automate this going forward, otherwise we'll have again at some point a similar PR.

Yes, there is no expectation to review every single file. The clang-format changes are expected to be semantically equivalent.

This check actually does automatically enforce the right format on every file going forward. So a big PR like this should not be necessary anymore, unless we change the format file.

Copy link
Contributor

@jnfoster jnfoster left a comment

Choose a reason for hiding this comment

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

This is good and an improvement to our hygiene. Let's wait to merge it until we have clear consensus though.

@fruffy
Copy link
Collaborator Author

fruffy commented Nov 18, 2022

@mbudiu-vmw Any other thoughts on this? Once this is in, all PRs should be checked with clang-format. #3701 is a follow-up that cleans up the includes of the IR files so that clang-format can be enforced there.

@mihaibudiu
Copy link
Contributor

No other comments.

@mihaibudiu
Copy link
Contributor

Prehaps a pre-commit hook should check the format, otherwise we'll have lots of failed jobs.

@fruffy fruffy merged commit e26a49d into main Nov 18, 2022
@jnfoster
Copy link
Contributor

🙌

@mihaibudiu mihaibudiu deleted the fruffy/clang-format branch November 19, 2022 00:02
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.

4 participants