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

Fix all clang-tidy warnings #340

Merged
merged 11 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# - hicpp-deprecated-headers,modernize-deprecated-headers
# - hicpp-use-nullptr,modernize-use-nullptr

# Reasons for disabling certain checks:
# - llvm-header-guard: Giving false positives, either because of the copyright lines or because we're using #pragma once
# - performance-no-int-to-ptr,cppcoreguidelines-pro-type-cstyle-cast: HAL library relies on int to ptr conversions heavily

Checks: >
bugprone-*,
-bugprone-easily-swappable-parameters,
Expand All @@ -24,6 +28,7 @@ Checks: >
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-narrowing-conversions,
-cppcoreguidelines-pro-type-cstyle-cast,
google-*,
-google-readability-todo,
-google-readability-braces-around-statements,
Expand All @@ -42,13 +47,15 @@ Checks: >
-hicpp-use-equals-default,
llvm-*,
-llvm-else-after-return,
-llvm-header-guard,
misc-*,
-misc-non-private-member-variables-in-classes,
modernize-*,
-modernize-use-trailing-return-type,
-modernize-avoid-c-arrays,
-modernize-macro-to-enum,
performance-*,
-performance-no-int-to-ptr,
portability-*,
readability-*,
-readability-magic-numbers,
Expand Down
113 changes: 95 additions & 18 deletions .github/workflows/merge-criteria.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ jobs:

echo "$filtered_array"
echo "matrix=$filtered_array" >> "$GITHUB_OUTPUT"

outputs:
matrix: ${{ steps.changed-files-filtered.outputs.matrix }}

format_check:
if: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
name: Format Check
needs: generate_matrix
strategy:
fail-fast: false
matrix:
matrix:
project: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
runs-on: ubuntu-latest

Expand All @@ -67,57 +67,134 @@ jobs:
check-path: '${{ matrix.project }}/src'
exclude-regex: '(lib|telemetry/src/st|ground_station/src/format)'

build:
build_lint:
if: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
needs: [generate_matrix, format_check]
name: Build + Lint
name: '[Ubuntu] Build + Lint'
# We are linting on Ubuntu because the linter seems to work better on Linux
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Check cache
uses: actions/cache@v3
with:
path: ~/.platformio/.cache
# Add OS to key if testing with multiple OSes
key: ${{ matrix.project }}-pio

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.9'
cache: 'pip'

- name: Install dependencies
run: pip install --upgrade platformio

- name: Install PlatformIO Libraries
run: pio pkg install --global

- name: Build
shell: bash
run: |
if [[ "${{ matrix.project }}" == "flight_computer" ]]; then
platformio run -d ${{ matrix.project }} --environment debug
else
platformio run -d ${{ matrix.project }}
fi

- name: Generate compile_commands.json
run: |
if [[ "${{ matrix.project }}" == "flight_computer" ]]; then
platformio run -d ${{ matrix.project }} --target compiledb --environment debug
else
platformio run -d ${{ matrix.project }} --target compiledb
fi

- name: Lint
working-directory: ./${{ matrix.project }}
run: |
if [[ "${{ matrix.project }}" == "flight_computer" ]]; then
output=$(platformio check --environment debug)
else
output=$(platformio check)
fi

echo "$output"

echo "Note: Warnings 'clang-diagnostic-c++17-extensions' and 'clang-analyzer-valist.Uninitialized' are excluded from checking since they seem to be false-positives. Fix everything else!"

# filter the output to exclude false positives
filtered_output=$(echo "$output" | grep -vE 'clang-diagnostic-c\+\+17-extensions|clang-analyzer-valist.Uninitialized')

if echo "$filtered_output" | grep -q "warning"; then
echo "clang-tidy check failed!"
exit 1
fi

- name: Upload Compile Commands
uses: actions/upload-artifact@v3
with:
name: ubuntu_compile_commands
path: |
./${{ matrix.project }}/.pio/build/**/compile_commands.json
if-no-files-found: error
retention-days: 90

build_upload:
stojadin2701 marked this conversation as resolved.
Show resolved Hide resolved
if: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
needs: [generate_matrix, format_check]
name: '[Windows] Build + Upload'
# We are running this on windows because the users get binaries compiled on windows.
# The code should also be tested in a linux build.
runs-on: windows-latest
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
matrix:
project: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Check cache
uses: actions/cache@v3
with:
path: ~/.platformio/.cache
# Add OS to key if testing with multiple OSes
key: ${{ matrix.project }}-pio

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.9'
cache: 'pip'

- name: Install dependencies
run: pip install --upgrade platformio

- name: Install PlatformIO Libraries
run: pio pkg install --global

- name: Build
shell: bash
run: |
platformio run -d ${{ matrix.project }}
if [[ "${{ matrix.project }}" == "ground_station" ]]; then
python ${{ matrix.project }}/uf2_loader.py ${{ matrix.project }}/.pio/build/esp32-s2-saola-1/firmware
python ${{ matrix.project }}/uf2_loader.py ${{ matrix.project }}/.pio/build/ground_station/firmware
fi

- name: Generate compile_commands.json
run: platformio run -d ${{ matrix.project }} --target compiledb

- name: Lint
working-directory: ./${{ matrix.project }}
run: platformio check


- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion flight_computer/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ check_src_filters =
build_unflags=-fno-rtti

build_flags =
-D FIRMWARE_VERSION='"3.0.1"'
-D FIRMWARE_VERSION='"3.0.2"'
-D ARM_MATH_CM4
-D ARM_MATH_MATRIX_CHECK
-D ARM_MATH_ROUNDING
Expand Down
Loading
Loading