Skip to content

Commit b3f4d7d

Browse files
authored
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 88d9565 commit b3f4d7d

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
@@ -639,6 +651,55 @@ functions:
639651
name: perf
640652
file: mongo-cxx-driver/results.json
641653

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