From 3c461ca5ccf1b0ae2b9164feced96a5aa4998555 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh <8762862+adeebshihadeh@users.noreply.github.com> Date: Fri, 19 Jun 2020 20:39:34 -0700 Subject: [PATCH] Add cppcheck as a pre-commit hook (#1646) * add cppcheck as a pre-commit hook * fix Dockerfile * update precommit config * exclude panda and opendbc --- .github/workflows/test.yaml | 14 +------------- .gitignore | 1 - .pre-commit-config.yaml | 13 +++++++++++++ Dockerfile.openpilot | 1 - cppcheck_openpilot.sh | 4 ---- selfdrive/ui/sidebar.cc | 2 +- 6 files changed, 15 insertions(+), 20 deletions(-) delete mode 100755 cppcheck_openpilot.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index dc061610..4f6bb66d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,7 +37,7 @@ jobs: external/bin selfdrive/modeld/runners $TEST_DIR # need these so docker copy won't fail - cp Pipfile Pipfile.lock .pylintrc cppcheck_openpilot.sh .coveragerc-app .pre-commit-config.yaml $TEST_DIR + cp Pipfile Pipfile.lock .pylintrc .coveragerc-app .pre-commit-config.yaml $TEST_DIR cd $TEST_DIR mkdir laika laika_repo tools release - name: Build Docker image @@ -96,18 +96,6 @@ jobs: run: eval "$BUILD" - name: pre-commit run: $RUN "cd /tmp/openpilot/ && git init && git add -A && pre-commit run --all" - - name: cppcheck - run: $PERSIST "cd /tmp/openpilot/ && ./cppcheck_openpilot.sh 2> cppcheck_report.txt" - - name: Print cppcheck report - if: always() - run: | - docker cp tmppilot:/tmp/openpilot/cppcheck_report.txt cppcheck_report.txt - cat cppcheck_report.txt - - uses: actions/upload-artifact@v2 - if: always() - with: - name: cppcheck_report.txt - path: cppcheck_report.txt unit_tests: name: unit tests diff --git a/.gitignore b/.gitignore index fb1cbfc0..31ced88c 100644 --- a/.gitignore +++ b/.gitignore @@ -59,7 +59,6 @@ openpilot-apks .coverage* coverage.xml -cppcheck_report.txt htmlcov pandaextra diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af18f795..491d5fb4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,3 +31,16 @@ repos: language: system types: [python] exclude: '^(pyextra)|(external)|(cereal)|(rednose)|(panda)|(laika)|(laika_repo)|(rednose_repo)/' +- repo: local + hooks: + - id: cppcheck + name: cppcheck + entry: cppcheck + language: system + types: [c++] + exclude: '^(phonelibs)|(external)|(cereal)|(opendbc)|(panda)|(tools)|(selfdrive/modeld/thneed/debug)|(selfdrive/modeld/test)|(selfdrive/camerad/test)/' + args: + - --error-exitcode=1 + - --quiet + - --force + - -j8 diff --git a/Dockerfile.openpilot b/Dockerfile.openpilot index ec4ee189..71827ae9 100644 --- a/Dockerfile.openpilot +++ b/Dockerfile.openpilot @@ -77,7 +77,6 @@ RUN pyenv install 3.8.2 && \ RUN mkdir -p /tmp/openpilot COPY SConstruct \ - cppcheck_openpilot.sh \ .pylintrc \ .pre-commit-config.yaml \ .coveragerc-app \ diff --git a/cppcheck_openpilot.sh b/cppcheck_openpilot.sh deleted file mode 100755 index 6f652080..00000000 --- a/cppcheck_openpilot.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -cppcheck --force -j$(nproc) selfdrive/ common/ opendbc/ cereal/ installer/ 2> cppcheck_report.txt - diff --git a/selfdrive/ui/sidebar.cc b/selfdrive/ui/sidebar.cc index 5d75a9bb..890ea7e7 100644 --- a/selfdrive/ui/sidebar.cc +++ b/selfdrive/ui/sidebar.cc @@ -136,7 +136,7 @@ static void ui_draw_sidebar_temp_metric(UIState *s) { } static void ui_draw_sidebar_panda_metric(UIState *s) { - int panda_severity; + int panda_severity = 2; char panda_message_str[32]; const int panda_y_offset = 32 + 148;