Skip to content

Commit a92b85f

Browse files
geurtoJelmerdw
andauthored
227 workflow add checks on cpp documentation (#313)
* added doxygen for linting C++ code. Signed-off-by: Peter Geurts <peter.geurts@proton.me> * added doxygen to workflow Signed-off-by: Peter Geurts <peter.geurts@proton.me> * updated documentation Signed-off-by: Peter Geurts <peter.geurts@proton.me> * typo Signed-off-by: Peter Geurts <peter.geurts@proton.me> * added private methods to doxyfile; added documentation to private methods; remove generated Doxygen output folder after script has run Signed-off-by: Peter Geurts <peter.geurts@proton.me> * added .clang-format file for consistent formatting; added additional doc warnings in doxyfile.lint Signed-off-by: Peter Geurts <peter.geurts@proton.me> * added REUSE lines to .clang-format Signed-off-by: Peter Geurts <peter.geurts@proton.me> * changed clang-format style to Google; updated clang-format runner in GH workflows to use modern pip version of clang-format Signed-off-by: Peter Geurts <peter.geurts@proton.me> * Add support for newer clangd version. Signed-off-by: Jelmer de Wolde <jelmer.de.wolde@alliander.com> --------- Signed-off-by: Peter Geurts <peter.geurts@proton.me> Signed-off-by: Jelmer de Wolde <jelmer.de.wolde@alliander.com> Co-authored-by: Jelmer de Wolde <jelmer.de.wolde@alliander.com>
1 parent bbcf97c commit a92b85f

12 files changed

Lines changed: 244 additions & 42 deletions

File tree

.clang-format

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: Alliander N. V.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
Language: Cpp
5+
BasedOnStyle: Google
6+
7+
InsertNewlineAtEOF: true
8+
SeparateDefinitionBlocks: Always
9+
SortIncludes: true
10+
IncludeBlocks: Regroup
11+
KeepEmptyLines:
12+
AtEndOfFile: false
13+
AtStartOfBlock: false
14+
AtStartOfFile: false

.clangd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: Alliander N. V.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
Documentation:
5+
CommentFormat: Doxygen

.devcontainer/docker-compose.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-FileCopyrightText: Alliander N. V.
2-
#
2+
#
33
# SPDX-License-Identifier: Apache-2.0
44

55
services:
@@ -17,13 +17,16 @@ services:
1717
- "/tmp/.X11-unix:/tmp/.X11-unix"
1818
- "${HOME}/.vscode-server:/home/rcdt/.vscode-server"
1919
- "../:/home/rcdt/rcdt_robotics/"
20-
- ../.cache/zed/resources:/usr/local/zed/resources
21-
- ../.cache/zed/settings:/usr/local/zed/settings
2220
- "../.personal.bashrc:/home/rcdt/.personal.bashrc"
2321
- "../.env:/home/rcdt/.env"
2422
- "../pyproject.toml:/home/rcdt/pyproject.toml"
2523
- "../.config:/home/rcdt/.config"
24+
- "../clangd:/home/rcdt/clangd" # Allows to mount a newer clangd version, can be used in VSCode.
2625
- "/dev:/dev"
26+
- "${HOME}/.nix-profile/bin/nvim:/usr/bin/nvim"
27+
- "/nix/store:/nix/store"
28+
- "../.cache/zed/resources:/usr/local/zed/resources"
29+
- "../.cache/zed/settings:/usr/local/zed/settings"
2730
environment:
2831
- "DISPLAY"
2932
- "RCUTILS_COLORIZED_OUTPUT=1"

.github/workflows/linting.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,19 @@ jobs:
3737
runs-on: ubuntu-latest
3838
steps:
3939
- uses: actions/checkout@v4
40-
- run: sudo apt install -y clang-format
41-
- run: find ros2_ws/src -iname '*.h' -o -iname '*.hpp' -o -iname '*.cpp' | xargs clang-format --dry-run --Werror
40+
- run: python3 -m pip install clang-format
41+
- run: find ros2_ws/src -iname '*.h' -o -iname '*.hpp' -o -iname '*.cpp' | xargs clang-format --dry-run --Werror --style=file
42+
43+
doxygen:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
47+
- run: sudo apt update && sudo apt install -y doxygen
48+
- run: ./doxygen-lint.sh
4249

4350
reuse:
4451
runs-on: ubuntu-latest
4552
steps:
4653
- uses: actions/checkout@v4
4754
- name: REUSE Compliance Check
48-
uses: fsfe/reuse-action@v4
55+
uses: fsfe/reuse-action@v4

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ ignore/
2020
.vscode-server
2121

2222
build/
23+
clangd/
2324

2425
.env
2526
!.devcontainer/.env
2627
.cache
2728
.venv
29+
30+
# for LSP in neovim
31+
.clangd-build/
32+
**/compile_commands.json

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ repos:
5151
hooks:
5252
- id: clang-format
5353
types_or: [c++, c, cuda]
54+
- repo: local
55+
hooks:
56+
- id: doxygen
57+
name: doxygen linting
58+
entry: ./doxygen-lint.sh
59+
language: system
60+
pass_filenames: false
5461
- repo: https://github.com/fsfe/reuse-tool
5562
rev: v5.0.2
5663
hooks:

dockerfiles/install_scripts/dev_packages.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ source /home/$UNAME/.bashrc
99
apt update
1010

1111
apt install -y \
12-
ros-$ROS_DISTRO-nmea-navsat-driver
12+
clang \
13+
doxygen \
14+
ros-$ROS_DISTRO-nmea-navsat-driver

docs/content/workflows.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Checks all files in this repository on usage of copyright terms.
2727
- **Ty**:\
2828
Runs static type checks on our Python code using [Ty](https://github.com/astral-sh/ty).
2929

30+
- **doxygen**:\
31+
Runs code documentation checks for .cpp, .hpp, and .h files, using the rules specified in *doxyfile.lint*. In the future, other filetypes may be added as well.
32+
3033
### Local Development
3134

3235
You can run these checks locally before committing by using the [`pre-commit`](https://pre-commit.com/) framework:

doxyfile.lint

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-FileCopyrightText: Alliander N. V.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
PROJECT_NAME = "RCDT Robotics"
5+
6+
INPUT = ros2_ws/src
7+
RECURSIVE = YES
8+
QUIET = YES
9+
10+
WARNINGS = YES
11+
WARN_NO_PARAMDOC = YES
12+
WARN_IF_UNDOC_ENUM_VAL = YES
13+
14+
EXTRACT_PRIVATE = YES
15+
EXTRACT_PRIV_VIRTUAL = YES
16+
EXTRACT_PACKAGE = YES
17+
EXTRACT_STATIC = YES
18+
EXTRACT_LOCAL_CLASSES = YES
19+
20+
# If no output is generated, Doxygen seems to not fully parse documentation.
21+
# This can lead to erroneous warnings that are not present if any type of output is generated.
22+
GENERATE_LATEX = NO
23+
GENERATE_HTML = NO
24+
GENERATE_RTF = YES
25+
26+
FILE_PATTERNS = *.cpp \
27+
*.h \
28+
*.hpp

doxygen-lint.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# SPDX-FileCopyrightText: Alliander N. V.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
FILENAME=doxyfile.lint
7+
8+
if ! command -v doxygen > /dev/null 2>&1 ; then
9+
echo "Doxygen not found, exiting."
10+
exit 1
11+
fi
12+
13+
if [ ! -f $FILENAME ]; then
14+
echo "Doxyfile '$FILENAME' not found, exiting."
15+
exit 1
16+
fi
17+
18+
OUTPUT=$(doxygen $FILENAME /dev/null 2>&1)
19+
NUM_WARNINGS=$(echo "$OUTPUT" | grep -i "warning:" | wc -l)
20+
21+
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
22+
rm -rf $SCRIPT_DIR/rtf/
23+
24+
if [ "$NUM_WARNINGS" -gt 0 ]; then
25+
echo "$OUTPUT"
26+
echo "Doxygen found $NUM_WARNINGS documentation warnings."
27+
exit 1
28+
fi

0 commit comments

Comments
 (0)