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

core: Add coding style enforcement and update selected code areas #8595

Closed
wants to merge 3 commits into from

Conversation

a-szegel
Copy link
Contributor

@a-szegel a-szegel commented Mar 2, 2023

Lets enforce a style guide across the project to save everyone time (no more giving or getting formatting comments).

Adds the clang format file from linux kernel.
Adds CI to make sure future PR's are formatted (tested on this PR, it works).
Formatted all files in the project.

To format the entire project:

find foo/bar/ -iname *.h -o -iname *.c | xargs clang-format -i

To format just the files you have changed:

git-clang-format

.clang-format Outdated
# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ tools/ \
# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
# | LC_ALL=C sort -u
ForEachMacros:
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing these are kernel macros that can be removed from this file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree. We can add our own foreach macros defined in ofi_list.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@shefty
Copy link
Member

shefty commented Mar 2, 2023

Some providers will never pass these checks.

@a-szegel
Copy link
Contributor Author

a-szegel commented Mar 2, 2023

@shefty

I formatted every provider in this PR with find foo/bar/ -iname *.h -o -iname *.c | xargs clang-format -i, and added a github workflow to enforce new PR's follow the style guidelines. If a commit fails, they can just run git-clang-format to only modify changed files.

Do we like this idea?

@a-szegel
Copy link
Contributor Author

a-szegel commented Mar 2, 2023

Err.. apparently I messed it up a bit... but will fix

@shefty
Copy link
Member

shefty commented Mar 2, 2023

I don't want to reformat all existing providers or force those providers to a specific coding style. This needs to be more selective.

I want loosely enforced style for any of the core code, plus specific providers that are close to following the standard (tcp, ucx, shm, util, udp, verbs, rxm, rxd, mrail). I would not modify psmX, opx, bqg, or gni.

And there's 0 chance of anyone reviewing a 100k line patch.

@shefty
Copy link
Member

shefty commented Mar 2, 2023

Btw, these sort of changes end up making it difficult to cherry-pick patches to stable branches.

@a-szegel
Copy link
Contributor Author

a-szegel commented Mar 2, 2023

@shefty Would you be ok with me adding this... and only modifying include and source?

@a-szegel
Copy link
Contributor Author

a-szegel commented Mar 2, 2023

and we can have separate PR's for each provider who wants to opt-in... we can choose which directories the CI checker looks in too (so we can keep that)

@a-szegel
Copy link
Contributor Author

a-szegel commented Mar 2, 2023

I think the long term benefits of not wasting time on style comments outweigh the temporary pain of a few hard re-bases.

Signed-off-by: Seth Zegelstein <szegel@amazon.com>
@a-szegel a-szegel force-pushed the clang-format branch 2 times, most recently from 89cd20d to 3441cad Compare March 2, 2023 02:21
@a-szegel
Copy link
Contributor Author

a-szegel commented Mar 2, 2023

something is wrong with how I setup the clang format file, or how I am calling clang-format

@a-szegel
Copy link
Contributor Author

a-szegel commented Mar 2, 2023

after spinning up an ubuntu instance and running clang, format with no changes... it is the job that is broken

Signed-off-by: Seth Zegelstein <szegel@amazon.com>
Signed-off-by: Seth Zegelstein <szegel@amazon.com>
@a-szegel
Copy link
Contributor Author

a-szegel commented Mar 2, 2023

CI was using clang format version 13, I was using clang format version 14... apparently version matters

@@ -0,0 +1,121 @@
# copied from: https://github.com/torvalds/linux/blob/master/.clang-format
#
# SPDX-License-Identifier: GPL-2.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we include with GPL-2.0 license?

Copy link
Member

Choose a reason for hiding this comment

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

No - we need dual license or one usable with BSD., such as MIT.

@shefty
Copy link
Member

shefty commented Mar 2, 2023

Let's leave this as-is and discuss in next week's ofiwg call to get more input.

@shefty shefty changed the title Clang Format core: Add coding style enforcement and update selected code areas Mar 2, 2023
@sydidelot
Copy link
Member

sydidelot commented Mar 3, 2023

I think the long term benefits of not wasting time on style comments outweigh the temporary pain of a few hard re-bases.

Mon opinion probably doesn't matter much, but the fact that the PR breaks cherry-picking is definitely a big concern. It's not only about "a few rebases" as you say.

  • Backporting hotfixes becomes difficult after your PR. When I find a bug in Libfabric, my first reaction is usually to check if a newer version of libfabric has a fix and backport it if possible. Updating to a newer version of Libfabric is not always an option.
  • Git blame doesn't give you the original author/commit for a given line. (yes, I find git blame/log really useful and a good source of documentation)

If your concern is about detecting coding style issues during reviews, why not implement a GitHub action that would do a quick check on the lines changed by the PR when it's submitted?

@j-xiong
Copy link
Contributor

j-xiong commented Mar 3, 2023

I agree with @sydidelot and @shefty. Furthermore, I don't think giving formatting comments at reviewing time is a bad thing. It helps people proactively adopt the recommended coding style instead of relying on automatic tools.

@shefty
Copy link
Member

shefty commented Mar 7, 2023

From the ofiwg: There's not support for widespread updates to the code formatting. People are okay with having a check per PR to verify the formatting, as long as we can ignore the results and still commit changes. (So, we don't end up with weird formatting trying to force a coding style on part of a function that has a different style.)

@a-szegel
Copy link
Contributor Author

a-szegel commented Mar 8, 2023

Can I get rid of the formatting commit and keep the CI + the file? What do we want to do about the license?

@shefty
Copy link
Member

shefty commented Mar 8, 2023

Yes, the consensus was that that would be acceptable. We would need a new version of the file without the GPL only license, which means creating our own, basically from scratch, unless you can find another project or base template that's usable.

@shefty
Copy link
Member

shefty commented Mar 8, 2023

We can generate a template format file using a command similar to this:

clang-format -style=llvm -dump-config > ~/tmp/.clang-format

There are a few options for -style, but I don't know which one is the closest to what we want as a starting point: llvm, gnu, mozilla, google, etc.

We could start with a fairly minimal set and expand as needed.

@a-szegel
Copy link
Contributor Author

I am going to make SM2 the first provider to follow these rules.... Will re-open this when I am ready

@a-szegel a-szegel closed this Mar 13, 2023
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.

None yet

5 participants