Skip to content

Commit a59ad65

Browse files
committed
CXX-2793 Add scan-build tasks to EVG config (#1126)
* Add scan-build tasks to EVG config * Cleanup misc. EVG post command output * Add Coverity check to release instructions
1 parent 73d89a5 commit a59ad65

File tree

3 files changed

+224
-7
lines changed

3 files changed

+224
-7
lines changed

.evergreen/compile-scan-build.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
6+
: "${BSONCXX_POLYFILL:?}"
7+
: "${CXX_STANDARD:?}"
8+
9+
mongoc_prefix="$(pwd)/../mongoc"
10+
11+
# shellcheck source=/dev/null
12+
. "${mongoc_prefix:?}/.evergreen/scripts/find-cmake-latest.sh"
13+
export cmake_binary
14+
cmake_binary="$(find_cmake_latest)"
15+
command -v "$cmake_binary"
16+
17+
# scan-build binary is available in different locations depending on the distro.
18+
# Search for a match in order of preference as listed.
19+
declare -a scan_build_directories
20+
21+
scan_build_directories+=(
22+
# Prefer toolchain scan-build if available.
23+
"/opt/mongodbtoolchain/v4/bin"
24+
"/opt/mongodbtoolchain/v3/bin"
25+
)
26+
27+
# Use system scan-build otherwise.
28+
IFS=: read -ra sys_dirs <<< "${PATH:-}"
29+
scan_build_directories+=("${sys_dirs[@]:-}")
30+
31+
declare scan_build_binary
32+
for dir in "${scan_build_directories[@]}"; do
33+
if command -v "${dir}/scan-build" && command -v "${dir}/clang" && command -v "${dir}/clang++"; then
34+
# Ensure compilers are consistent with scan-build binary. All three binaries
35+
# should be present in the same directory.
36+
scan_build_binary="${dir}/scan-build"
37+
CC="${dir}/clang"
38+
CXX="${dir}/clang++"
39+
break
40+
fi
41+
done
42+
: "${scan_build_binary:?"could not find a scan-build binary!"}"
43+
export CC
44+
export CXX
45+
46+
if [[ "${OSTYPE}" == darwin* ]]; then
47+
# MacOS does not have nproc.
48+
nproc() {
49+
sysctl -n hw.logicalcpu
50+
}
51+
fi
52+
CMAKE_BUILD_PARALLEL_LEVEL="$(nproc)"
53+
export CMAKE_BUILD_PARALLEL_LEVEL
54+
55+
cmake_flags=(
56+
-D CMAKE_BUILD_TYPE=Debug
57+
-D "CMAKE_CXX_STANDARD=${CXX_STANDARD:?}"
58+
-D CMAKE_CXX_STANDARD_REQUIRED=ON
59+
-D ENABLE_TESTS=OFF
60+
)
61+
62+
scan_build_flags=(
63+
--use-cc "${CC:?}"
64+
--use-c++ "${CXX:?}"
65+
-analyze-headers
66+
--exclude "$(pwd)/build/src/bsoncxx/third_party/_deps" # mnmlstc
67+
--exclude "$(pwd)/build/_deps" # mongoc
68+
)
69+
70+
case "${BSONCXX_POLYFILL:?}" in
71+
mnmlstc) cmake_flags+=(-D "BSONCXX_POLY_USE_MNMLSTC=ON") ;;
72+
boost) cmake_flags+=(-D "BSONCXX_POLY_USE_BOOST=ON") ;;
73+
impls) cmake_flags+=(-D "BSONCXX_POLY_USE_IMPLS=ON") ;;
74+
std) cmake_flags+=(-D "BSONCXX_POLY_USE_STD=ON") ;;
75+
esac
76+
77+
echo "Configuring with CMake flags: ${cmake_flags[*]}"
78+
79+
# Configure via scan-build for consistency.
80+
CCCACHE_DISABLE=1 "${scan_build_binary}" "${scan_build_flags[@]}" "${cmake_binary:?}" -S . -B build "${cmake_flags[@]}"
81+
82+
# If scan-build emits warnings, continue the task and upload scan results before marking task as a failure.
83+
declare -r continue_command='{"status":"failed", "type":"test", "should_continue":true, "desc":"scan-build emitted one or more warnings or errors"}'
84+
85+
# Put clang static analyzer results in scan/ and fail build if warnings found.
86+
"${scan_build_binary}" "${scan_build_flags[@]}" -o scan --status-bugs "${cmake_binary:?}" --build build ||
87+
curl -sS -d "${continue_command}" -H "Content-Type: application/json" -X POST localhost:2285/task_status

.mci.yml

Lines changed: 133 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,16 @@ functions:
335335

336336

337337
"stop_mongod":
338-
command: shell.exec
338+
command: subprocess.exec
339339
params:
340-
shell: bash
340+
binary: bash
341341
working_dir: "."
342-
script: |
342+
args:
343+
- -c
344+
- |
343345
set -o errexit
344346
set -o pipefail
345-
if cd drivers-evergreen-tools/.evergreen/orchestration; then
347+
if cd drivers-evergreen-tools/.evergreen/orchestration 2>/dev/null; then
346348
. ../venv-utils.sh
347349
if venvactivate venv; then
348350
mongo-orchestration stop
@@ -579,13 +581,23 @@ functions:
579581
display_name: "working-dir.tar.gz"
580582

581583
"upload mongo orchestration artifacts":
582-
- command: shell.exec
584+
- command: subprocess.exec
583585
params:
584586
working_dir: "."
585-
script: |
586-
find . -name \*.log | xargs tar czf mongodb-logs.tar.gz
587+
binary: bash
588+
args:
589+
- -c
590+
- |
591+
set -o errexit
592+
for log in $(find . -name '*.log'); do
593+
tar rf mongodb-logs.tar "$log"
594+
done
595+
if [[ -f mongodb-logs.tar ]]; then
596+
gzip mongodb-logs.tar
597+
fi
587598
- command: s3.put
588599
params:
600+
optional: true
589601
aws_key: ${aws_key}
590602
aws_secret: ${aws_secret}
591603
local_file: mongodb-logs.tar.gz
@@ -638,6 +650,55 @@ functions:
638650
name: perf
639651
file: mongo-cxx-driver/results.json
640652

653+
"run scan build":
654+
- command: subprocess.exec
655+
type: test
656+
params:
657+
binary: bash
658+
working_dir: "mongo-cxx-driver"
659+
add_expansions_to_env: true
660+
redirect_standard_error_to_output: true
661+
args:
662+
- -c
663+
- .evergreen/compile-scan-build.sh
664+
665+
"upload scan artifacts":
666+
- command: subprocess.exec
667+
type: test
668+
params:
669+
working_dir: "mongo-cxx-driver"
670+
binary: bash
671+
args:
672+
- -c
673+
- |
674+
set -o errexit
675+
if find scan -name \*.html | grep -q html; then
676+
(cd scan && find . -name index.html -exec echo "<li><a href='{}'>{}</a></li>" \;) >> scan.html
677+
else
678+
echo "No issues found" > scan.html
679+
fi
680+
- command: subprocess.exec
681+
params:
682+
silent: true
683+
working_dir: mongo-cxx-driver
684+
binary: bash
685+
env:
686+
AWS_ACCESS_KEY_ID: ${aws_key}
687+
AWS_SECRET_ACCESS_KEY: ${aws_secret}
688+
args:
689+
- -c
690+
- aws s3 cp scan s3://mciuploads/${project}/${build_variant}/${revision}/${version_id}/${build_id}/scan/ --recursive --acl public-read --region us-east-1
691+
- command: s3.put
692+
params:
693+
aws_key: ${aws_key}
694+
aws_secret: ${aws_secret}
695+
remote_file: ${project}/${build_variant}/${revision}/${version_id}/${build_id}/scan/index.html
696+
bucket: mciuploads
697+
permissions: public-read
698+
local_file: mongo-cxx-driver/scan.html
699+
content_type: text/html
700+
display_name: Scan Build Report
701+
641702
#######################################
642703
# Post Task #
643704
#######################################
@@ -1108,6 +1169,66 @@ tasks:
11081169
11091170
./build/src/mongocxx/test/test_driver "atlas search indexes prose tests"
11101171
1172+
- name: scan-build-ubuntu2204-std11-mnmlstc
1173+
run_on: ubuntu2204-large
1174+
tags: [scan-build-matrix]
1175+
commands:
1176+
- func: "setup"
1177+
- func: "fetch_c_driver_source"
1178+
- func: "run scan build"
1179+
vars:
1180+
CXX_STANDARD: 11
1181+
BSONCXX_POLYFILL: mnmlstc
1182+
- func: "upload scan artifacts"
1183+
1184+
- name: scan-build-ubuntu2204-std11-boost
1185+
run_on: ubuntu2204-large
1186+
tags: [scan-build-matrix]
1187+
commands:
1188+
- func: "setup"
1189+
- func: "fetch_c_driver_source"
1190+
- func: "run scan build"
1191+
vars:
1192+
CXX_STANDARD: 11
1193+
BSONCXX_POLYFILL: boost
1194+
- func: "upload scan artifacts"
1195+
1196+
- name: scan-build-ubuntu2204-std11-impls
1197+
run_on: ubuntu2204-large
1198+
tags: [scan-build-matrix]
1199+
commands:
1200+
- func: "setup"
1201+
- func: "fetch_c_driver_source"
1202+
- func: "run scan build"
1203+
vars:
1204+
CXX_STANDARD: 11
1205+
BSONCXX_POLYFILL: impls
1206+
- func: "upload scan artifacts"
1207+
1208+
- name: scan-build-ubuntu2204-std14-impls
1209+
run_on: ubuntu2204-large
1210+
tags: [scan-build-matrix]
1211+
commands:
1212+
- func: "setup"
1213+
- func: "fetch_c_driver_source"
1214+
- func: "run scan build"
1215+
vars:
1216+
CXX_STANDARD: 14
1217+
BSONCXX_POLYFILL: impls
1218+
- func: "upload scan artifacts"
1219+
1220+
- name: scan-build-ubuntu2204-std17
1221+
run_on: ubuntu2204-large
1222+
tags: [scan-build-matrix]
1223+
commands:
1224+
- func: "setup"
1225+
- func: "fetch_c_driver_source"
1226+
- func: "run scan build"
1227+
vars:
1228+
CXX_STANDARD: 17
1229+
BSONCXX_POLYFILL: std
1230+
- func: "upload scan artifacts"
1231+
11111232
task_groups:
11121233
- name: tg-abi-stability
11131234
max_hosts: -1
@@ -2044,3 +2165,8 @@ buildvariants:
20442165
- name: lint
20452166
display_name: Lint
20462167
tasks: [lint]
2168+
2169+
- name: scan-build-matrix
2170+
display_name: scan-build-matrix
2171+
tasks:
2172+
- name: .scan-build-matrix

etc/releasing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ releasing 1.2.3, then refer to the the waterfall tracking
1919
If there are test failures, ensure they are at least expected or not introduced
2020
by changes in the new release.
2121

22+
## Check Coverity
23+
24+
Ensure there are no new, unexpected, or high severity issues on Coverity.
25+
2226
## Check fixVersions in Jira
2327

2428
Ensure that all tickets under the

0 commit comments

Comments
 (0)