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

Clang format #824

Merged
merged 52 commits into from
Jun 19, 2022
Merged

Clang format #824

merged 52 commits into from
Jun 19, 2022

Conversation

2bndy5
Copy link
Member

@2bndy5 2bndy5 commented Jan 22, 2022

This PR is designed to enforce uniform code style using clang-format. The style rules that clang-format adheres to are defined in the .clang-format files.

While modifying the CI workflows to check code format, I added a new action that will report compile size changes when the PR is open or re-opened. The reports come in the form of thread comments (see below), and they only focus on Arduino Nano, ATTinyx5, and Arduino MKR Zero. This solves #802

There are 2 .clang-format files:

  1. The .clang-format at root of the repo specifies the style rules used for all C/C++ files in the repo except for the BCM2xxx lib source code (in utility/RPi) and the examples directory (& its sub-directories) - it is used for Linux and Pico SDK examples.
  2. The .clang-format located in examples directory specifies the style rules for all Arduino/PlatformIO examples.

Using the cpp-linter-action

For now I have the action setup to check all source code in the repo. This could be changed to only check the the event's diff for code style violations. This decision is entirely dependent on preference and checking only the diff will yield slightly faster CI runs (like 2 or 3 seconds faster).

  • Linux CI workflow will not check Arduino/PlatformIO examples.
    • Please note that the utility/RPi/bcm2835.* files are ignored since that code is not maintained here (only distributed from here).
  • Arduino/PlatformIO CI workflows will only check the examples' code (not the lib's code).
    • Please note that the examples/old_backups directory is ignored by the action (mainly because those examples aren't compiled in the CI workflows).

As of right now, the action is configured to use clang-format v12 since that was the latest stable version available via apt and LLVM releases at the initial creation of this branch. Note that by default sudo apt install clang-format installs clang-format v10 (use sudo apt install clang-format-12).

For those of you using VSCode, there is a handy extension that formats source code using the locally installed clang-format; I used this extension to make the most of changes in this PR. There are other officially endorsed IDE integrations which are named in the LLVM docs.

Going Forward

I plan to create a repo for the nRF24 org (called .github - see github docs about org profiles)

  • This new repo will be the home for any files that are not specific to any particular code in the org's repos/libs, namely CONTRIBUTING.md.

  • I will begin writing up a code style guideline there, so that the style rules defined in the .clang-format files are explicitly explained.

  • Potentially, the .github repo could also contain re-usable CI workflows/actions. This is more of a long-term goal though.

    In researching this further I found that only workflows that don't use a job matrix can call reusable workflows. This means that only the docs CI could be made into a reusable workflow from the .github repo.

Lastly I found and fixed a dead link in CONTRIBUTING.md to the Arduino example style guide.

@github-actions
Copy link
Contributor

Memory usage change @ 51da30e

Board flash % RAM for global variables %
ATTinyCore:avr:attinyx5 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:nano 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrzero 🔺 0 - +4 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table
Board examples/rf24_ATTiny/rf24ping85
flash
% examples/rf24_ATTiny/rf24ping85
RAM for global variables
% examples/rf24_ATTiny/timingSearch3pin
flash
% examples/rf24_ATTiny/timingSearch3pin
RAM for global variables
% examples/GettingStarted
flash
% examples/GettingStarted
RAM for global variables
% examples/AcknowledgementPayloads
flash
% examples/AcknowledgementPayloads
RAM for global variables
% examples/ManualAcknowledgements
flash
% examples/ManualAcknowledgements
RAM for global variables
% examples/StreamingData
flash
% examples/StreamingData
RAM for global variables
% examples/MulticeiverDemo
flash
% examples/MulticeiverDemo
RAM for global variables
% examples/InterruptConfigure
flash
% examples/InterruptConfigure
RAM for global variables
% examples/scanner
flash
% examples/scanner
RAM for global variables
%
ATTinyCore:avr:attinyx5 0 0.0 0 0.0 0 0.0 0 0.0
arduino:avr:nano 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:samd:mkrzero 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 4 0.0 0 0.0
Click for full report CSV
Board,examples/rf24_ATTiny/rf24ping85<br>flash,%,examples/rf24_ATTiny/rf24ping85<br>RAM for global variables,%,examples/rf24_ATTiny/timingSearch3pin<br>flash,%,examples/rf24_ATTiny/timingSearch3pin<br>RAM for global variables,%,examples/GettingStarted<br>flash,%,examples/GettingStarted<br>RAM for global variables,%,examples/AcknowledgementPayloads<br>flash,%,examples/AcknowledgementPayloads<br>RAM for global variables,%,examples/ManualAcknowledgements<br>flash,%,examples/ManualAcknowledgements<br>RAM for global variables,%,examples/StreamingData<br>flash,%,examples/StreamingData<br>RAM for global variables,%,examples/MulticeiverDemo<br>flash,%,examples/MulticeiverDemo<br>RAM for global variables,%,examples/InterruptConfigure<br>flash,%,examples/InterruptConfigure<br>RAM for global variables,%,examples/scanner<br>flash,%,examples/scanner<br>RAM for global variables,%
ATTinyCore:avr:attinyx5,0,0.0,0,0.0,0,0.0,0,0.0
arduino:avr:nano,,,,,,,,,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:samd:mkrzero,,,,,,,,,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,4,0.0,0,0.0

@nRF24 nRF24 deleted a comment from github-actions bot Jan 22, 2022
@2bndy5 2bndy5 marked this pull request as ready for review January 22, 2022 22:39
@2bndy5 2bndy5 linked an issue Jan 26, 2022 that may be closed by this pull request
@2bndy5 2bndy5 requested review from TMRh20 and Avamander June 17, 2022 01:13
Copy link
Member

@TMRh20 TMRh20 left a comment

Choose a reason for hiding this comment

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

Quite a bit of changes to review here, but I guess most if it is formatting changes. Looks good from what I can see so far...

@2bndy5
Copy link
Member Author

2bndy5 commented Jun 17, 2022

Yeah, its all white space changes and some CI upgrades. I just wanted your sign off on the style because these changes will validate a consistent code style going forward (clang-format can be rather picky).

@Avamander I know we haven't heard much from you lately, but if you wanted to review before merging, let me know. I mention this because you've expressed significant interest about code style in the past.

Once this is merged, I'll open similar PRs for the other nRF24 repos...

Copy link
Member

@Avamander Avamander left a comment

Choose a reason for hiding this comment

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

Yeah, I've been a bit busy. These changes look good.

@2bndy5 2bndy5 merged commit 031954d into master Jun 19, 2022
@2bndy5 2bndy5 deleted the clang-format branch June 19, 2022 11:26
@2bndy5 2bndy5 mentioned this pull request Jun 20, 2022
TMRh20 pushed a commit that referenced this pull request Jun 21, 2022
* revert 1 line conditions, loops, & case labels

* avoid duplicate builds for reported boards

* missed a case label
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 CI workflow that compares changes in code-size
3 participants