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

WIP - (clang-tidy): Modernize code using clang-tidy #227

Merged
merged 11 commits into from
Jul 5, 2021
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
104 changes: 104 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# vim: set filetype=yaml:
---
HeaderFilterRegex: ""
UseColor: true
FormatStyle: file

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-constant-array-index \
, 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-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
- key: readability-magic-numbers.IgnoredIntegerValues
value: '1;2;3;4;10;100;1000;60;3600;9600;115200'


WarningsAsErrors: " \
modernize-*
"
169 changes: 149 additions & 20 deletions .github/workflows/ci-code_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,32 @@ 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++
CLICOLOR_FORCE: true # ninja

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
Expand Down Expand Up @@ -170,7 +172,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
Expand All @@ -193,9 +195,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=. --quiet
2 changes: 2 additions & 0 deletions .github/workflows/ci-cross_compilation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/ci-unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"files.associations": {
"*.orig": "cpp",
".clang-format": "yaml",
".clang-tidy": "yaml",
"*.orig": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
Expand Down Expand Up @@ -96,6 +97,7 @@
"--log=verbose",
"--completion-style=detailed",
"--clang-tidy",
"--clang-tidy-checks=-*,modernize*"
"--header-insertion=never",
"--suggest-missing-includes"
]
}
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ set(CMAKE_C_EXTENSIONS TRUE)

# Add custom flags
add_compile_options(
-fdiagnostics-color
-fdiagnostics-color=always
$<$<COMPILE_LANGUAGE:CXX>:-Wno-register>
)

Expand All @@ -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)
Expand Down
Loading