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

quality-of-life fixes: clang-format, clang-static-analyzer, pre-commit #351

Closed
wants to merge 30 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Feb 22, 2024

Description of Changes

This introduces a large set of quality-of-life improvements.

    3a5a984 ci(github): run CodeChecker on PRs
    ecedcc0 ci(github): run pre-commit on PRs
    81c9a71 misc(git): introduce .git-blame-ignore-revs
    b40dc51 ci(pre-commit): add actionlint
    99e3f12 style(tree): apply mdformat fixes
    a517e34 ci(pre-commit): add mdformat
    c022660 style(tree): apply clang format changes
    a25887e ci(pre-commit): introduce clang-format
    190df1d ci(pre-commit): add editorconfig file
    8e8adf9 ci(pre-commit): introduce conventional commit hook
    0d59cb3 ci(pre-commit): introduce shellcheck
    46a1f43 style(tree): apply pre-commit whitespace/eol fixes
    e5a2c86 ci(pre-commit): add eof/whitespace checks
    b120d73 ci(pre-commit): introduce pre-commit
  1. Introduces pre-commit hooks which run on every pull request under GitHub
    actions, as well as locally when setup by developers. This can catch a large
    variety of style nits before they reach PR. When attempting to commit a
    violating file, the fix will be automatically made and developers just need
    to restage the file.

    Checker Description
    trailing-whitespace Delete trailing whitespace, also covered by clang-format.
    end-of-file-fixer Ensure that there is a new line at the end of all files.
    check-merge-conflict Looks for strings like ’<<<’ and prevents their commit.
    detect-private-key Looks for anything that looks like a private key and prevents its commit.
    mixed-line-ending Prevents CRLF/LF mixture.
    check-added-large-files Prevents accidental staging of output files
    check-shebang-scripts-are-executable If it has a shebang, it should have +x
    check-symlinks Symlinks should point to a file that is tracked by git.
    check-xml XML should parse.
    shellcheck Runs shellcheck over any executable sh/bash script.
    mdformat Runs mdformat, applies consistent markdown style, and applies fixes to markdown which minimize diffs.
    conventional-pre-commit Enforces the usage of a standardized commit message. This can be used to generate changelogs and helps identify breaking commits.
    clang-format Runs clang-format over the code on each commit. See below section for details.
    actionlint Ensures that all github actions in the repo parse properly.

    The runtime is reasonably acceptable.

        trim trailing whitespace.................................................Passed
        fix end of files.........................................................Passed
        check for merge conflicts................................................Passed
        detect private key.......................................................Passed
        mixed line ending........................................................Passed
        check for added large files..............................................Passed
        check that scripts with shebangs are executable..........................Passed
        check for broken symlinks............................(no files to check)Skipped
        check xml................................................................Passed
        shellcheck...............................................................Passed
        mdformat.................................................................Passed
        clang-format.............................................................Passed
        Lint GitHub Actions workflow files.......................................Passed
        pre-commit run --all-files  9.56s user 4.32s system 322% cpu 4.308 total

If the checks get in your way when making temporary commits, one can always
pass --no-verify to git and run git rebase --interactive origin/master --exec 'pre-commit run --all-files' when preparing for PR.

  1. Introduces a clang-format file to the repository, and makes the style more consistent.

    See commit message of a25887e ci(pre-commit): introduce clang-format for
    details on how the specific style was chosen. To avoid making all git history
    useless as a part of this, .git-blame-ignore-revs is introduced, which can be
    configured locally to hide these commits from git blame. GitHub has support
    for reading this file and hiding it from the blame view, as well.

  2. Introduces static analysis which runs on every pull request under GitHub
    actions. An example run can be found here. This runs cppcheck, clang-tidy,
    and clang-static-analyzer internally via CodeChecker. Note that CodeChecker
    is referenced on the upstream LLVM docs as a replacement for their older
    python scripts and is fully open source. For now, PRs are not blocked on
    reports from these tools. A follow-up PR will fix some of these issues, after
    which, we can remove the remaining warnings that are not useful and fail the
    analyzer when it introduces regressions.

There are several opinionated changes in this PR that need further discussion
and it is marked as WIP for that reason.

@ghost ghost mentioned this pull request Feb 22, 2024
Copy link
Member

@rajachan rajachan left a comment

Choose a reason for hiding this comment

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

High-level comment: While the rules files additions are good, I don't think we should have commits that fix everything in one shot. We can adopt the format rules for subsequent changes and incrementally change parts of code as we touch them, but a blanket fix makes diving into history harder than just git blaming and tracking down changes from there.

@ghost
Copy link
Author

ghost commented Feb 22, 2024

High-level comment: While the rules files additions are good, I don't think we should have commits that fix everything in one shot. We can adopt the format rules for subsequent changes and incrementally change parts of code as we touch them, but a blanket fix makes diving into history harder than just git blaming and tracking down changes from there.

I tried to alleviate some of this pain with .git-blame-ignore-revs, are you saying that you feel it's still too noisy with that configured? Here's blame on ofi_nccl_net.c, for example.

AFAICT, the only case where those listed commits still appear in git blame is where it added lines, eg: with the include reordering, line wrapping, or brace insertion. I agree that it's still more lines than I would like to see.

@bwbarrett
Copy link
Contributor

I don't like whitespace refactoring commits. They break git blame. I'm happy to have filters to make sure we don't screw up whitespace again, but no silly whitespace fixup commits, please.

@@ -0,0 +1,8 @@
# style(tree): apply mdformat fixes
99e3f12c2b09d23369262e4a17912cacab17ee1f
Copy link
Contributor

Choose a reason for hiding this comment

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

nah; we just shouldn't do these commits.

Copy link
Author

Choose a reason for hiding this comment

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

ack, fine with this.

Copy link
Author

Choose a reason for hiding this comment

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

I want to reraise this -- this is a good feature that can help us make changes without clobbering history. I've dropped the application of clang-format on this PR, but I didn't drop all of linters/fixers and some of those are better ignored. Note that github supports this file and blame should work correctly if you go to the top of this page and click the branch, or this link: https://github.com/aws-nslick/aws-ofi-nccl/tree/qol

@AvivBenchorin AvivBenchorin added the BuildTriggerRequest CI build will be triggered when this label is set label Mar 3, 2024
@ghost ghost force-pushed the qol branch 3 times, most recently from 485972d to 6fd60de Compare March 11, 2024 22:25
configure.ac Outdated
@@ -29,6 +30,7 @@ NCCL_NET_OFI_DISTCHCK_CONFIGURE_FLAGS=
# Checks for programs
AC_PROG_CC
m4_version_prereq([2.70], [], [AC_PROG_CC_STDC])
AC_GNU_SOURCE
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not actually sure why we need GNU_SOURCE defined, but I definitely don't want to make it the default.

Copy link
Author

Choose a reason for hiding this comment

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

We definitely need it for asprintf, potentially others.

I agree that we should avoid gnu extensions, but so long as they're already in the codebase, I feel it's more reasonable to commit to compiling with a consistent set of feature macros until we can get back to _POSIX_C_SOURCE >= 200809L compatibility.

Copy link
Author

Choose a reason for hiding this comment

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

I feel strongly that this change is prudent because of potential ABI breakage when files are compiled with different feature test macros.

I also went a step further and removed config.h for the same reason -- we have had bugs in the past few months where files did not include it, or didn't include it at the top, and this solves that for good -- no file is evaluated without bringing those macros into scope.

@AvivBenchorin AvivBenchorin added BuildTriggerRequest CI build will be triggered when this label is set and removed BuildTriggerRequest CI build will be triggered when this label is set labels Mar 12, 2024
@ghost ghost mentioned this pull request Mar 14, 2024
@ghost ghost mentioned this pull request Apr 30, 2024
Nicholas Sielicki added 2 commits May 13, 2024 00:24
prior to this commit, some (but not all) files #define _GNU_SOURCE
individually. Mixing gnu/posix extensions at a per-TU level is a recipe
for disaster, ABI incompabitilities between files in the same project is
never your first guess.

Opt into extensions once and for all at the top for consistency, and
also add AC_LANG([C]) to ensure that the compiler isn't guessing whether
it's a C++ or C source file.
This commits parent set _GNU_SOURCE globally via automake to opt into
gnu extensions for the entire project, rather than directly setting it
inline in several (but not all) files. The rationale behind this was
that conditionally enabling gnu extensions can lead to very hard to
debug issues where different compilation units are using
different (potentially abi incompatible) implementations.

Similarly, not all files in our tree include `config.h' (or in some
cases, TUs were including the file but not placing it at the very top,
which defeats the purpose of eg: feature test macros.)

Our config is ultimately very small (on the order of a dozen or so
"actual" options, well within reasonable command line argument max
length constraints) and can be passed directly in the compiler command
line arguments instead. Do this instead so we don't have to worry about
this footgun.
@ghost ghost force-pushed the qol branch 4 times, most recently from 6e48d60 to 7870ec8 Compare May 13, 2024 09:15
Nicholas Sielicki added 4 commits May 13, 2024 02:33
pre-commit is a tool for composing portable/generic git hooks. Introduce
this to the repository with a small set of base hooks. Update docs with
instructions on how to use it.
Add a pre-commit hook to format yaml files (including pre-commit's
config file.)
Apply yamlfmt to files under .ci and .github. This is split into a
separate commit so that it can be hidden from git blame.
add a pre-commit hook to validate that all github actions in this
repository are properly formatted and don't have common gh action
typos/bugs.
@ghost ghost force-pushed the qol branch 4 times, most recently from ba0d8d3 to 9f2289c Compare May 13, 2024 11:34
Nicholas Sielicki added 14 commits May 13, 2024 04:37
Exclude all unit tests from reporting, and select a handful of checks
that are relevant to this project.
Add a pre-commit hook to run clang-tidy for files under src/ on every
commit.
__builtin_ffsll takes a signed long long, not a uint64_t. Explicitly
cast to `signed long long' before passing it.

Caught with clang tidy.
This is initialized with a signed integer, but assigned to a uint64_t.
Do the initialization math in a uint64_t so that there is no conversion.

Caught with clang tidy.
This adds a generic editorconfig [1] file for the repo to ensure that
CRLF/LF and tabwidth settings are automatically applied when possible,
and adds a pre-commit hook to ensure that it is coherent with the tree.

[1]: https://editorconfig.org
rename the distcheck workflow to pr-ci. Add a second job to the file for
pre-commit, that runs all non-manual pre-commit hooks. Add
workflow_dispatch to the file so it can be triggered manually if desired.
fixes:
`warning: ‘schedule’ may be used uninitialized [-Wmaybe-uninitialized]'

Signed-off-by: Nicholas Sielicki <[email protected]>
use the gh actions cache for apt packages, rather than redownloading
them every time. This should accelerate the build somewhat.
Uploading the artifact with only matrix.cc in the name can cause
collisions when both fail. Upload it as
 `${{ matrix.cc }}-${{ matrix.sdk}}-config.log'
instead so that it is unique.
+ ignore unit tests
+ disable unused parameter warnings.
Add a basic clang-format spec to the repository and a pre-commit hook to
enforce it. Actually formatting the repository by the rules within this
file is split into a separate commit for the sake of doing as much as
possible to keep git-blame clean (via .git-blame-ignore-revs)

This style was chosen with the help of a tool called whatstyle [1].
@a-szegel
Copy link
Contributor

bot:aws:retest

@ghost ghost marked this pull request as ready for review May 15, 2024 04:49
@ghost ghost self-requested a review as a code owner May 15, 2024 04:49
@ghost ghost requested review from rajachan and bwbarrett May 15, 2024 05:02
@ghost ghost mentioned this pull request May 21, 2024
@a-szegel a-szegel removed the BuildTriggerRequest CI build will be triggered when this label is set label Jun 3, 2024
@a-szegel
Copy link
Contributor

a-szegel commented Jun 3, 2024

Please merge master.

@ghost ghost closed this Jul 3, 2024
@ghost ghost mentioned this pull request Dec 13, 2024
@ghost ghost mentioned this pull request Jan 25, 2025
This pull request was closed.
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.

5 participants