Skip to content

Commit f4a83c0

Browse files
authored
CDRIVER-3620 Audit compile and test scripts (#1187)
* Reorder maintainer flags to permit manual disabling of warnings * Improve behavior of bypass_dlclose() * Add support for add_expansions_to_env to shell_exec * Format .codecov.yml * Format scripts * Sanitize abi-compliance-check.sh * Sanitize add-build-dirs-to-paths.sh * Sanitize build-and-test-with-toolchain.sh * Sanitize compile*.sh scripts * Sanitize install-ssl.sh and run*.sh scripts * CDRIVER-3562 drop OpenSSL versions less than 1.0.1 * Do not run tests in compile tasks * Move all code coverage test-coverage-* tasks * Add env-var-utils.sh * Use env-var-utils.sh * Use nproc to specify Make job count * Support linking with custom OpenSSL library without system conflicts * CDRIVER-4562 Add SSL_CERT_DIR to resolve cert verify failure with 1.1.0 * Fallback to otool on MacOS if available
1 parent 3f41e4d commit f4a83c0

28 files changed

+2240
-3475
lines changed

.evergreen/.codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
ignore:
2+
- "src/libmongoc/tests/mock_server"
23
- "src/zlib-1.2.12"
3-
- "src/libmongoc/tests/mock_server"

.evergreen/abi-compliance-check.sh

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23
set -o errexit
34

45
# create all needed directories
@@ -7,48 +8,49 @@ mkdir abi-compliance/changes-install
78
mkdir abi-compliance/latest-release-install
89
mkdir abi-compliance/dumps
910

11+
python ./build/calc_release_version.py --next-minor >VERSION_CURRENT
12+
python ./build/calc_release_version.py --next-minor -p >VERSION_RELEASED
13+
14+
declare newest current
15+
newest="$(cat VERSION_RELEASED)"
16+
current="$(cat VERSION_CURRENT)"
17+
1018
# build the current changes
11-
export SKIP_MOCK_TESTS=ON
12-
export EXTRA_CONFIGURE_FLAGS="-DCMAKE_INSTALL_PREFIX=./abi-compliance/changes-install -DCMAKE_C_FLAGS=-g -Og"
13-
echo $(python ./build/calc_release_version.py --next-minor) > VERSION_CURRENT
14-
echo $(python ./build/calc_release_version.py --next-minor -p) > VERSION_RELEASED
15-
sh .evergreen/compile.sh
16-
make install
19+
env \
20+
CFLAGS="-g -Og" \
21+
EXTRA_CONFIGURE_FLAGS="-DCMAKE_INSTALL_PREFIX=./abi-compliance/changes-install" \
22+
bash .evergreen/compile.sh
1723

1824
# checkout the newest release
19-
newest=`cat VERSION_RELEASED`
20-
current=`cat VERSION_CURRENT`
21-
22-
git checkout tags/$newest -f
25+
git checkout "tags/${newest}" -f
2326

2427
# build the newest release
25-
export SKIP_MOCK_TESTS=ON
26-
export EXTRA_CONFIGURE_FLAGS="-DCMAKE_INSTALL_PREFIX=./abi-compliance/latest-release-install -DCMAKE_C_FLAGS=-g -Og"
27-
sh .evergreen/compile.sh
28-
make install
28+
env \
29+
CFLAGS="-g -Og" \
30+
EXTRA_CONFIGURE_FLAGS="-DCMAKE_INSTALL_PREFIX=./abi-compliance/latest-release-install" \
31+
bash .evergreen/compile.sh
2932

33+
# check for abi compliance. Generates HTML Reports.
3034
cd abi-compliance
3135

32-
old_xml="<version>$newest</version>\n"
33-
old_xml="${old_xml}<headers>\n"
34-
old_xml="${old_xml}$(pwd)/latest-release-install/include/libmongoc-1.0/mongoc/mongoc.h\n"
35-
old_xml="${old_xml}$(pwd)/latest-release-install/include/libbson-1.0/bson/bson.h\n"
36-
old_xml="${old_xml}</headers>\n"
37-
old_xml="${old_xml}<libs>$(pwd)/latest-release-install/lib</libs>"
38-
39-
printf $old_xml > old.xml
40-
41-
new_xml="<version>$current</version>\n"
42-
new_xml="${new_xml}<headers>\n"
43-
new_xml="${new_xml}$(pwd)/changes-install/include/libmongoc-1.0/mongoc/mongoc.h\n"
44-
new_xml="${new_xml}$(pwd)/changes-install/include/libbson-1.0/bson/bson.h\n"
45-
new_xml="${new_xml}</headers>\n"
46-
new_xml="${new_xml}<libs>$(pwd)/changes-install/lib</libs>"
47-
48-
printf $new_xml > new.xml
49-
50-
# check for abi compliance. Generates HTML Reports
51-
abi-compliance-checker -lib mongo-c-driver -old old.xml -new new.xml || result=$?
52-
if [ -n "$result" ]; then
53-
touch ./abi-error.txt
36+
cat >|old.xml <<DOC
37+
<version>${newest}</version>
38+
<headers>
39+
$(pwd)/latest-release-install/include/libmongoc-1.0/mongoc/mongoc.h
40+
$(pwd)/latest-release-install/include/libbson-1.0/bson/bson.h
41+
</headers>
42+
<libs>$(pwd)/latest-release-install/lib</libs>
43+
DOC
44+
45+
cat >|new.xml <<DOC
46+
<version>${current}</version>
47+
<headers>
48+
$(pwd)/changes-install/include/libmongoc-1.0/mongoc/mongoc.h
49+
$(pwd)/changes-install/include/libbson-1.0/bson/bson.h
50+
</headers>
51+
<libs>$(pwd)/changes-install/lib</libs>
52+
DOC
53+
54+
if ! abi-compliance-checker -lib mongo-c-driver -old old.xml -new new.xml; then
55+
touch ./abi-error.txt
5456
fi

.evergreen/add-build-dirs-to-paths.sh

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
1-
#!/bin/sh
2-
set -o errexit # Exit the script with error if any of the commands fail
1+
#!/usr/bin/env bash
32

4-
set_path ()
5-
{
6-
case "$OS" in
7-
cygwin*)
8-
export PATH="$PATH:$(pwd)/src/libbson/Debug"
9-
export PATH="$PATH:$(pwd)/src/libbson/Release"
10-
export PATH="$PATH:$(pwd)/install-dir/bin"
11-
chmod -f +x src/libmongoc/Debug/* || true
12-
chmod -f +x src/libbson/Debug/* || true
13-
chmod -f +x src/libmongoc/Release/* || true
14-
chmod -f +x src/libbson/Release/* || true
15-
chmod -f +x $(pwd)/install-dir/bin/* || true
16-
;;
3+
case "${OSTYPE}" in
4+
cygwin)
5+
export PATH
6+
PATH="$(pwd)/install-dir/bin:${PATH:-}"
7+
PATH="$(pwd)/src/libbson/Release:${PATH}"
8+
PATH="$(pwd)/src/libbson/Debug:${PATH}"
9+
chmod -f +x src/libmongoc/Debug/* || true
10+
chmod -f +x src/libbson/Debug/* || true
11+
chmod -f +x src/libmongoc/Release/* || true
12+
chmod -f +x src/libbson/Release/* || true
13+
chmod -f +x install-dir/bin/* || true
14+
;;
1715

18-
darwin)
19-
export DYLD_LIBRARY_PATH=".:install-dir/lib:install-dir/lib64:src/libbson:src/libmongoc:$EXTRA_LIB_PATH:$DYLD_LIBRARY_PATH"
20-
;;
16+
darwin*)
17+
export DYLD_LIBRARY_PATH
18+
DYLD_LIBRARY_PATH="${EXTRA_LIB_PATH:-}:${DYLD_LIBRARY_PATH:-}"
19+
DYLD_LIBRARY_PATH="$(pwd)/src/libmongoc:${DYLD_LIBRARY_PATH}"
20+
DYLD_LIBRARY_PATH="$(pwd)/src/libbson:${DYLD_LIBRARY_PATH}"
21+
DYLD_LIBRARY_PATH="$(pwd)/install-dir/lib64:${DYLD_LIBRARY_PATH}"
22+
DYLD_LIBRARY_PATH="$(pwd)/install-dir/lib:${DYLD_LIBRARY_PATH}"
23+
DYLD_LIBRARY_PATH="$(pwd):${DYLD_LIBRARY_PATH}"
24+
;;
2125

22-
*)
23-
export LD_LIBRARY_PATH=".:install-dir/lib:install-dir/lib64:src/libbson:src/libmongoc:$EXTRA_LIB_PATH:$LD_LIBRARY_PATH"
24-
;;
25-
esac
26-
27-
case "$OS" in
28-
cygwin*)
29-
;;
30-
31-
*)
32-
export PKG_CONFIG_PATH=$INSTALL_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
33-
export PATH=$INSTALL_DIR/bin:$PATH
34-
;;
35-
esac
36-
}
37-
38-
set_path
26+
*)
27+
export LD_LIBRARY_PATH
28+
LD_LIBRARY_PATH="${EXTRA_LIB_PATH:-}:${LD_LIBRARY_PATH:-}"
29+
LD_LIBRARY_PATH="$(pwd)/src/libmongoc:${LD_LIBRARY_PATH}"
30+
LD_LIBRARY_PATH="$(pwd)/src/libbson:${LD_LIBRARY_PATH}"
31+
LD_LIBRARY_PATH="$(pwd)/install-dir/lib64:${LD_LIBRARY_PATH}"
32+
LD_LIBRARY_PATH="$(pwd)/install-dir/lib:${LD_LIBRARY_PATH}"
33+
LD_LIBRARY_PATH="$(pwd):${LD_LIBRARY_PATH}"
34+
;;
35+
esac
Lines changed: 87 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,95 @@
1-
#!/bin/sh
2-
set -o errexit # Exit the script with error if any of the commands fail
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o pipefail
35

46
echo "BUILDING WITH TOOLCHAIN"
57

68
# Configure environment with toolchain components
7-
[ -d /opt/mongo-c-toolchain ] && sudo rm -r /opt/mongo-c-toolchain
9+
if [[ -d /opt/mongo-c-toolchain ]]; then
10+
sudo rm -r /opt/mongo-c-toolchain
11+
fi
12+
813
sudo mkdir /opt/mongo-c-toolchain
9-
TOOLCHAIN_TAR_GZ=$(readlink -f ../mongo-c-toolchain.tar.gz)
10-
sudo tar -xvf "${TOOLCHAIN_TAR_GZ}" -C /opt/mongo-c-toolchain
14+
15+
declare toolchain_tar_gz
16+
toolchain_tar_gz=$(readlink -f ../mongo-c-toolchain.tar.gz)
17+
sudo tar -xvf "${toolchain_tar_gz}" -C /opt/mongo-c-toolchain
18+
1119
echo "--- TOOLCHAIN MANIFEST ---"
1220
cat /opt/mongo-c-toolchain/MANIFEST.txt
13-
OLD_PATH=${PATH}
14-
ADDL_PATH=$(readlink -f /opt/mongo-c-toolchain/bin):${PATH}
15-
export CMAKE=$(readlink -f /opt/mongo-c-toolchain/bin/cmake)
16-
[ -x "${CMAKE}" ] || (echo "CMake (${CMAKE}) does not exist or is not executable"; exit 1)
17-
TOOLCHAIN_BASE_DIR=$(readlink -f /opt/mongo-c-toolchain)
18-
TOOLCHAIN_LIB_DIR=${TOOLCHAIN_BASE_DIR}/lib
19-
20-
for ssl_ver in libressl-2.5 libressl-3.0 openssl-0.9.8 openssl-1.0.0 openssl-1.0.1 openssl-1.0.1-fips openssl-1.0.2 openssl-1.1.0; do
21-
22-
cd ..
23-
cp -a mongoc mongoc-${ssl_ver}
24-
cd mongoc-${ssl_ver}
25-
export PATH=$(readlink -f /opt/mongo-c-toolchain/${ssl_ver}/bin):${ADDL_PATH}:${OLD_PATH}
26-
ssl_base_dir=$(readlink -f /opt/mongo-c-toolchain/${ssl_ver})
27-
ssl_lib_dir=${ssl_base_dir}/lib
28-
export EXTRA_CONFIGURE_FLAGS="-DCMAKE_VERBOSE_MAKEFILE=ON"
29-
export EXTRA_CMAKE_PREFIX_PATH="${ssl_base_dir};${TOOLCHAIN_BASE_DIR}"
30-
31-
# Output some information about our build environment
32-
"${CMAKE}" --version
33-
34-
# Run the build and tests
35-
export LD_LIBRARY_PATH="${ssl_lib_dir}:${TOOLCHAIN_LIB_DIR}"
36-
if [ "${ssl_ver#*libressl}" != "${ssl_ver}" ]; then
37-
SSL_TYPE=LIBRESSL
38-
else
39-
SSL_TYPE=OPENSSL
40-
fi
41-
output_file=$(mktemp)
42-
SSL=${SSL_TYPE} sh ./.evergreen/compile-unix.sh 2>&1 | tee -a "${output_file}"
43-
44-
# Verify that the toolchain components were used
45-
if grep -Ec "[-]I/opt/mongo-c-toolchain/include" "${output_file}" >/dev/null \
46-
&& grep -Ec "[-]I/opt/mongo-c-toolchain/${ssl_ver}/include" "${output_file}" >/dev/null \
47-
&& grep -Ec "[-]L/opt/mongo-c-toolchain/lib" "${output_file}" >/dev/null \
48-
&& grep -Ec "/opt/mongo-c-toolchain/${ssl_ver}/lib" "${output_file}" >/dev/null; then
49-
echo "Toolchain components for ${ssl_ver} were detected in build output...continuing."
50-
else
51-
echo "TOOLCHAIN COMPONENTS FOR ${ssl_ver} NOT DETECTED IN BUILD OUTPUT...ABORTING!"
52-
exit 1
53-
fi
54-
rm -f "${output_file}"
55-
56-
cd ../mongoc
21+
22+
declare addl_path
23+
addl_path="$(readlink -f /opt/mongo-c-toolchain/bin):${PATH:-}"
24+
25+
declare cmake_binary
26+
cmake_binary="$(readlink -f /opt/mongo-c-toolchain/bin/cmake)"
27+
28+
if [[ ! -x "${cmake_binary}" ]]; then
29+
echo "CMake (${cmake_binary}) does not exist or is not executable" 1>&2
30+
exit 1
31+
fi
32+
33+
declare toolchain_base_dir
34+
toolchain_base_dir="$(readlink -f /opt/mongo-c-toolchain)"
35+
36+
declare toolchain_lib_dir="${toolchain_base_dir}/lib"
37+
38+
declare -a ssl_vers=(
39+
"libressl-2.5"
40+
"libressl-3.0"
41+
"openssl-1.0.1"
42+
"openssl-1.0.1-fips"
43+
"openssl-1.0.2"
44+
"openssl-1.1.0"
45+
)
46+
47+
for ssl_ver in "${ssl_vers[@]}"; do
48+
cp -a ../mongoc "../mongoc-${ssl_ver}"
49+
pushd "../mongoc-${ssl_ver}"
50+
51+
declare new_path
52+
new_path="$(readlink -f "/opt/mongo-c-toolchain/${ssl_ver}/bin")"
53+
new_path+=":${addl_path}"
54+
55+
declare ssl_base_dir
56+
ssl_base_dir="$(readlink -f "/opt/mongo-c-toolchain/${ssl_ver}")"
57+
58+
declare ssl_lib_dir="${ssl_base_dir}/lib"
59+
60+
# Output some information about our build environment
61+
"${cmake_binary}" --version
62+
63+
declare ssl
64+
if [[ "${ssl_ver#*libressl}" != "${ssl_ver}" ]]; then
65+
ssl="LIBRESSL"
66+
else
67+
ssl="OPENSSL"
68+
fi
69+
70+
declare output_file
71+
output_file="$(mktemp)"
72+
73+
env \
74+
EXTRA_CMAKE_PREFIX_PATH="${ssl_base_dir};${toolchain_base_dir}" \
75+
EXTRA_CONFIGURE_FLAGS="-DCMAKE_VERBOSE_MAKEFILE=ON" \
76+
LD_LIBRARY_PATH="${ssl_lib_dir}:${toolchain_lib_dir}" \
77+
PATH="${new_path}" \
78+
SSL="${ssl}" \
79+
bash ./.evergreen/compile-unix.sh 2>&1 | tee -a "${output_file}"
80+
81+
# Verify that the toolchain components were used
82+
if grep -Ec "[-]I/opt/mongo-c-toolchain/include" "${output_file}" >/dev/null &&
83+
grep -Ec "[-]I/opt/mongo-c-toolchain/${ssl_ver}/include" "${output_file}" >/dev/null &&
84+
grep -Ec "[-]L/opt/mongo-c-toolchain/lib" "${output_file}" >/dev/null &&
85+
grep -Ec "/opt/mongo-c-toolchain/${ssl_ver}/lib" "${output_file}" >/dev/null; then
86+
echo "Toolchain components for ${ssl_ver} were detected in build output...continuing."
87+
else
88+
echo "TOOLCHAIN COMPONENTS FOR ${ssl_ver} NOT DETECTED IN BUILD OUTPUT...ABORTING!" 1>&2
89+
exit 1
90+
fi
91+
92+
rm -f "${output_file}"
93+
94+
popd # "mongoc-${ssl_ver}"
5795
done

.evergreen/bypass-dlclose.sh

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,44 @@
66
# bypass_dlclose command args...
77
#
88
# Parameters:
9-
# "$@": command and arguments to evaluate.
109
# "$CC": compiler to use to compile and link the bypass_dlclose library.
1110
#
12-
# Evaluates the provided command and arguments with LD_PRELOAD defined to
13-
# preload a `bypass_dlclose.so` library defining a no-op `dlclose()`.
14-
# If necessary, also preloads the `libasan.so` library to satisfy linker
15-
# requirements.
16-
bypass_dlclose() {
17-
: "${1:?'bypass_dlclose expects at least one argument to run as command!'}"
11+
# Return 0 (true) if able to create a shared library to bypass calls to dlclose.
12+
# Return a non-zero (false) value otherwise.
13+
#
14+
# If successful, print paths to add to LD_PRELOAD to stdout (pipe 1).
15+
# Otherwise, no output is printed to stdout (pipe 1).
16+
#
17+
# Diagnostic messages may be printed to stderr (pipe 2). Redirect to /dev/null
18+
# with `2>/dev/null` to silence these messages.
19+
bypass_dlclose() (
1820
: "${CC:?'bypass_dlclose expects environment variable CC to be defined!'}"
1921

20-
declare tmp
22+
declare ld_preload
2123

22-
if ! tmp="$(mktemp -d)"; then
23-
echo "Could not create temporary directory for bypass_dlclose library!" 1>&2
24-
return 1
25-
fi
26-
trap 'rm -rf "$tmp"' EXIT
24+
{
25+
declare tmp
2726

28-
declare ld_preload
27+
if ! tmp="$(mktemp -d)"; then
28+
echo "Could not create temporary directory for bypass_dlclose library!" 1>&2
29+
return 1
30+
fi
2931

30-
echo "int dlclose (void *handle) {(void) handle; return 0; }" >|"$tmp/bypass_dlclose.c"
32+
echo "int dlclose (void *handle) {(void) handle; return 0; }" \
33+
>|"${tmp}/bypass_dlclose.c" || return
3134

32-
"$CC" -o "$tmp/bypass_dlclose.so" -shared "$tmp/bypass_dlclose.c" || return
35+
"${CC}" -o "${tmp}/bypass_dlclose.so" \
36+
-shared "${tmp}/bypass_dlclose.c" || return
3337

34-
ld_preload="$tmp/bypass_dlclose.so"
38+
ld_preload="${tmp}/bypass_dlclose.so"
3539

36-
# Clang uses its own libasan.so; do not preload it!
37-
if [ "$CC" != "clang" ]; then
38-
declare asan_path
39-
asan_path="$($CC -print-file-name=libasan.so)" || return
40-
ld_preload="$asan_path:$ld_preload"
41-
fi
40+
# Clang uses its own libasan.so; do not preload it!
41+
if [ "${CC}" != "clang" ]; then
42+
declare asan_path
43+
asan_path="$(${CC} -print-file-name=libasan.so)" || return
44+
ld_preload="${asan_path}:${ld_preload}"
45+
fi
46+
} 1>&2
4247

43-
LD_PRELOAD="$ld_preload:${LD_PRELOAD:-}" "$@"
44-
}
48+
printf "%s" "${ld_preload}"
49+
)

0 commit comments

Comments
 (0)