Skip to content

Download and build-from-source valgrind 3.24.0 when not present #1383

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 3 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from config_generator.components.funcs.set_cache_dir import SetCacheDir

from config_generator.etc.function import Function
from config_generator.etc.utils import bash_exec

from shrub.v3.evg_command import EvgCommandType, expansions_update


class InstallValgrind(Function):
name = 'install-valgrind'
commands = SetCacheDir.commands + [
bash_exec(
command_type=EvgCommandType.SETUP,
script='''\
set -o errexit
set -o pipefail

if [[ ! -n "${MONGO_CXX_DRIVER_CACHE_DIR}" ]]; then
echo "MONGO_CXX_DRIVER_CACHE_DIR is not defined!" 1>&2
exit 1
fi

valgrind_install_dir="${MONGO_CXX_DRIVER_CACHE_DIR}/valgrind-3.24.0"
mkdir -p "$valgrind_install_dir"

if ! command -v "$valgrind_install_dir/bin/valgrind" 2>/dev/null; then
env \\
install_prefix="${MONGO_CXX_DRIVER_CACHE_DIR}/valgrind-3.24.0" \\
mongo-cxx-driver/.evergreen/scripts/valgrind-installer.sh
fi

PATH="$valgrind_install_dir/bin:$PATH" command -V valgrind
PATH="$valgrind_install_dir/bin:$PATH" valgrind --version

printf "VALGRIND_INSTALL_DIR: %s\\n" "$valgrind_install_dir/bin" >|expansions.valgrind.yml
''',
),
expansions_update(
command_type=EvgCommandType.SETUP,
file='expansions.valgrind.yml',
),
]


def functions():
return InstallValgrind.defn()
1 change: 1 addition & 0 deletions .evergreen/config_generator/components/funcs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Test(Function):
'TEST_WITH_VALGRIND',
'use_mongocryptd',
'USE_STATIC_LIBS',
'VALGRIND_INSTALL_DIR',
],
working_dir='mongo-cxx-driver',
script='.evergreen/scripts/test.sh',
Expand Down
2 changes: 2 additions & 0 deletions .evergreen/config_generator/components/valgrind.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from config_generator.components.funcs.compile import Compile
from config_generator.components.funcs.fetch_det import FetchDET
from config_generator.components.funcs.install_c_driver import InstallCDriver
from config_generator.components.funcs.install_valgrind import InstallValgrind
from config_generator.components.funcs.install_uv import InstallUV
from config_generator.components.funcs.run_kms_servers import RunKMSServers
from config_generator.components.funcs.setup import Setup
Expand Down Expand Up @@ -67,6 +68,7 @@ def tasks():

commands += [
Setup.call(),
InstallValgrind.call(),
StartMongod.call(mongodb_version=mongodb_version, topology=topology),
InstallCDriver.call(vars=icd_vars),
InstallUV.call(),
Expand Down
65 changes: 65 additions & 0 deletions .evergreen/generated_configs/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,70 @@ functions:
type: setup
params:
file: expansions.uv.yml
install-valgrind:
- command: subprocess.exec
type: setup
params:
binary: bash
args:
- -c
- |
if [[ -n "$XDG_CACHE_DIR" ]]; then
cache_dir="$XDG_CACHE_DIR" # XDG Base Directory specification.
elif [[ -n "$LOCALAPPDATA" ]]; then
cache_dir="$LOCALAPPDATA" # Windows.
elif [[ -n "$USERPROFILE" ]]; then
cache_dir="$USERPROFILE/.cache" # Windows (fallback).
elif [[ -d "$HOME/Library/Caches" ]]; then
cache_dir="$HOME/Library/Caches" # MacOS.
elif [[ -n "$HOME" ]]; then
cache_dir="$HOME/.cache" # Linux-like.
elif [[ -d ~/.cache ]]; then
cache_dir="~/.cache" # Linux-like (fallback).
else
cache_dir="$(pwd)/.cache" # EVG task directory (fallback).
fi

mkdir -p "$cache_dir/mongo-cxx-driver" || exit
cache_dir="$(cd "$cache_dir/mongo-cxx-driver" && pwd)" || exit

printf "MONGO_CXX_DRIVER_CACHE_DIR: %s\n" "$cache_dir" >|expansions.set-cache-dir.yml
- command: expansions.update
type: setup
params:
file: expansions.set-cache-dir.yml
- command: subprocess.exec
type: setup
params:
binary: bash
args:
- -c
- |
set -o errexit
set -o pipefail

if [[ ! -n "${MONGO_CXX_DRIVER_CACHE_DIR}" ]]; then
echo "MONGO_CXX_DRIVER_CACHE_DIR is not defined!" 1>&2
exit 1
fi

valgrind_install_dir="${MONGO_CXX_DRIVER_CACHE_DIR}/valgrind-3.24.0"
mkdir -p "$valgrind_install_dir"

if ! command -v "$valgrind_install_dir/bin/valgrind" 2>/dev/null; then
env \
install_prefix="${MONGO_CXX_DRIVER_CACHE_DIR}/valgrind-3.24.0" \
mongo-cxx-driver/.evergreen/scripts/valgrind-installer.sh
fi

PATH="$valgrind_install_dir/bin:$PATH" command -V valgrind
PATH="$valgrind_install_dir/bin:$PATH" valgrind --version

printf "VALGRIND_INSTALL_DIR: %s\n" "$valgrind_install_dir/bin" >|expansions.valgrind.yml
- command: expansions.update
type: setup
params:
file: expansions.valgrind.yml
install_c_driver:
- command: expansions.update
type: setup
Expand Down Expand Up @@ -607,6 +671,7 @@ functions:
- TEST_WITH_VALGRIND
- use_mongocryptd
- USE_STATIC_LIBS
- VALGRIND_INSTALL_DIR
args:
- -c
- .evergreen/scripts/test.sh
Expand Down
9 changes: 9 additions & 0 deletions .evergreen/generated_configs/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15889,6 +15889,7 @@ tasks:
updates:
- { key: build_type, value: Debug }
- func: setup
- func: install-valgrind
- func: start_mongod
vars:
TOPOLOGY: replica_set
Expand Down Expand Up @@ -15918,6 +15919,7 @@ tasks:
updates:
- { key: build_type, value: Debug }
- func: setup
- func: install-valgrind
- func: start_mongod
vars:
TOPOLOGY: sharded_cluster
Expand Down Expand Up @@ -15947,6 +15949,7 @@ tasks:
updates:
- { key: build_type, value: Debug }
- func: setup
- func: install-valgrind
- func: start_mongod
vars:
mongodb_version: "4.0"
Expand Down Expand Up @@ -15975,6 +15978,7 @@ tasks:
updates:
- { key: build_type, value: Debug }
- func: setup
- func: install-valgrind
- func: start_mongod
vars:
TOPOLOGY: replica_set
Expand Down Expand Up @@ -16004,6 +16008,7 @@ tasks:
updates:
- { key: build_type, value: Debug }
- func: setup
- func: install-valgrind
- func: start_mongod
vars:
TOPOLOGY: sharded_cluster
Expand Down Expand Up @@ -16033,6 +16038,7 @@ tasks:
updates:
- { key: build_type, value: Debug }
- func: setup
- func: install-valgrind
- func: start_mongod
vars:
mongodb_version: "8.0"
Expand Down Expand Up @@ -16061,6 +16067,7 @@ tasks:
updates:
- { key: build_type, value: Debug }
- func: setup
- func: install-valgrind
- func: start_mongod
vars:
TOPOLOGY: replica_set
Expand Down Expand Up @@ -16090,6 +16097,7 @@ tasks:
updates:
- { key: build_type, value: Debug }
- func: setup
- func: install-valgrind
- func: start_mongod
vars:
TOPOLOGY: sharded_cluster
Expand Down Expand Up @@ -16119,6 +16127,7 @@ tasks:
updates:
- { key: build_type, value: Debug }
- func: setup
- func: install-valgrind
- func: start_mongod
vars:
mongodb_version: latest
Expand Down
12 changes: 2 additions & 10 deletions .evergreen/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ set -o pipefail
: "${TEST_WITH_VALGRIND:-}"
: "${use_mongocryptd:-}"
: "${USE_STATIC_LIBS:-}"
: "${VALGRIND_INSTALL_DIR:-}" # Only when `TEST_WITH_VALGRIND` is set to "ON".

working_dir="$(pwd)"

Expand Down Expand Up @@ -282,16 +283,7 @@ else
export UBSAN_OPTIONS="print_stacktrace=1"
export PATH="/opt/mongodbtoolchain/v4/bin:${PATH:-}" # llvm-symbolizer
elif [[ "${TEST_WITH_VALGRIND:-}" == "ON" ]]; then
if ! command -v valgrind >/dev/null; then
if command -v yum >/dev/null; then
sudo yum install -q -y valgrind
elif command -v apt-get >/dev/null; then
sudo apt-get install -q -y valgrind
else
echo "Unknown how to install valgrind on this distro: ${distro_id:?}" 1>&2
exit 1
fi
fi
PATH="${VALGRIND_INSTALL_DIR:?}:${PATH:-}"
valgrind --version
run_test() {
valgrind --leak-check=full --track-origins=yes --num-callers=50 --error-exitcode=1 --error-limit=no --read-var-info=yes --suppressions=../etc/memcheck.suppressions "$@" "${test_args[@]:?}"
Expand Down
21 changes: 21 additions & 0 deletions .evergreen/scripts/valgrind-installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -o errexit
set -o pipefail

: "${install_prefix:?}"

cd "$(mktemp -d)"

# https://valgrind.org/downloads/current.html
curl -sSL -m 60 --retry 5 -o valgrind-3.24.0.tar.bz2 https://sourceware.org/pub/valgrind/valgrind-3.24.0.tar.bz2
cat >checksum.txt <<<'6fc0470fedc0d85dae3e042297cabd13c6100749 *valgrind-3.24.0.tar.bz2'
sha1sum -c checksum.txt >/dev/null

tar -xjf valgrind-3.24.0.tar.bz2
cd valgrind-3.24.0

# https://valgrind.org/docs/manual/manual-core.html#manual-core.install
./configure --prefix "${install_prefix:?}" >/dev/null
make --no-print-directory -j "$(nproc)" >/dev/null
make --no-print-directory install >/dev/null