Skip to content

CDRIVER-3620 Audit compile and test scripts #1187

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

Merged
merged 35 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
70f8ac0
Reorder maintainer flags to permit manual disabling of warnings
eramongodb Jan 20, 2023
8976ccd
Improve behavior of bypass_dlclose()
eramongodb Jan 18, 2023
68ac566
Add support for add_expansions_to_env to shell_exec
eramongodb Jan 18, 2023
a60e6b7
Format .codecov.yml
eramongodb Jan 17, 2023
0d3a655
Format scripts
eramongodb Jan 17, 2023
caf03a4
Sanitize abi-compliance-check.sh
eramongodb Jan 17, 2023
fb21728
Sanitize add-build-dirs-to-paths.sh
eramongodb Jan 17, 2023
8dc2a52
Sanitize build-and-test-with-toolchain.sh
eramongodb Jan 18, 2023
5c0e3a7
Sanitize compile*.sh scripts
eramongodb Jan 18, 2023
807df24
Sanitize install-ssl.sh and run*.sh scripts
eramongodb Jan 18, 2023
ef246cc
CDRIVER-3562 drop OpenSSL versions less than 1.0.1
eramongodb Jan 19, 2023
374ce98
Add SKIP_MOCK_TESTS=ON to test variants and special variants
eramongodb Jan 20, 2023
0e49426
Do not run tests in compile tasks
eramongodb Jan 20, 2023
112ae98
Move all code coverage test-coverage-* tasks
eramongodb Jan 20, 2023
4878c42
Test if value of argument is null, not argument itself
eramongodb Jan 23, 2023
8525df2
Use array for args to tar
eramongodb Jan 23, 2023
ec5a15d
Format compile-unix.sh
eramongodb Jan 23, 2023
1d49f4c
Add env-var-utils.sh
eramongodb Jan 23, 2023
a33e8ed
Use env-var-utils.sh
eramongodb Jan 23, 2023
527f8aa
Use nproc to specify Make job count
eramongodb Jan 23, 2023
8791d28
Unquote variables being checked to distinguish from values
eramongodb Jan 23, 2023
22ea125
Support linking with custom OpenSSL library without system conflicts
eramongodb Jan 23, 2023
ff13e60
Use consistent definition of configure_flags_append_if_not_null
eramongodb Jan 24, 2023
1eacba0
Use env-var-utils.sh in run-auth-tests.sh
eramongodb Jan 24, 2023
f05704a
Do not error on missing libssl in ldd output
eramongodb Jan 24, 2023
e1cd742
Remove call to openssl binary in favor of ldd output
eramongodb Jan 24, 2023
f6544bf
Remove redundant variable old_path
eramongodb Jan 24, 2023
c1bf56f
Fix typo in zstd comment
eramongodb Jan 24, 2023
0872b88
Fix set xtrace command
eramongodb Jan 24, 2023
690e8b5
Print message when copying certificate to SSL install dir
eramongodb Jan 24, 2023
1d9e2f9
Do not run tests after mingw compilation either
eramongodb Jan 24, 2023
afd07be
Update comment documenting libmongocrypt linkage behavior
eramongodb Jan 25, 2023
c486e20
CDRIVER-4562 Add SSL_CERT_DIR to resolve cert verify failure with 1.1.0
eramongodb Jan 25, 2023
ca232bf
Fallback to otool on MacOS if available
eramongodb Jan 25, 2023
ec717f1
Fix indentation
eramongodb Jan 25, 2023
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
2 changes: 1 addition & 1 deletion .evergreen/.codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ignore:
- "src/libmongoc/tests/mock_server"
- "src/zlib-1.2.12"
- "src/libmongoc/tests/mock_server"
76 changes: 39 additions & 37 deletions .evergreen/abi-compliance-check.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash

set -o errexit

# create all needed directories
Expand All @@ -7,48 +8,49 @@ mkdir abi-compliance/changes-install
mkdir abi-compliance/latest-release-install
mkdir abi-compliance/dumps

python ./build/calc_release_version.py --next-minor >VERSION_CURRENT
python ./build/calc_release_version.py --next-minor -p >VERSION_RELEASED

declare newest current
newest="$(cat VERSION_RELEASED)"
current="$(cat VERSION_CURRENT)"

# build the current changes
export SKIP_MOCK_TESTS=ON
export EXTRA_CONFIGURE_FLAGS="-DCMAKE_INSTALL_PREFIX=./abi-compliance/changes-install -DCMAKE_C_FLAGS=-g -Og"
echo $(python ./build/calc_release_version.py --next-minor) > VERSION_CURRENT
echo $(python ./build/calc_release_version.py --next-minor -p) > VERSION_RELEASED
sh .evergreen/compile.sh
make install
env \
CFLAGS="-g -Og" \
EXTRA_CONFIGURE_FLAGS="-DCMAKE_INSTALL_PREFIX=./abi-compliance/changes-install" \
bash .evergreen/compile.sh

# checkout the newest release
newest=`cat VERSION_RELEASED`
current=`cat VERSION_CURRENT`

git checkout tags/$newest -f
git checkout "tags/${newest}" -f

# build the newest release
export SKIP_MOCK_TESTS=ON
export EXTRA_CONFIGURE_FLAGS="-DCMAKE_INSTALL_PREFIX=./abi-compliance/latest-release-install -DCMAKE_C_FLAGS=-g -Og"
sh .evergreen/compile.sh
make install
env \
CFLAGS="-g -Og" \
EXTRA_CONFIGURE_FLAGS="-DCMAKE_INSTALL_PREFIX=./abi-compliance/latest-release-install" \
bash .evergreen/compile.sh

# check for abi compliance. Generates HTML Reports.
cd abi-compliance

old_xml="<version>$newest</version>\n"
old_xml="${old_xml}<headers>\n"
old_xml="${old_xml}$(pwd)/latest-release-install/include/libmongoc-1.0/mongoc/mongoc.h\n"
old_xml="${old_xml}$(pwd)/latest-release-install/include/libbson-1.0/bson/bson.h\n"
old_xml="${old_xml}</headers>\n"
old_xml="${old_xml}<libs>$(pwd)/latest-release-install/lib</libs>"

printf $old_xml > old.xml

new_xml="<version>$current</version>\n"
new_xml="${new_xml}<headers>\n"
new_xml="${new_xml}$(pwd)/changes-install/include/libmongoc-1.0/mongoc/mongoc.h\n"
new_xml="${new_xml}$(pwd)/changes-install/include/libbson-1.0/bson/bson.h\n"
new_xml="${new_xml}</headers>\n"
new_xml="${new_xml}<libs>$(pwd)/changes-install/lib</libs>"

printf $new_xml > new.xml

# check for abi compliance. Generates HTML Reports
abi-compliance-checker -lib mongo-c-driver -old old.xml -new new.xml || result=$?
if [ -n "$result" ]; then
touch ./abi-error.txt
cat >|old.xml <<DOC
<version>${newest}</version>
<headers>
$(pwd)/latest-release-install/include/libmongoc-1.0/mongoc/mongoc.h
$(pwd)/latest-release-install/include/libbson-1.0/bson/bson.h
</headers>
<libs>$(pwd)/latest-release-install/lib</libs>
DOC

cat >|new.xml <<DOC
<version>${current}</version>
<headers>
$(pwd)/changes-install/include/libmongoc-1.0/mongoc/mongoc.h
$(pwd)/changes-install/include/libbson-1.0/bson/bson.h
</headers>
<libs>$(pwd)/changes-install/lib</libs>
DOC

if ! abi-compliance-checker -lib mongo-c-driver -old old.xml -new new.xml; then
touch ./abi-error.txt
fi
67 changes: 32 additions & 35 deletions .evergreen/add-build-dirs-to-paths.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
#!/bin/sh
set -o errexit # Exit the script with error if any of the commands fail
#!/usr/bin/env bash

set_path ()
{
case "$OS" in
cygwin*)
export PATH="$PATH:$(pwd)/src/libbson/Debug"
export PATH="$PATH:$(pwd)/src/libbson/Release"
export PATH="$PATH:$(pwd)/install-dir/bin"
chmod -f +x src/libmongoc/Debug/* || true
chmod -f +x src/libbson/Debug/* || true
chmod -f +x src/libmongoc/Release/* || true
chmod -f +x src/libbson/Release/* || true
chmod -f +x $(pwd)/install-dir/bin/* || true
;;
case "${OSTYPE}" in
cygwin)
export PATH
PATH="$(pwd)/install-dir/bin:${PATH:-}"
PATH="$(pwd)/src/libbson/Release:${PATH}"
PATH="$(pwd)/src/libbson/Debug:${PATH}"
chmod -f +x src/libmongoc/Debug/* || true
chmod -f +x src/libbson/Debug/* || true
chmod -f +x src/libmongoc/Release/* || true
chmod -f +x src/libbson/Release/* || true
chmod -f +x install-dir/bin/* || true
;;

darwin)
export DYLD_LIBRARY_PATH=".:install-dir/lib:install-dir/lib64:src/libbson:src/libmongoc:$EXTRA_LIB_PATH:$DYLD_LIBRARY_PATH"
;;
darwin*)
export DYLD_LIBRARY_PATH
DYLD_LIBRARY_PATH="${EXTRA_LIB_PATH:-}:${DYLD_LIBRARY_PATH:-}"
DYLD_LIBRARY_PATH="$(pwd)/src/libmongoc:${DYLD_LIBRARY_PATH}"
DYLD_LIBRARY_PATH="$(pwd)/src/libbson:${DYLD_LIBRARY_PATH}"
DYLD_LIBRARY_PATH="$(pwd)/install-dir/lib64:${DYLD_LIBRARY_PATH}"
DYLD_LIBRARY_PATH="$(pwd)/install-dir/lib:${DYLD_LIBRARY_PATH}"
DYLD_LIBRARY_PATH="$(pwd):${DYLD_LIBRARY_PATH}"
;;

*)
export LD_LIBRARY_PATH=".:install-dir/lib:install-dir/lib64:src/libbson:src/libmongoc:$EXTRA_LIB_PATH:$LD_LIBRARY_PATH"
;;
esac

case "$OS" in
cygwin*)
;;

*)
export PKG_CONFIG_PATH=$INSTALL_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
export PATH=$INSTALL_DIR/bin:$PATH
;;
esac
}

set_path
*)
export LD_LIBRARY_PATH
LD_LIBRARY_PATH="${EXTRA_LIB_PATH:-}:${LD_LIBRARY_PATH:-}"
LD_LIBRARY_PATH="$(pwd)/src/libmongoc:${LD_LIBRARY_PATH}"
LD_LIBRARY_PATH="$(pwd)/src/libbson:${LD_LIBRARY_PATH}"
LD_LIBRARY_PATH="$(pwd)/install-dir/lib64:${LD_LIBRARY_PATH}"
LD_LIBRARY_PATH="$(pwd)/install-dir/lib:${LD_LIBRARY_PATH}"
LD_LIBRARY_PATH="$(pwd):${LD_LIBRARY_PATH}"
;;
esac
136 changes: 87 additions & 49 deletions .evergreen/build-and-test-with-toolchain.sh
Original file line number Diff line number Diff line change
@@ -1,57 +1,95 @@
#!/bin/sh
set -o errexit # Exit the script with error if any of the commands fail
#!/usr/bin/env bash

set -o errexit
set -o pipefail

echo "BUILDING WITH TOOLCHAIN"

# Configure environment with toolchain components
[ -d /opt/mongo-c-toolchain ] && sudo rm -r /opt/mongo-c-toolchain
if [[ -d /opt/mongo-c-toolchain ]]; then
sudo rm -r /opt/mongo-c-toolchain
fi

sudo mkdir /opt/mongo-c-toolchain
TOOLCHAIN_TAR_GZ=$(readlink -f ../mongo-c-toolchain.tar.gz)
sudo tar -xvf "${TOOLCHAIN_TAR_GZ}" -C /opt/mongo-c-toolchain

declare toolchain_tar_gz
toolchain_tar_gz=$(readlink -f ../mongo-c-toolchain.tar.gz)
sudo tar -xvf "${toolchain_tar_gz}" -C /opt/mongo-c-toolchain

echo "--- TOOLCHAIN MANIFEST ---"
cat /opt/mongo-c-toolchain/MANIFEST.txt
OLD_PATH=${PATH}
ADDL_PATH=$(readlink -f /opt/mongo-c-toolchain/bin):${PATH}
export CMAKE=$(readlink -f /opt/mongo-c-toolchain/bin/cmake)
[ -x "${CMAKE}" ] || (echo "CMake (${CMAKE}) does not exist or is not executable"; exit 1)
TOOLCHAIN_BASE_DIR=$(readlink -f /opt/mongo-c-toolchain)
TOOLCHAIN_LIB_DIR=${TOOLCHAIN_BASE_DIR}/lib

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

cd ..
cp -a mongoc mongoc-${ssl_ver}
cd mongoc-${ssl_ver}
export PATH=$(readlink -f /opt/mongo-c-toolchain/${ssl_ver}/bin):${ADDL_PATH}:${OLD_PATH}
ssl_base_dir=$(readlink -f /opt/mongo-c-toolchain/${ssl_ver})
ssl_lib_dir=${ssl_base_dir}/lib
export EXTRA_CONFIGURE_FLAGS="-DCMAKE_VERBOSE_MAKEFILE=ON"
export EXTRA_CMAKE_PREFIX_PATH="${ssl_base_dir};${TOOLCHAIN_BASE_DIR}"

# Output some information about our build environment
"${CMAKE}" --version

# Run the build and tests
export LD_LIBRARY_PATH="${ssl_lib_dir}:${TOOLCHAIN_LIB_DIR}"
if [ "${ssl_ver#*libressl}" != "${ssl_ver}" ]; then
SSL_TYPE=LIBRESSL
else
SSL_TYPE=OPENSSL
fi
output_file=$(mktemp)
SSL=${SSL_TYPE} sh ./.evergreen/compile-unix.sh 2>&1 | tee -a "${output_file}"

# Verify that the toolchain components were used
if grep -Ec "[-]I/opt/mongo-c-toolchain/include" "${output_file}" >/dev/null \
&& grep -Ec "[-]I/opt/mongo-c-toolchain/${ssl_ver}/include" "${output_file}" >/dev/null \
&& grep -Ec "[-]L/opt/mongo-c-toolchain/lib" "${output_file}" >/dev/null \
&& grep -Ec "/opt/mongo-c-toolchain/${ssl_ver}/lib" "${output_file}" >/dev/null; then
echo "Toolchain components for ${ssl_ver} were detected in build output...continuing."
else
echo "TOOLCHAIN COMPONENTS FOR ${ssl_ver} NOT DETECTED IN BUILD OUTPUT...ABORTING!"
exit 1
fi
rm -f "${output_file}"

cd ../mongoc

declare addl_path
addl_path="$(readlink -f /opt/mongo-c-toolchain/bin):${PATH:-}"

declare cmake_binary
cmake_binary="$(readlink -f /opt/mongo-c-toolchain/bin/cmake)"

if [[ ! -x "${cmake_binary}" ]]; then
echo "CMake (${cmake_binary}) does not exist or is not executable" 1>&2
exit 1
fi

declare toolchain_base_dir
toolchain_base_dir="$(readlink -f /opt/mongo-c-toolchain)"

declare toolchain_lib_dir="${toolchain_base_dir}/lib"

declare -a ssl_vers=(
"libressl-2.5"
"libressl-3.0"
"openssl-1.0.1"
"openssl-1.0.1-fips"
"openssl-1.0.2"
"openssl-1.1.0"
)

for ssl_ver in "${ssl_vers[@]}"; do
cp -a ../mongoc "../mongoc-${ssl_ver}"
pushd "../mongoc-${ssl_ver}"

declare new_path
new_path="$(readlink -f "/opt/mongo-c-toolchain/${ssl_ver}/bin")"
new_path+=":${addl_path}"

declare ssl_base_dir
ssl_base_dir="$(readlink -f "/opt/mongo-c-toolchain/${ssl_ver}")"

declare ssl_lib_dir="${ssl_base_dir}/lib"

# Output some information about our build environment
"${cmake_binary}" --version

declare ssl
if [[ "${ssl_ver#*libressl}" != "${ssl_ver}" ]]; then
ssl="LIBRESSL"
else
ssl="OPENSSL"
fi

declare output_file
output_file="$(mktemp)"

env \
EXTRA_CMAKE_PREFIX_PATH="${ssl_base_dir};${toolchain_base_dir}" \
EXTRA_CONFIGURE_FLAGS="-DCMAKE_VERBOSE_MAKEFILE=ON" \
LD_LIBRARY_PATH="${ssl_lib_dir}:${toolchain_lib_dir}" \
PATH="${new_path}" \
SSL="${ssl}" \
bash ./.evergreen/compile-unix.sh 2>&1 | tee -a "${output_file}"

# Verify that the toolchain components were used
if grep -Ec "[-]I/opt/mongo-c-toolchain/include" "${output_file}" >/dev/null &&
grep -Ec "[-]I/opt/mongo-c-toolchain/${ssl_ver}/include" "${output_file}" >/dev/null &&
grep -Ec "[-]L/opt/mongo-c-toolchain/lib" "${output_file}" >/dev/null &&
grep -Ec "/opt/mongo-c-toolchain/${ssl_ver}/lib" "${output_file}" >/dev/null; then
echo "Toolchain components for ${ssl_ver} were detected in build output...continuing."
else
echo "TOOLCHAIN COMPONENTS FOR ${ssl_ver} NOT DETECTED IN BUILD OUTPUT...ABORTING!" 1>&2
exit 1
fi

rm -f "${output_file}"

popd # "mongoc-${ssl_ver}"
done
55 changes: 30 additions & 25 deletions .evergreen/bypass-dlclose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,44 @@
# bypass_dlclose command args...
#
# Parameters:
# "$@": command and arguments to evaluate.
# "$CC": compiler to use to compile and link the bypass_dlclose library.
#
# Evaluates the provided command and arguments with LD_PRELOAD defined to
# preload a `bypass_dlclose.so` library defining a no-op `dlclose()`.
# If necessary, also preloads the `libasan.so` library to satisfy linker
# requirements.
bypass_dlclose() {
: "${1:?'bypass_dlclose expects at least one argument to run as command!'}"
# Return 0 (true) if able to create a shared library to bypass calls to dlclose.
# Return a non-zero (false) value otherwise.
#
# If successful, print paths to add to LD_PRELOAD to stdout (pipe 1).
# Otherwise, no output is printed to stdout (pipe 1).
#
# Diagnostic messages may be printed to stderr (pipe 2). Redirect to /dev/null
# with `2>/dev/null` to silence these messages.
bypass_dlclose() (
: "${CC:?'bypass_dlclose expects environment variable CC to be defined!'}"

declare tmp
declare ld_preload

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

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

echo "int dlclose (void *handle) {(void) handle; return 0; }" >|"$tmp/bypass_dlclose.c"
echo "int dlclose (void *handle) {(void) handle; return 0; }" \
>|"${tmp}/bypass_dlclose.c" || return

"$CC" -o "$tmp/bypass_dlclose.so" -shared "$tmp/bypass_dlclose.c" || return
"${CC}" -o "${tmp}/bypass_dlclose.so" \
-shared "${tmp}/bypass_dlclose.c" || return

ld_preload="$tmp/bypass_dlclose.so"
ld_preload="${tmp}/bypass_dlclose.so"

# Clang uses its own libasan.so; do not preload it!
if [ "$CC" != "clang" ]; then
declare asan_path
asan_path="$($CC -print-file-name=libasan.so)" || return
ld_preload="$asan_path:$ld_preload"
fi
# Clang uses its own libasan.so; do not preload it!
if [ "${CC}" != "clang" ]; then
declare asan_path
asan_path="$(${CC} -print-file-name=libasan.so)" || return
ld_preload="${asan_path}:${ld_preload}"
fi
} 1>&2

LD_PRELOAD="$ld_preload:${LD_PRELOAD:-}" "$@"
}
printf "%s" "${ld_preload}"
)
Loading