Skip to content

Commit

Permalink
CI: check the coding style of bpf programs
Browse files Browse the repository at this point in the history
The project, as stated in CONTRIBUTING have a strong preference for
the Linux kernel coding style.
This patch enforces it by adding automatic checks in the CI for bpf
sources.
The patch uses and import the current checkpatch.pl and its
requirement spelling.txt.

Signed-off-by: Paolo Valerio <[email protected]>
  • Loading branch information
vlrpl committed Jan 30, 2025
1 parent 80bec99 commit 298d82b
Show file tree
Hide file tree
Showing 6 changed files with 9,599 additions and 6 deletions.
18 changes: 17 additions & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,23 @@ unittest_task:
image: rust:bookworm
build_script: make V=1 CARGO_OPTS=--verbose
test_script: make test V=1 CARGO_OPTS=--verbose
check_script:
ebpf_style_script: |
# same as checkpatch for git output
# this will also makes perl happy.
export LANGUAGE=en_US.UTF-8; export LC_ALL=en_US.UTF-8
git remote update origin
cirrus_base=$(git merge-base origin/$CIRRUS_BASE_BRANCH HEAD)
COMMIT_RANGE=$(git rev-list ${cirrus_base}..HEAD --reverse)
for commit in $COMMIT_RANGE; do
pretty_commit=$(git -P show -s --format="%h (\"%s\")" --abbrev=12 ${commit})
echo "Commit ${pretty_commit}"
printf -- '-%0.s' $(seq 1 ${#pretty_commit})
echo "-------"
git show --format=email ${commit} -- '*/bpf/*' | ./tools/checkpatch.pl --no-tree --ignore=SPDX_LICENSE_TAG,FILE_PATH_CHANGES,EMAIL_SUBJECT,VOLATILE -q || { restyle=1 ; true ; }
echo
done
[ -z "${restyle}" ]
rust_check_script:
- cargo fmt --check
- cargo clippy -- -D warnings

Expand Down
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
vmlinux.h linguist-vendored
**/bpf_sys/include/linux/*.h linguist-vendored
*_uapi.rs linguist-vendored
tools/checkpatch.pl linguist-vendored
tools/spelling.txt linguist-vendored
tools/const_structs.checkpatch linguist-vendored
11 changes: 6 additions & 5 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ and/or [help wanted](https://github.com/retis-org/retis/issues?q=is%3Aissue+is%3

### Coding style

We strictly follow the Rust coding style as enforced by `rustfmt` and have a
strong preference for the
[Linux kernel](https://www.kernel.org/doc/html/latest/process/coding-style.html)
and particularly its
We strictly follow the Rust coding style as enforced by `rustfmt` and we also adhere the
[Linux kernel](https://www.kernel.org/doc/html/latest/process/coding-style.html) coding style
as enforced by `checkpatch.pl` and particularly its
[networking](https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html#multi-line-comments)
flavor coding style for the BPF parts.
flavor for the BPF parts. `checkpatch.pl` can generate false
positives, and in such case the formerly described coding style rules
take precedence over its suggestions.

### Events and Rust bindings

Expand Down
Loading

0 comments on commit 298d82b

Please sign in to comment.