Skip to content

Commit f40f081

Browse files
committed
Issue #10: Implement Code Style and Static Code Analyse check
1 parent 9375f80 commit f40f081

File tree

11 files changed

+248
-48
lines changed

11 files changed

+248
-48
lines changed

.clang-format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BasedOnStyle: Google
2+
IndentWidth: 4
3+
ColumnLimit: 120
4+
Language: Cpp

.clang-tidy

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Checks: >
2+
google-*,
3+
clang-analyzer-*,
4+
modernize-*,
5+
readability-*,
6+
performance-*,
7+
cert-*,
8+
concurrency-*,
9+
misc-*,
10+
portability-*,
11+
cppcoreguidelines-*,
12+
misc-definitions-in-headers,
13+
-modernize-use-trailing-return-type,
14+
-cppcoreguidelines-pro-bounds-pointer-arithmetic
15+
16+
17+
CheckOptions:
18+
- key: readability-identifier-naming.ClassCase
19+
value: CamelCase # Classes should use CamelCase
20+
21+
- key: readability-identifier-naming.StructCase
22+
value: CamelCase # Structs should use CamelCase
23+
24+
- key: readability-identifier-naming.EnumCase
25+
value: CamelCase # Enums should use CamelCase
26+
27+
- key: readability-identifier-naming.EnumConstantCase
28+
value: CamelCase
29+
- key: readability-identifier-naming.EnumConstantPrefix
30+
value: k # Google style: kEnumValue
31+
32+
- key: readability-identifier-naming.FunctionCase
33+
value: CamelCase # Google style: Functions use CamelCase, not camelCase
34+
35+
- key: readability-identifier-naming.VariableCase
36+
value: lower_case # Google style: snake_case for variables
37+
38+
- key: readability-identifier-naming.MemberCase
39+
value: lower_case # Google style: snake_case for member variables
40+
41+
- key: readability-identifier-naming.MemberSuffix
42+
value: _ # Google style: member variables have trailing underscore
43+
44+
- key: readability-identifier-naming.PrivateMemberSuffix
45+
value: _ # Private members have underscore suffix in Google style
46+
47+
- key: readability-identifier-naming.GlobalVariableCase
48+
value: lower_case # Global variables use snake_case
49+
50+
- key: readability-identifier-naming.GlobalConstantCase
51+
value: CamelCase
52+
- key: readability-identifier-naming.GlobalConstantPrefix
53+
value: k # Google style: kCamelCase
54+
55+
- key: readability-identifier-naming.StaticVariableCase
56+
value: lower_case # Static variables use snake_case
57+
58+
- key: readability-identifier-naming.StaticConstantCase
59+
value: CamelCase
60+
- key: readability-identifier-naming.StaticConstantPrefix
61+
value: k # Static constants use kCamelCase
62+
63+
- key: readability-identifier-naming.ConstantCase
64+
value: CamelCase
65+
- key: readability-identifier-naming.ConstantPrefix
66+
value: k # Constants use kCamelCase
67+
68+
- key: readability-identifier-naming.MacroCase
69+
value: UPPER_CASE # Macros use UPPER_CASE
70+
71+
- key: readability-identifier-naming.TypedefCase
72+
value: CamelCase # Typedefs use CamelCase
73+
74+
- key: readability-identifier-naming.NamespaceCase
75+
value: lower_case # Namespaces use snake_case
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: C++ Code Style and Static Analysis
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
7+
jobs:
8+
check-cs:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
checks: write
13+
packages: read
14+
container: ghcr.io/kpi-rover/kpi-rover-bbb-check:latest
15+
steps:
16+
- name: Checkout Code with Submodules
17+
uses: actions/checkout@v3
18+
with:
19+
submodules: recursive
20+
fetch-depth: 0
21+
22+
- name: Configure CMake
23+
run: cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B build/check
24+
25+
- name: Verify compile_commands.json exists
26+
run: ls build/check/compile_commands.json
27+
28+
- name: Run Clang-Format
29+
id: clang-format
30+
run: find src/kpi_rover_ecu/ -name '*.cpp' -o -name '*.h' | xargs --no-run-if-empty clang-format --dry-run --Werror
31+
32+
- name: Run Clang-Tidy
33+
id: clang-tidy
34+
run: find src/kpi_rover_ecu/ -name '*.cpp' -o -name '*.h' | xargs --no-run-if-empty clang-tidy -p=build/check --warnings-as-errors='*'

README.md

Lines changed: 63 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
For the first time, the Beaglebone board should be prepared. Please refer to the section [Preparing Beaglebone Blue Board](#Preparing-Beaglebone-Blue-Board).
44

5-
## Communication between BBB and ROS2
6-
![BBB2ROS](./docs/BBB2ROS.png)
5+
## Build project and deploy on BBB
76

8-
## Download Source Code
7+
### Download Source Code
98
```
109
git clone --recurse-submodules [email protected]:KPI-Rover/ecu_sw_bb.git
1110
cd ecu_sw_bb
@@ -18,6 +17,67 @@ git submodule init
1817
git submodule update
1918
```
2019

20+
### Build Docker Image
21+
```
22+
docker build -t kpi-rover-bbb-build -f docker/Dockerfile.build .
23+
24+
docker build -t kpi-rover-bbb-check -f docker/Dockerfile.check .
25+
```
26+
27+
### Build application using Docker
28+
```bash
29+
./build.sh
30+
```
31+
32+
### Upload binary file to Beaglebone Blue
33+
```bash
34+
export BBB_HOST=debian@<BeagleBone Blue IP>
35+
./deploy.sh
36+
```
37+
38+
## Run software on BBB
39+
40+
### Connect to board using SSH
41+
Using USB over network
42+
43+
```
44+
45+
password: temppwd
46+
```
47+
48+
If you set wireless interface
49+
50+
```
51+
ssh debian@<bbb_local_ip>:~
52+
password: temppwd
53+
```
54+
55+
### Run program
56+
```
57+
./kpi_rover_ecu -a 0.0.0.0 -p 6000
58+
```
59+
## Code Style Check and Static Code Analysis
60+
61+
### Importance
62+
Consistent code style and static code analysis are essential for maintaining high-quality software:
63+
- **Code Readability**: Consistent style makes code easier to read and understand for all team members
64+
- **Error Prevention**: Static analysis helps identify potential bugs, memory leaks, and undefined behavior before runtime
65+
- **Maintainability**: Standardized code is easier to maintain and extend over time
66+
- **Collaboration**: Unified coding conventions improve team collaboration and onboarding process
67+
68+
### Standards
69+
This project follows the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html), which provides comprehensive guidelines for C++ coding conventions.
70+
71+
### Continuous Integration
72+
GitHub CI is configured to automatically verify code style and perform static analysis on each Pull Request. PRs failing these checks cannot be merged until issues are resolved, ensuring code quality standards are maintained throughout the development process.
73+
74+
### Local Verification
75+
To check code style and run static analysis locally before committing:
76+
```bash
77+
./check_cs.sh
78+
```
79+
This script will identify any style violations or potential issues in your code, allowing you to fix them before pushing your changes.
80+
2181
## Preparing Beaglebone Blue Board
2282

2383
### Download and flash image
@@ -132,46 +192,6 @@ sudo systemctl enable robotcontrol
132192
sudo systemctl start robotcontrol
133193
```
134194

135-
## Build of project and loading on BBB
136-
137-
### Build Docker Image
138-
```
139-
docker build -t kpi-rover-bbb .
140-
```
141-
142-
### Build application using Docker
143-
```bash
144-
./build.sh
145-
```
146-
147-
### Upload binary file to Beaglebone Blue
148-
```bash
149-
export BBB_HOST=debian@<BeagleBone Blue IP>
150-
./deploy.sh
151-
```
152-
153-
## Running
154-
155-
### Connect to board using SSH
156-
Using USB over network
157-
158-
```
159-
160-
password: temppwd
161-
```
162-
163-
If you set wireless interface
164-
165-
```
166-
ssh debian@<bbb_local_ip>:~
167-
password: temppwd
168-
```
169-
170-
### Run program
171-
```
172-
./kpi_rover_ecu -a 0.0.0.0 -p 6000
173-
```
174-
175195
## Fixing probable issues while debugging or testing
176196

177197
If server started on 192.168.7.2 :

build.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#!/bin/bash
22

3+
# Ensure build directory exists
4+
mkdir -p build/target
5+
36
# Check if the "nocache" argument is passed
47
if [[ "$1" == "nocache" ]]; then
58
echo "-- Clearing CMake cache..."
6-
rm -rf build/*
9+
rm -rf build/target/*
710
fi
811

912
# Run the Docker container with CMake commands
1013
docker run -it --rm \
1114
-u $(id -u ${USER}):$(id -g ${USER}) \
12-
-v $(pwd):/work \
13-
kpi-rover-bbb \
14-
bash -c "cmake -B build -H. && cmake --build build -- -j$(nproc)"
15+
-v $(pwd):/workspace \
16+
kpi-rover-bbb-build \
17+
bash -c "cmake -B build/target -H. && cmake --build build/target -- -j$(nproc)"

check_cs.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
docker run -it --rm \
4+
-u $(id -u ${USER}):$(id -g ${USER}) \
5+
-v $(pwd):/workspace \
6+
kpi-rover-bbb-check \
7+
bash -c "
8+
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B build/check && ls build/check/compile_commands.json && \
9+
find src/kpi_rover_ecu/ -name '*.cpp' -o -name '*.h' | xargs --no-run-if-empty clang-format --dry-run --Werror; \
10+
find src/kpi_rover_ecu/ -name '*.cpp' -o -name '*.h' | xargs --no-run-if-empty clang-tidy -p=build/check --warnings-as-errors='*'
11+
"
12+

Dockerfile renamed to docker/Dockerfile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ ENV AS=/usr/bin/arm-linux-gnueabihf-as \
2424

2525
RUN echo "alias ll='ls -alF --color=auto'" >> /etc/bash.bashrc
2626

27-
WORKDIR /work
27+
WORKDIR /workspace

docker/Dockerfile.check

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#######################################################
2+
# Dockerfile for the Beaglebone blue cross compilation
3+
#######################################################
4+
5+
FROM ubuntu:24.04
6+
7+
RUN apt-get update -q && \
8+
apt-get install -y -q \
9+
gcc-arm-linux-gnueabihf \
10+
g++-arm-linux-gnueabihf \
11+
clang-format \
12+
clang-tidy \
13+
cppcheck \
14+
python3 \
15+
python3-pip \
16+
cmake \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
# RUN ln -s /usr/bin/arm-linux-gnueabihf-g++-8 /usr/bin/arm-linux-gnueabihf-g++ && \
20+
# ln -s /usr/bin/arm-linux-gnueabihf-gcc-8 /usr/bin/arm-linux-gnueabihf-gcc && \
21+
# ln -s /usr/bin/arm-linux-gnueabihf-cpp-8 /usr/bin/arm-linux-gnueabihf-cpp
22+
23+
ENV AS=/usr/bin/arm-linux-gnueabihf-as \
24+
AR=/usr/bin/arm-linux-gnueabihf-ar \
25+
CC=/usr/bin/arm-linux-gnueabihf-gcc \
26+
CPP=/usr/bin/arm-linux-gnueabihf-cpp \
27+
CXX=/usr/bin/arm-linux-gnueabihf-g++ \
28+
LD=/usr/bin/arm-linux-gnueabihf-ld
29+
30+
RUN echo "alias ll='ls -alF --color=auto'" >> /etc/bash.bashrc
31+
32+
RUN apt-get update -q && \
33+
apt-get install -y -q \
34+
git \
35+
&& rm -rf /var/lib/apt/lists/*
36+
37+
WORKDIR /workspace

docs/architecture.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Communication between BBB and ROS2
2+
![BBB2ROS](BBB2ROS.png)

external/.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DisableFormat: true

0 commit comments

Comments
 (0)