-
Notifications
You must be signed in to change notification settings - Fork 91
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
Use fixed clang format #1461
Use fixed clang format #1461
Conversation
When this is merged, we should merge ginkgo-project/git-cmake-format#13 |
I think the current |
d578455
to
f89317d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should old pr be #1405 ?
Could you add the pre-commit requirement into the README.md and pre-commit and mirrors-clang-format license into ABOUT-LICENSING.md.
I just noticed ABOUT-LICENSING render is broken. Could you also fix them?
.pre-commit-config.yaml
Outdated
- repo: https://github.com/pre-commit/mirrors-clang-format | ||
rev: 'v14.0.0' # The default in Ubuntu 22.04, which is used in our CI | ||
hooks: | ||
- id: clang-format | ||
types_or: [c, c++, cuda, inc] | ||
exclude: third_party/SuiteSparse/AMD/.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 2 space indention as the other yaml
#include <omp.h> | ||
#include <Kokkos_Core.hpp> | ||
#include <ginkgo/ginkgo.hpp> | ||
#include <Kokkos_Core.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be separated
jobs: | ||
pre-commit: | ||
name: Run pre-commit hooks | ||
runs-on: ubuntu-latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runs-on: ubuntu-latest | |
runs-on: ubuntu-22.04 |
because format_header currently still use the system clang-format-14, using 22.04 might be more stable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change this, but what is the purpose of format_header.sh
anyway? It seems to reorder the includes, but that should be covered by clang-format already. Special handling like the force-on-top
could be handled by disabling clang-format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, clang-format reordering does not fit our main header (it's somehow complex, so I would also like to change) and the ordering can not be handled across sections (or across-section reorder will only contain one space line for sep?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the format_header did two things:
- put the correct main header on the top
- put all the other headers together, reorder the header with clang-format 12+ and then replace one line sep -> two line sep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a way to achieve 1. with clang-format. But that requires changing
#include <ginkgo/core/what/ever.hpp>
into
#include "ginkgo/core/what/ever.hpp"
So clang-format recognizes the main header of a source file only if its in ""
, but not if its in <>
.
I will also look into 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the main header issue is we have several rules for main header. Please take a look at https://github.com/ginkgo-project/ginkgo/blob/develop/dev_tools/scripts/config
Some of them could be merged, but it's still complex if we do not have certain forced rules.
We try writing the general rules in https://github.com/ginkgo-project/ginkgo/wiki/Contributing-guidelines#main-header
From https://clang.llvm.org/docs/ClangFormatStyleOptions.html#includeismainregex, you can only have simple regex for all of them.
Thanks for looking at that, look forward to avoiding complex format_header.
I suggest it should be another pr if you find something easy to maintain.
@yhmtsai I'm not sure if we need to add either pre-commit, or the clang-format hook to our licensing description. Our ginkgo package (the source code + whatever is in the third_party stuff) does not contain any code or binaries from either pre-commit or clang-format. The pre-commit config could be licensed, but we didn't get into that yet. |
just copy paste the comment from #1405 if want to use clang-format from pre-commit in the editor. (easier find in the future)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something I can not put comments directly but needs updates:
- git-cmake-format can be deleted in ABOUT-LICENSING.md
- INSTALL.md replaces git-cmake-format by pre-commit
- delete third-party git-cmake-format
- dummy_hook/CMakeLists.txt needs to update
include/ginkgo/core/log/papi.hpp
Outdated
#include <mutex> | ||
|
||
|
||
#include <sde_lib.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, I do not get this changes.
do you add new breaks and only run format without format_header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I forgot the format_header. I will also run this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although I do not know why the format_header change it, it shuold keep everything in #if
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just go through again the format_header. the thing in #if only raises a warning only. the header is still considered in clang-format with regroup (in format_header)
format! |
8653ec9
to
e2418ca
Compare
- fix format-rebase.sh - yml formatting - update checkout action version - fix ABOUT-LICENSING.md formatting - use fixed ubuntu version Co-authored-by: Yu-Hsiang M. Tsai <[email protected]>
e2418ca
to
1cce135
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information The version of Java (11.0.3) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17. |
Old PR: #1404
This PR enables us to force users to use the same version of clang-format as our CI. This is done by requiring contributors to install pre-commit (which can be done easily through pip/pipx). pre-commit allows us to fix the used version of clang-format, so that contributors will use exactly the same version as our CI.
If pre-commit can't be detected during cmake an error is thrown. Otherwise, the pre-commit hooks are installed.
Since this replaces our git-cmake-format, I have removed it.
To see it in action: here is an PR in a fork that shows the CI use cases MarcelKoch#9
Additional changes:
.clang-format
Warning
For those using git-worktrees, if one working tree is updated with this PR it will overwrite the git hooks for all working trees (I don't think you can have different hooks for different working trees). The easy fix is of course to just update all used working trees accordingly.
Note: I think the previous PR #1405 got closed because it was based not on develop and it was from my fork, but who knows?