Skip to content

Commit f5c55af

Browse files
authored
Download and build-from-source valgrind 3.24.0 when not present (#1383)
1 parent 88cad64 commit f5c55af

File tree

7 files changed

+146
-10
lines changed

7 files changed

+146
-10
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from config_generator.components.funcs.set_cache_dir import SetCacheDir
2+
3+
from config_generator.etc.function import Function
4+
from config_generator.etc.utils import bash_exec
5+
6+
from shrub.v3.evg_command import EvgCommandType, expansions_update
7+
8+
9+
class InstallValgrind(Function):
10+
name = 'install-valgrind'
11+
commands = SetCacheDir.commands + [
12+
bash_exec(
13+
command_type=EvgCommandType.SETUP,
14+
script='''\
15+
set -o errexit
16+
set -o pipefail
17+
18+
if [[ ! -n "${MONGO_CXX_DRIVER_CACHE_DIR}" ]]; then
19+
echo "MONGO_CXX_DRIVER_CACHE_DIR is not defined!" 1>&2
20+
exit 1
21+
fi
22+
23+
valgrind_install_dir="${MONGO_CXX_DRIVER_CACHE_DIR}/valgrind-3.24.0"
24+
mkdir -p "$valgrind_install_dir"
25+
26+
if ! command -v "$valgrind_install_dir/bin/valgrind" 2>/dev/null; then
27+
env \\
28+
install_prefix="${MONGO_CXX_DRIVER_CACHE_DIR}/valgrind-3.24.0" \\
29+
mongo-cxx-driver/.evergreen/scripts/valgrind-installer.sh
30+
fi
31+
32+
PATH="$valgrind_install_dir/bin:$PATH" command -V valgrind
33+
PATH="$valgrind_install_dir/bin:$PATH" valgrind --version
34+
35+
printf "VALGRIND_INSTALL_DIR: %s\\n" "$valgrind_install_dir/bin" >|expansions.valgrind.yml
36+
''',
37+
),
38+
expansions_update(
39+
command_type=EvgCommandType.SETUP,
40+
file='expansions.valgrind.yml',
41+
),
42+
]
43+
44+
45+
def functions():
46+
return InstallValgrind.defn()

.evergreen/config_generator/components/funcs/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Test(Function):
3737
'TEST_WITH_VALGRIND',
3838
'use_mongocryptd',
3939
'USE_STATIC_LIBS',
40+
'VALGRIND_INSTALL_DIR',
4041
],
4142
working_dir='mongo-cxx-driver',
4243
script='.evergreen/scripts/test.sh',

.evergreen/config_generator/components/valgrind.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from config_generator.components.funcs.compile import Compile
22
from config_generator.components.funcs.fetch_det import FetchDET
33
from config_generator.components.funcs.install_c_driver import InstallCDriver
4+
from config_generator.components.funcs.install_valgrind import InstallValgrind
45
from config_generator.components.funcs.install_uv import InstallUV
56
from config_generator.components.funcs.run_kms_servers import RunKMSServers
67
from config_generator.components.funcs.setup import Setup
@@ -67,6 +68,7 @@ def tasks():
6768

6869
commands += [
6970
Setup.call(),
71+
InstallValgrind.call(),
7072
StartMongod.call(mongodb_version=mongodb_version, topology=topology),
7173
InstallCDriver.call(vars=icd_vars),
7274
InstallUV.call(),

.evergreen/generated_configs/functions.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,70 @@ functions:
392392
type: setup
393393
params:
394394
file: expansions.uv.yml
395+
install-valgrind:
396+
- command: subprocess.exec
397+
type: setup
398+
params:
399+
binary: bash
400+
args:
401+
- -c
402+
- |
403+
if [[ -n "$XDG_CACHE_DIR" ]]; then
404+
cache_dir="$XDG_CACHE_DIR" # XDG Base Directory specification.
405+
elif [[ -n "$LOCALAPPDATA" ]]; then
406+
cache_dir="$LOCALAPPDATA" # Windows.
407+
elif [[ -n "$USERPROFILE" ]]; then
408+
cache_dir="$USERPROFILE/.cache" # Windows (fallback).
409+
elif [[ -d "$HOME/Library/Caches" ]]; then
410+
cache_dir="$HOME/Library/Caches" # MacOS.
411+
elif [[ -n "$HOME" ]]; then
412+
cache_dir="$HOME/.cache" # Linux-like.
413+
elif [[ -d ~/.cache ]]; then
414+
cache_dir="~/.cache" # Linux-like (fallback).
415+
else
416+
cache_dir="$(pwd)/.cache" # EVG task directory (fallback).
417+
fi
418+
419+
mkdir -p "$cache_dir/mongo-cxx-driver" || exit
420+
cache_dir="$(cd "$cache_dir/mongo-cxx-driver" && pwd)" || exit
421+
422+
printf "MONGO_CXX_DRIVER_CACHE_DIR: %s\n" "$cache_dir" >|expansions.set-cache-dir.yml
423+
- command: expansions.update
424+
type: setup
425+
params:
426+
file: expansions.set-cache-dir.yml
427+
- command: subprocess.exec
428+
type: setup
429+
params:
430+
binary: bash
431+
args:
432+
- -c
433+
- |
434+
set -o errexit
435+
set -o pipefail
436+
437+
if [[ ! -n "${MONGO_CXX_DRIVER_CACHE_DIR}" ]]; then
438+
echo "MONGO_CXX_DRIVER_CACHE_DIR is not defined!" 1>&2
439+
exit 1
440+
fi
441+
442+
valgrind_install_dir="${MONGO_CXX_DRIVER_CACHE_DIR}/valgrind-3.24.0"
443+
mkdir -p "$valgrind_install_dir"
444+
445+
if ! command -v "$valgrind_install_dir/bin/valgrind" 2>/dev/null; then
446+
env \
447+
install_prefix="${MONGO_CXX_DRIVER_CACHE_DIR}/valgrind-3.24.0" \
448+
mongo-cxx-driver/.evergreen/scripts/valgrind-installer.sh
449+
fi
450+
451+
PATH="$valgrind_install_dir/bin:$PATH" command -V valgrind
452+
PATH="$valgrind_install_dir/bin:$PATH" valgrind --version
453+
454+
printf "VALGRIND_INSTALL_DIR: %s\n" "$valgrind_install_dir/bin" >|expansions.valgrind.yml
455+
- command: expansions.update
456+
type: setup
457+
params:
458+
file: expansions.valgrind.yml
395459
install_c_driver:
396460
- command: expansions.update
397461
type: setup
@@ -607,6 +671,7 @@ functions:
607671
- TEST_WITH_VALGRIND
608672
- use_mongocryptd
609673
- USE_STATIC_LIBS
674+
- VALGRIND_INSTALL_DIR
610675
args:
611676
- -c
612677
- .evergreen/scripts/test.sh

.evergreen/generated_configs/tasks.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15889,6 +15889,7 @@ tasks:
1588915889
updates:
1589015890
- { key: build_type, value: Debug }
1589115891
- func: setup
15892+
- func: install-valgrind
1589215893
- func: start_mongod
1589315894
vars:
1589415895
TOPOLOGY: replica_set
@@ -15918,6 +15919,7 @@ tasks:
1591815919
updates:
1591915920
- { key: build_type, value: Debug }
1592015921
- func: setup
15922+
- func: install-valgrind
1592115923
- func: start_mongod
1592215924
vars:
1592315925
TOPOLOGY: sharded_cluster
@@ -15947,6 +15949,7 @@ tasks:
1594715949
updates:
1594815950
- { key: build_type, value: Debug }
1594915951
- func: setup
15952+
- func: install-valgrind
1595015953
- func: start_mongod
1595115954
vars:
1595215955
mongodb_version: "4.0"
@@ -15975,6 +15978,7 @@ tasks:
1597515978
updates:
1597615979
- { key: build_type, value: Debug }
1597715980
- func: setup
15981+
- func: install-valgrind
1597815982
- func: start_mongod
1597915983
vars:
1598015984
TOPOLOGY: replica_set
@@ -16004,6 +16008,7 @@ tasks:
1600416008
updates:
1600516009
- { key: build_type, value: Debug }
1600616010
- func: setup
16011+
- func: install-valgrind
1600716012
- func: start_mongod
1600816013
vars:
1600916014
TOPOLOGY: sharded_cluster
@@ -16033,6 +16038,7 @@ tasks:
1603316038
updates:
1603416039
- { key: build_type, value: Debug }
1603516040
- func: setup
16041+
- func: install-valgrind
1603616042
- func: start_mongod
1603716043
vars:
1603816044
mongodb_version: "8.0"
@@ -16061,6 +16067,7 @@ tasks:
1606116067
updates:
1606216068
- { key: build_type, value: Debug }
1606316069
- func: setup
16070+
- func: install-valgrind
1606416071
- func: start_mongod
1606516072
vars:
1606616073
TOPOLOGY: replica_set
@@ -16090,6 +16097,7 @@ tasks:
1609016097
updates:
1609116098
- { key: build_type, value: Debug }
1609216099
- func: setup
16100+
- func: install-valgrind
1609316101
- func: start_mongod
1609416102
vars:
1609516103
TOPOLOGY: sharded_cluster
@@ -16119,6 +16127,7 @@ tasks:
1611916127
updates:
1612016128
- { key: build_type, value: Debug }
1612116129
- func: setup
16130+
- func: install-valgrind
1612216131
- func: start_mongod
1612316132
vars:
1612416133
mongodb_version: latest

.evergreen/scripts/test.sh

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ set -o pipefail
3030
: "${TEST_WITH_VALGRIND:-}"
3131
: "${use_mongocryptd:-}"
3232
: "${USE_STATIC_LIBS:-}"
33+
: "${VALGRIND_INSTALL_DIR:-}" # Only when `TEST_WITH_VALGRIND` is set to "ON".
3334

3435
working_dir="$(pwd)"
3536

@@ -282,16 +283,7 @@ else
282283
export UBSAN_OPTIONS="print_stacktrace=1"
283284
export PATH="/opt/mongodbtoolchain/v4/bin:${PATH:-}" # llvm-symbolizer
284285
elif [[ "${TEST_WITH_VALGRIND:-}" == "ON" ]]; then
285-
if ! command -v valgrind >/dev/null; then
286-
if command -v yum >/dev/null; then
287-
sudo yum install -q -y valgrind
288-
elif command -v apt-get >/dev/null; then
289-
sudo apt-get install -q -y valgrind
290-
else
291-
echo "Unknown how to install valgrind on this distro: ${distro_id:?}" 1>&2
292-
exit 1
293-
fi
294-
fi
286+
PATH="${VALGRIND_INSTALL_DIR:?}:${PATH:-}"
295287
valgrind --version
296288
run_test() {
297289
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[@]:?}"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
6+
: "${install_prefix:?}"
7+
8+
cd "$(mktemp -d)"
9+
10+
# https://valgrind.org/downloads/current.html
11+
curl -sSL -m 60 --retry 5 -o valgrind-3.24.0.tar.bz2 https://sourceware.org/pub/valgrind/valgrind-3.24.0.tar.bz2
12+
cat >checksum.txt <<<'6fc0470fedc0d85dae3e042297cabd13c6100749 *valgrind-3.24.0.tar.bz2'
13+
sha1sum -c checksum.txt >/dev/null
14+
15+
tar -xjf valgrind-3.24.0.tar.bz2
16+
cd valgrind-3.24.0
17+
18+
# https://valgrind.org/docs/manual/manual-core.html#manual-core.install
19+
./configure --prefix "${install_prefix:?}" >/dev/null
20+
make --no-print-directory -j "$(nproc)" >/dev/null
21+
make --no-print-directory install >/dev/null

0 commit comments

Comments
 (0)