From f8ed3f7edba79418c676ad7ea2077ad1db32a3ee Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Tue, 29 Jun 2021 16:58:24 +0200 Subject: [PATCH 01/11] :wrench: (analysis): Add .clang-tidy config file --- .clang-tidy | 98 +++++++++++++++++++++++++++++++++++++++++++ .vscode/settings.json | 6 ++- 2 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000..a7bfe51173 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,98 @@ +# vim: set filetype=yaml: +--- +Checks: " \ + -* \ + , bugprone-assert-side-effect \ + , bugprone-bool-pointer-implicit-conversion \ + , bugprone-branch-clone \ + , bugprone-copy-constructor-init \ + , bugprone-dangling-handle \ + , bugprone-dynamic-static-initializers \ + , bugprone-exception-escape \ + , bugprone-forward-declaration-namespace \ + , bugprone-implicit-widening-of-multiplication-result \ + , bugprone-incorrect-roundings \ + , bugprone-infinite-loop \ + , bugprone-integer-division \ + , bugprone-lambda-function-name \ + , bugprone-macro-parentheses \ + , bugprone-macro-repeated-side-effects \ + , bugprone-misplaced-operator-in-strlen-in-alloc \ + , bugprone-misplaced-pointer-arithmetic-in-alloc \ + , bugprone-misplaced-widening-cast \ + , bugprone-move-forwarding-reference \ + , bugprone-multiple-statement-macro \ + , bugprone-not-null-terminated-result \ + , bugprone-parent-virtual-call \ + , bugprone-redundant-branch-condition \ + , bugprone-signed-char-misuse \ + , bugprone-sizeof-container \ + , bugprone-sizeof-expression \ + , bugprone-string-constructor \ + , bugprone-string-integer-assignment \ + , bugprone-string-literal-with-embedded-nul \ + , bugprone-suspicious-enum-usage \ + , bugprone-suspicious-include \ + , bugprone-suspicious-memset-usage \ + , bugprone-suspicious-missing-comma \ + , bugprone-suspicious-semicolon \ + , bugprone-suspicious-string-compare \ + , bugprone-swapped-arguments \ + , bugprone-terminating-continue \ + , bugprone-too-small-loop-variable \ + , bugprone-undefined-memory-manipulation \ + , bugprone-undelegated-constructor \ + , bugprone-unused-raii \ + , bugprone-unused-return-value \ + , bugprone-use-after-move \ + , bugprone-virtual-near-miss \ + , cppcoreguidelines-avoid-goto \ + , cppcoreguidelines-avoid-non-const-global-variables \ + , cppcoreguidelines-init-variables \ + , cppcoreguidelines-interfaces-global-init \ + , cppcoreguidelines-macro-usage \ + , cppcoreguidelines-narrowing-conversions \ + , cppcoreguidelines-no-malloc \ + , cppcoreguidelines-prefer-member-initializer \ + , cppcoreguidelines-pro-bounds-array-to-pointer-decay \ + , cppcoreguidelines-pro-bounds-constant-array-index \ + , cppcoreguidelines-pro-bounds-pointer-arithmetic \ + , cppcoreguidelines-pro-type-const-cast \ + , cppcoreguidelines-pro-type-cstyle-cast \ + , cppcoreguidelines-pro-type-member-init \ + , cppcoreguidelines-pro-type-reinterpret-cast \ + , cppcoreguidelines-pro-type-static-cast-downcast \ + , cppcoreguidelines-pro-type-union-access \ + , cppcoreguidelines-pro-type-vararg \ + , cppcoreguidelines-slicing \ + , cppcoreguidelines-special-member-functions \ + , google-readability-avoid-underscore-in-googletest-name \ + , google-readability-casting \ + , google-readability-todo \ + , google-upgrade-googletest-case \ + , hicpp-multiway-paths-covered \ + , misc-definitions-in-headers \ + , misc-misplaced-const \ + , misc-non-copyable-objects \ + , misc-non-private-member-variables-in-classes \ + , misc-redundant-expression \ + , misc-static-assert \ + , misc-unconventional-assign-operator \ + , misc-unused-alias-decls \ + , misc-unused-using-decls \ + , modernize-* \ + , readability-* \ + , -readability-convert-member-functions-to-static \ + " + +CheckOptions: + - key: bugprone-misplaced-widening-cast.CheckImplicitCasts + value: true + - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor + value: true + - key: readability-magic-numbers.IgnorePowersOf2IntegerValues + value: true + - key: readability-function-cognitive-complexity.IgnoreMacros + value: true + +HeaderFilterRegex: "" diff --git a/.vscode/settings.json b/.vscode/settings.json index 46f4031888..e996221ba3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,8 @@ { "files.associations": { - "*.orig": "cpp", ".clang-format": "yaml", + ".clang-tidy": "yaml", + "*.orig": "cpp", "any": "cpp", "array": "cpp", "atomic": "cpp", @@ -96,6 +97,7 @@ "--log=verbose", "--completion-style=detailed", "--clang-tidy", - "--clang-tidy-checks=-*,modernize*" + "--header-insertion=never", + "--suggest-missing-includes" ] } From 01547185dea63b765070d82cdcd67ba44dbf7616 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 1 Jul 2021 11:16:59 +0200 Subject: [PATCH 02/11] :hammer: (tools): Symlink compile_commands.json when configuring cmake tools --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0aa7807ec3..75a1d62c79 100644 --- a/Makefile +++ b/Makefile @@ -69,8 +69,6 @@ all: @echo "" @echo "๐Ÿ—๏ธ Building everything! ๐ŸŒˆ" cmake --build $(TARGET_BUILD_DIR) - @rm -rf $(ROOT_DIR)/compile_commands.json - @cp $(TARGET_BUILD_DIR)/compile_commands.json ./ os: @echo "" @@ -126,6 +124,7 @@ config_tools_build: mkdir_tools_config @echo "" @echo "๐Ÿƒ Running cmake configuration script for target $(TARGET_BOARD) ๐Ÿ“" @cmake -S . -B $(CMAKE_TOOLS_BUILD_DIR) -GNinja -DCMAKE_CONFIG_DIR="$(CMAKE_TOOLS_CONFIG_DIR)" -DTARGET_BOARD="$(TARGET_BOARD)" -DCMAKE_BUILD_TYPE=Debug -DENABLE_CODE_ANALYSIS=$(ENABLE_CODE_ANALYSIS) + @ln -sf $(CMAKE_TOOLS_BUILD_DIR)/compile_commands.json ./ # # MARK: - Tests targets @@ -276,6 +275,7 @@ rm_build_all: @echo "โš ๏ธ Cleaning up all build directories ๐Ÿงน" rm -rf $(PROJECT_BUILD_DIR) rm -rf $(CMAKE_TOOLS_BUILD_DIR) + rm -rf ./compile_commands.json rm_config: @echo "" From f94f2a7abebf4f28fde88390fcbbd6f962e5c407 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 1 Jul 2021 11:18:02 +0200 Subject: [PATCH 03/11] :adhesive_bandage: (tools): Fix CMAKE_EXPORT_COMPILE_COMMANDS for clang-tidy When running clang-tidy from the command line, it was not able to find std headers such as chrono, cstddef, etc. This is because the compile database did not have all the include path known to the compiler (arm-none-eabi-g{cc,++}) and therefore clang-tidy was falling back to clang's own includes Fix from: https://gitlab.kitware.com/cmake/cmake/-/issues/20912#note_795673 --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 545e1ae53f..054bf18a6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,10 @@ project(LekaOS LANGUAGES C CXX ASM) # Generate compile commands database set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") +if(CMAKE_EXPORT_COMPILE_COMMANDS) + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) +endif() + # For convenience you can define useful variables set(OS_DIR ${ROOT_DIR}/src) set(LIBS_DIR ${ROOT_DIR}/libs) From 0236c14fa6ba4b3ac171d608799abf1c63c9f80c Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 1 Jul 2021 11:43:29 +0200 Subject: [PATCH 04/11] :construction_worker: (analysis): Add clang-tidy to code analysis workflow --- .clang-tidy | 4 + .github/workflows/ci-code_analysis.yml | 167 ++++++++++++++++++++++--- 2 files changed, 151 insertions(+), 20 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index a7bfe51173..883c12e577 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -96,3 +96,7 @@ CheckOptions: value: true HeaderFilterRegex: "" + +WarningsAsErrors: " \ + modernize-* + " diff --git a/.github/workflows/ci-code_analysis.yml b/.github/workflows/ci-code_analysis.yml index c352cb4cdf..1ed1b5b077 100644 --- a/.github/workflows/ci-code_analysis.yml +++ b/.github/workflows/ci-code_analysis.yml @@ -11,30 +11,30 @@ on: pull_request: types: [opened, synchronize, reopened] -jobs: - sonarcloud: - name: sonarcloud - runs-on: ubuntu-latest +env: + CC: /usr/bin/gcc + CXX: /usr/bin/g++ - env: - CC: /usr/bin/gcc - CXX: /usr/bin/g++ + CCACHE_DIR: /home/runner/work/ccache + CCACHE_COMPRESS: true + CCACHE_COMPRESSLEVEL: 6 - CCACHE_DIR: /home/runner/work/ccache - CCACHE_COMPRESS: true - CCACHE_COMPRESSLEVEL: 6 + ARM_TOOLCHAIN_URL: "https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2" + ARM_TOOLCHAIN_FILENAME: "gcc-arm-none-eabi-*-x86_64-linux.tar.bz2" + ARM_TOOLCHAIN_EXTRACT_DIRECTORY: "gcc-arm-none-eabi-*" - ARM_TOOLCHAIN_URL: "https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2" - ARM_TOOLCHAIN_FILENAME: "gcc-arm-none-eabi-*-x86_64-linux.tar.bz2" - ARM_TOOLCHAIN_EXTRACT_DIRECTORY: "gcc-arm-none-eabi-*" + SONARCLOUD_CLI_URL: "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472.zip" + SONARCLOUD_CLI_FILENAME: "sonar-scanner-cli-*.zip" + SONARCLOUD_CLI_EXTRACT_DIRECTORY: "sonar-scanner-*" - SONARCLOUD_CLI_URL: "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472.zip" - SONARCLOUD_CLI_FILENAME: "sonar-scanner-cli-*.zip" - SONARCLOUD_CLI_EXTRACT_DIRECTORY: "sonar-scanner-*" + SONARCLOUD_BUILD_WRAPPER_URL: "https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip" + SONARCLOUD_BUILD_WRAPPER_FILENAME: "build-wrapper-linux-x86.zip" + SONARCLOUD_BUILD_WRAPPER_EXTRACT_DIRECTORY: "build-wrapper-linux-x86" - SONARCLOUD_BUILD_WRAPPER_URL: "https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip" - SONARCLOUD_BUILD_WRAPPER_FILENAME: "build-wrapper-linux-x86.zip" - SONARCLOUD_BUILD_WRAPPER_EXTRACT_DIRECTORY: "build-wrapper-linux-x86" +jobs: + sonarcloud: + name: sonarcloud + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -170,7 +170,7 @@ jobs: - name: Config, build LekaOS & al. run: | - make config + make config config_tools build-wrapper-linux-x86-64 --out-dir bw-output make - name: Ccache post build @@ -193,9 +193,136 @@ jobs: make ccache_postbuild ccache -z + - name: Upload compilation database + uses: actions/upload-artifact@v2 + with: + name: compile_commands.json + path: ./_build_cmake_tools/compile_commands.json + - name: Run sonar-scanner run: | sonar-scanner -X -Dsonar.login=${{ secrets.SONAR_TOKEN }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + clang_tidy: + name: clang-tidy + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 2 + + # + # Mark: - Install ARM GCC Toolchain + # + + - name: Cache ARM GCC Toolchain + id: cache_arm_toolchain + uses: actions/cache@v2 + with: + path: ~/gcc-arm-none-eabi + key: ${{ runner.os }}-global_cache-arm_toolchain-${{ steps.cache_variables.outputs.arm_toolchain_url_sha }} + + - name: Install ARM GCC Toolchain + if: steps.cache_arm_toolchain.outputs.cache-hit != 'true' + run: | + wget ${{ env.ARM_TOOLCHAIN_URL }} + tar -xjf ${{ env.ARM_TOOLCHAIN_FILENAME }} && rm -rf ${{ env.ARM_TOOLCHAIN_FILENAME }} + mv ${{ env.ARM_TOOLCHAIN_EXTRACT_DIRECTORY }} ~/gcc-arm-none-eabi + + - name: Add ARM GCC Toolchain to path + run: | + echo "~/gcc-arm-none-eabi/bin" >> $GITHUB_PATH + + - name: Test ARM GCC Toolchain + run: | + ls -al ~/gcc-arm-none-eabi/bin + arm-none-eabi-gcc -v + + # + # Mark: - Install clang-tidy + # + + - name: Install clang-tidy 12 + run: | + sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-12 main" + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - + sudo apt update -y + sudo apt install -y --no-install-recommends clang-tidy-12 + clang-tidy-12 --version + + # + # Mark: - Install misc. tools + # + + - name: Install tools + run: | + sudo apt-get install -y --no-install-recommends ninja-build + + # + # Mark: - Download mbed-os & ccache + # + + - name: Cache Mbed OS + id: cache_mbed_os + uses: actions/cache@v2 + with: + path: extern/mbed-os + key: ${{ runner.os }}-global_cache-mbed_os-${{ hashFiles('extern/mbed-os/platform/include/platform/mbed_version.h', '.mbed_version') }} + + - name: Curl Mbed OS + if: steps.cache_mbed_os.outputs.cache-hit != 'true' + run: | + make mbed_curl + + # + # Mark: - Install python/pip dependencies + # + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.x" + + - name: Cache pip dependencies + id: cache_pip_dependencies + uses: actions/cache@v2 + with: + path: | + ~/.cache/pip + ${{ env.pythonLocation }} + key: ${{ runner.os }}-global_cache-pip_dependencies-${{ env.pythonLocation }}-${{ hashFiles('extern/mbed-os/requirements.txt', '.mbed_version') }} + + - name: Install pip packages + run: | + pip install --upgrade --upgrade-strategy eager mbed-cli + pip install --upgrade --upgrade-strategy eager -r ./extern/mbed-os/requirements.txt + + - name: Test pip packages + run: | + pip list -v + mbed-cli --help + + # + # Mark: - Analysze + # + + - name: Generate compile_commands.json + run: | + make config_tools + + - name: Get modified files + id: modified_files + uses: Ana06/get-changed-files@v1.2 + with: + format: "space-delimited" + filter: "*" + + - name: Run clang-tidy + run: | + echo ${{ steps.modified_files.outputs.all }} + echo ${{ steps.modified_files.outputs.all }} | xargs -n1 | grep -E '\.h$|\.cpp$' | xargs --no-run-if-empty clang-tidy-12 -p=. From b58ab5a7fd9ac3fc94e9340089387b6048363aa0 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 1 Jul 2021 15:54:32 +0200 Subject: [PATCH 05/11] :art: (ci): Force color outpu for clang, gcc, googletest --- .clang-tidy | 5 +++-- .github/workflows/ci-code_analysis.yml | 2 ++ .github/workflows/ci-cross_compilation.yml | 2 ++ .github/workflows/ci-unit_tests.yml | 15 +++++++-------- CMakeLists.txt | 2 +- Makefile | 2 +- tests/unit/CMakeLists.txt | 4 +++- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 883c12e577..b356d3d499 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,8 @@ # vim: set filetype=yaml: --- +HeaderFilterRegex: "" +UseColor: true + Checks: " \ -* \ , bugprone-assert-side-effect \ @@ -95,8 +98,6 @@ CheckOptions: - key: readability-function-cognitive-complexity.IgnoreMacros value: true -HeaderFilterRegex: "" - WarningsAsErrors: " \ modernize-* " diff --git a/.github/workflows/ci-code_analysis.yml b/.github/workflows/ci-code_analysis.yml index 1ed1b5b077..83dd2ffee7 100644 --- a/.github/workflows/ci-code_analysis.yml +++ b/.github/workflows/ci-code_analysis.yml @@ -15,6 +15,8 @@ env: CC: /usr/bin/gcc CXX: /usr/bin/g++ + CLICOLOR_FORCE: true # ninja + CCACHE_DIR: /home/runner/work/ccache CCACHE_COMPRESS: true CCACHE_COMPRESSLEVEL: 6 diff --git a/.github/workflows/ci-cross_compilation.yml b/.github/workflows/ci-cross_compilation.yml index bb0a7b11a0..dd49f4bfd2 100644 --- a/.github/workflows/ci-cross_compilation.yml +++ b/.github/workflows/ci-cross_compilation.yml @@ -20,6 +20,8 @@ jobs: runs-on: ubuntu-latest env: + CLICOLOR_FORCE: true # ninja + CCACHE_DIR: /home/runner/work/ccache CCACHE_COMPRESS: true CCACHE_COMPRESSLEVEL: 6 diff --git a/.github/workflows/ci-unit_tests.yml b/.github/workflows/ci-unit_tests.yml index 010a799a9b..cad87ad993 100644 --- a/.github/workflows/ci-unit_tests.yml +++ b/.github/workflows/ci-unit_tests.yml @@ -14,6 +14,13 @@ on: - "feature/**" - "bugfix/**" +env: + CLICOLOR_FORCE: true # ninja + + CCACHE_DIR: /home/runner/work/ccache + CCACHE_COMPRESS: true + CCACHE_COMPRESSLEVEL: 6 + jobs: gcc: name: gcc @@ -23,10 +30,6 @@ jobs: CC: /usr/bin/gcc CXX: /usr/bin/g++ - CCACHE_DIR: /home/runner/work/ccache - CCACHE_COMPRESS: true - CCACHE_COMPRESSLEVEL: 6 - steps: - uses: actions/checkout@v2 with: @@ -108,10 +111,6 @@ jobs: CC: /usr/bin/clang CXX: /usr/bin/clang++ - CCACHE_DIR: /home/runner/work/ccache - CCACHE_COMPRESS: true - CCACHE_COMPRESSLEVEL: 6 - steps: - uses: actions/checkout@v2 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index 054bf18a6a..d6e510eac2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ set(CMAKE_C_EXTENSIONS TRUE) # Add custom flags add_compile_options( - -fdiagnostics-color + -fdiagnostics-color=always $<$:-Wno-register> ) diff --git a/Makefile b/Makefile index 75a1d62c79..6dd1ceb0e9 100644 --- a/Makefile +++ b/Makefile @@ -188,7 +188,7 @@ build_unit_tests: run_unit_tests: @echo "" @echo "๐Ÿƒโ€โ™‚๏ธ Running unit tests ๐Ÿงช" - @$(UNIT_TESTS_BUILD_DIR)/LekaOSUnitTestsExec --gtest_output=xml:$(UNIT_TESTS_COVERAGE_DIR)/google_test_detail.xml + @$(UNIT_TESTS_BUILD_DIR)/LekaOSUnitTestsExec --gtest_color=yes --gtest_output=xml:$(UNIT_TESTS_COVERAGE_DIR)/google_test_detail.xml config_unit_tests: mkdir_build_unit_tests @echo "" diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index df425eb0d9..c2e1d5b47e 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -36,8 +36,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Colored output for compilation if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + message(STATUS "GCC found! Adding -fdiagnostics-color=always compile option") add_compile_options("-fdiagnostics-color=always") -elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$") +elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + message(STATUS "Clang found! Adding -fcolor-diagnostics compile option") add_compile_options("-fcolor-diagnostics") endif() From 7e07cdfcad28c8be779385b3f7ad2185b03986fe Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Thu, 1 Jul 2021 21:02:28 +0200 Subject: [PATCH 06/11] :hammer: (make): Add clang_tidy_diff(_fix) The target can be used to run clang-tidy on changed .h and .cpp files in the current branch --- Makefile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Makefile b/Makefile index 6dd1ceb0e9..69d5fab699 100644 --- a/Makefile +++ b/Makefile @@ -217,6 +217,22 @@ clang_format_fix: @echo "๐Ÿƒโ€โ™‚๏ธ Running clang-format & fixing files ๐ŸŽจ" python3 tools/run-clang-format.py -r --extension=h,c,cpp --color=always --style=file . -i +clang_tidy_diff: + @echo "" + @echo "๐Ÿƒโ€โ™‚๏ธ Running clang-tidy on modified files ๐Ÿงน" + @echo "" + @git diff --name-only develop | grep -E "\.h\$$|\.cpp\$$" + @echo "" + @git diff --name-only develop | grep -E "\.h\$$|\.cpp\$$" | xargs /usr/local/opt/llvm/bin/clang-tidy -p=. + +clang_tidy_diff_fix: + @echo "" + @echo "๐Ÿƒโ€โ™‚๏ธ Running clang-tidy on modified files ๐Ÿงน" + @echo "" + @git diff --name-only develop | grep -E "\.h\$$|\.cpp\$$" + @echo "" + @git diff --name-only develop | grep -E "\.h\$$|\.cpp\$$" | xargs /usr/local/opt/llvm/bin/clang-tidy -p=. --fix --fix-errors + code_analysis: mkdir_build @echo "" @echo "๐Ÿƒโ€โ™‚๏ธ Running cppcheck code analysis ๐Ÿ”ฌ" From b4b5eced0644307c4da0b92627822c94afed3c55 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Mon, 5 Jul 2021 11:15:54 +0200 Subject: [PATCH 07/11] :lipstick: (clang-tidy): Update readability-magic-numbers.IgnoredIntegerValues Add: - 10, 100, 1000 - hours/minutes - 60, 3600 - baudrates - 9600, 115200 --- .clang-tidy | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.clang-tidy b/.clang-tidy index b356d3d499..55f3e5ce84 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -97,6 +97,9 @@ CheckOptions: value: true - key: readability-function-cognitive-complexity.IgnoreMacros value: true + - key: readability-magic-numbers.IgnoredIntegerValues + value: '1;2;3;4;10;100;1000;60;3600;9600;115200' + WarningsAsErrors: " \ modernize-* From b4f2e08acf7fffc1bd048b43b368c3d9e86bf3d6 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Mon, 5 Jul 2021 12:32:31 +0200 Subject: [PATCH 08/11] :rotating_light: (clang-tidy): Remove rules conflicting with LogKit In particular, the following rules were breaking LogKit because of macros: - cppcoreguidelines-pro-bounds-array-to-pointer-decay - cppcoreguidelines-pro-bounds-pointer-arithmetic - cppcoreguidelines-pro-type-vararg We should find a way to fix this and still use the rules. --- .clang-tidy | 3 --- 1 file changed, 3 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 55f3e5ce84..e86b7e65f9 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -57,16 +57,13 @@ Checks: " \ , cppcoreguidelines-narrowing-conversions \ , cppcoreguidelines-no-malloc \ , cppcoreguidelines-prefer-member-initializer \ - , cppcoreguidelines-pro-bounds-array-to-pointer-decay \ , cppcoreguidelines-pro-bounds-constant-array-index \ - , cppcoreguidelines-pro-bounds-pointer-arithmetic \ , cppcoreguidelines-pro-type-const-cast \ , cppcoreguidelines-pro-type-cstyle-cast \ , cppcoreguidelines-pro-type-member-init \ , cppcoreguidelines-pro-type-reinterpret-cast \ , cppcoreguidelines-pro-type-static-cast-downcast \ , cppcoreguidelines-pro-type-union-access \ - , cppcoreguidelines-pro-type-vararg \ , cppcoreguidelines-slicing \ , cppcoreguidelines-special-member-functions \ , google-readability-avoid-underscore-in-googletest-name \ From e8702a8c61580f1f4ef42d546c59801c5dc5429c Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Mon, 5 Jul 2021 12:34:57 +0200 Subject: [PATCH 09/11] :rotating_light: (modernize): Fix clang-tidy issues --- src/main.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 90b3dd87e4..4a6cdc4cb6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,34 +2,35 @@ // Copyright 2020 APF France handicap // SPDX-License-Identifier: Apache-2.0 -#include "mbed.h" +#include "drivers/BufferedSerial.h" +#include "rtos/Kernel.h" +#include "rtos/ThisThread.h" +#include "rtos/Thread.h" #include "HelloWorld.h" +#include "LogKit.h" using namespace leka; +using namespace std::chrono; -HelloWorld hello; - -static BufferedSerial serial(USBTX, USBRX, 9600); - -constexpr uint8_t buff_size = 128; -char buff[buff_size] {}; - -int main(void) +auto main() -> int { - auto start = Kernel::Clock::now(); + static auto serial = mbed::BufferedSerial(USBTX, USBRX); + leka::logger::set_print_function([](const char *str, size_t size) { serial.write(str, size); }); + + rtos::ThisThread::sleep_for(1s); - printf("\nHello, Investigation Day!\n\n"); + log_info("\n\n"); + log_info("Hello, LekaOS!\n"); rtos::ThisThread::sleep_for(2s); + auto hello = HelloWorld(); hello.start(); while (true) { - auto t = Kernel::Clock::now() - start; - int length = sprintf(buff, "A message from your board %s --> \"%s\" at %i s\n", MBED_CONF_APP_TARGET_NAME, - hello.world, int(t.count() / 1000)); - serial.write(buff, length); + log_debug("A message from your board %s --> \"%s\" at %ims", MBED_CONF_APP_TARGET_NAME, hello.world, + int(rtos::Kernel::Clock::now().time_since_epoch().count())); rtos::ThisThread::sleep_for(1s); } } From 041aacfae959f9580585b513a388ef6235408910 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Mon, 5 Jul 2021 12:46:23 +0200 Subject: [PATCH 10/11] :hammer: (tidy): Format files on --fix --- .clang-tidy | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-tidy b/.clang-tidy index e86b7e65f9..9810d46665 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,6 +2,7 @@ --- HeaderFilterRegex: "" UseColor: true +FormatStyle: file Checks: " \ -* \ From 7f4b8d31aabf1d4e1b6d1003a691b625d4a70cea Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Mon, 5 Jul 2021 12:47:41 +0200 Subject: [PATCH 11/11] :hammer: (make): Run clang-tidy in --quiet mode --- .github/workflows/ci-code_analysis.yml | 2 +- Makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-code_analysis.yml b/.github/workflows/ci-code_analysis.yml index 83dd2ffee7..5f6065ee18 100644 --- a/.github/workflows/ci-code_analysis.yml +++ b/.github/workflows/ci-code_analysis.yml @@ -327,4 +327,4 @@ jobs: - name: Run clang-tidy run: | echo ${{ steps.modified_files.outputs.all }} - echo ${{ steps.modified_files.outputs.all }} | xargs -n1 | grep -E '\.h$|\.cpp$' | xargs --no-run-if-empty clang-tidy-12 -p=. + echo ${{ steps.modified_files.outputs.all }} | xargs -n1 | grep -E '\.h$|\.cpp$' | xargs --no-run-if-empty clang-tidy-12 -p=. --quiet diff --git a/Makefile b/Makefile index 69d5fab699..281744583d 100644 --- a/Makefile +++ b/Makefile @@ -223,7 +223,7 @@ clang_tidy_diff: @echo "" @git diff --name-only develop | grep -E "\.h\$$|\.cpp\$$" @echo "" - @git diff --name-only develop | grep -E "\.h\$$|\.cpp\$$" | xargs /usr/local/opt/llvm/bin/clang-tidy -p=. + @git diff --name-only develop | grep -E "\.h\$$|\.cpp\$$" | xargs /usr/local/opt/llvm/bin/clang-tidy -p=. --quiet clang_tidy_diff_fix: @echo "" @@ -231,7 +231,7 @@ clang_tidy_diff_fix: @echo "" @git diff --name-only develop | grep -E "\.h\$$|\.cpp\$$" @echo "" - @git diff --name-only develop | grep -E "\.h\$$|\.cpp\$$" | xargs /usr/local/opt/llvm/bin/clang-tidy -p=. --fix --fix-errors + @git diff --name-only develop | grep -E "\.h\$$|\.cpp\$$" | xargs /usr/local/opt/llvm/bin/clang-tidy -p=. --quiet --fix --fix-errors code_analysis: mkdir_build @echo ""