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

feat: add static checker for cpp with cppcheck #2346

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,33 @@ on:
branches: [ main ]

jobs:
cppcheck_analyser:
name: static check with cppcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: setup
env:
CC: /usr/bin/gcc-10
CXX: /usr/bin/g++-10
run: |
sudo -E ./ci/setup_cmake.sh
sudo -E ./ci/setup_ci_environment.sh
sudo apt-get -y install cmake
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should cmake install already handled by ./ci/setup_cmake.sh 2 lines above?

- name: build and run cppcheck
run: |
cd ..
git clone https://github.com/danmar/cppcheck.git --branch 2.12.x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the checkout action to checkout the cppcheck repo?

cd cppcheck
mkdir build
cd build
cmake ..
cmake --build .
chmod +x bin/cppcheck
cd ../../opentelemetry-cpp
../cppcheck/build/bin/cppcheck -ithird_party/ --error-exitcode=1 .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have this CI similar to that for format :

format:
name: Format
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: setup
run: sudo ./ci/install_format_tools.sh
- name: run tests
run: ./ci/do_ci.sh format

  • Create script to install a particular version of cppcheck passed as argument.
  • And invoke the cppcheck through ./do_ci.sh cppcheck

This will also allow developers to invoke static analysis locally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And should test_common also be ignored here?

cmake_test:
name: CMake test (without otlp-exporter)
runs-on: ubuntu-latest
Expand Down
23 changes: 23 additions & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,29 @@ elif [[ "$1" == "code.coverage" ]]; then
lcov --remove coverage.info '*/ext/http/server/*'> tmp_coverage.info 2>/dev/null
cp tmp_coverage.info coverage.info
exit 0
elif [[ "$1" == "cppcheck" ]]; then
pwd
excluded_dirs=()
while read -r excluded_dir; do
excluded_dirs+=("$excluded_dir")
done < ./ci/exclude_cppcheck.txt
args=()
echo $excluded_dirs
for excluded_dir in "${excluded_dirs[@]}"; do
args+=("$excluded_dir")
done
string_args=$(join " -\\i" "${args[@]}")
cd ..
git clone https://github.com/danmar/cppcheck.git --branch 2.12.x
cd cppcheck
mkdir build
cd build
cmake ..
cmake --build .
chmod +x bin/cppcheck
cd ../../opentelemetry-cpp
echo "../cppcheck/build/bin/cppcheck -i$string_args --error-exitcode=1 ."
# ../cppcheck/build/bin/cppcheck -i$string_args --error-exitcode=1 .
elif [[ "$1" == "third_party.tags" ]]; then
echo "gRPC=v1.49.2" > third_party_release
echo "abseil=20220623.1" >> third_party_release
Expand Down
2 changes: 2 additions & 0 deletions ci/exclude_cppcheck.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
third_party
test_common
Loading