Skip to content

Commit 0ea4f2b

Browse files
committed
Download and build-from-source valgrind 3.24.0 when not present (#1383)
1 parent dee9233 commit 0ea4f2b

File tree

8 files changed

+221
-0
lines changed

8 files changed

+221
-0
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()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from config_generator.etc.function import Function
2+
from config_generator.etc.utils import bash_exec
3+
4+
from shrub.v3.evg_command import EvgCommandType, expansions_update
5+
6+
7+
class SetCacheDir(Function):
8+
name = 'set-cache-dir'
9+
commands = [
10+
bash_exec(
11+
command_type=EvgCommandType.SETUP,
12+
script='''\
13+
if [[ -n "$XDG_CACHE_DIR" ]]; then
14+
cache_dir="$XDG_CACHE_DIR" # XDG Base Directory specification.
15+
elif [[ -n "$LOCALAPPDATA" ]]; then
16+
cache_dir="$LOCALAPPDATA" # Windows.
17+
elif [[ -n "$USERPROFILE" ]]; then
18+
cache_dir="$USERPROFILE/.cache" # Windows (fallback).
19+
elif [[ -d "$HOME/Library/Caches" ]]; then
20+
cache_dir="$HOME/Library/Caches" # MacOS.
21+
elif [[ -n "$HOME" ]]; then
22+
cache_dir="$HOME/.cache" # Linux-like.
23+
elif [[ -d ~/.cache ]]; then
24+
cache_dir="~/.cache" # Linux-like (fallback).
25+
else
26+
cache_dir="$(pwd)/.cache" # EVG task directory (fallback).
27+
fi
28+
29+
mkdir -p "$cache_dir/mongo-cxx-driver" || exit
30+
cache_dir="$(cd "$cache_dir/mongo-cxx-driver" && pwd)" || exit
31+
32+
printf "MONGO_CXX_DRIVER_CACHE_DIR: %s\\n" "$cache_dir" >|expansions.set-cache-dir.yml
33+
''',
34+
),
35+
expansions_update(
36+
command_type=EvgCommandType.SETUP,
37+
file='expansions.set-cache-dir.yml'
38+
),
39+
]
40+
41+
42+
def functions():
43+
return SetCacheDir.defn()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Test(Function):
3838
'TEST_WITH_VALGRIND',
3939
'use_mongocryptd',
4040
'USE_STATIC_LIBS',
41+
'VALGRIND_INSTALL_DIR',
4142
],
4243
working_dir='mongo-cxx-driver',
4344
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.run_kms_servers import RunKMSServers
56
from config_generator.components.funcs.setup import Setup
67
from config_generator.components.funcs.start_mongod import StartMongod
@@ -76,6 +77,7 @@ def tasks():
7677

7778
commands += [
7879
Setup.call(),
80+
InstallValgrind.call(),
7981
StartMongod.call(mongodb_version=mongodb_version, topology=topology),
8082
InstallCDriver.call(vars=icd_vars),
8183
Compile.call(compiler=compiler, vars=compile_vars),

.evergreen/generated_configs/functions.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,70 @@ functions:
325325
args:
326326
- -c
327327
- git clone --depth 1 https://github.com/mongodb/mongo-c-driver mongoc
328+
install-valgrind:
329+
- command: subprocess.exec
330+
type: setup
331+
params:
332+
binary: bash
333+
args:
334+
- -c
335+
- |
336+
if [[ -n "$XDG_CACHE_DIR" ]]; then
337+
cache_dir="$XDG_CACHE_DIR" # XDG Base Directory specification.
338+
elif [[ -n "$LOCALAPPDATA" ]]; then
339+
cache_dir="$LOCALAPPDATA" # Windows.
340+
elif [[ -n "$USERPROFILE" ]]; then
341+
cache_dir="$USERPROFILE/.cache" # Windows (fallback).
342+
elif [[ -d "$HOME/Library/Caches" ]]; then
343+
cache_dir="$HOME/Library/Caches" # MacOS.
344+
elif [[ -n "$HOME" ]]; then
345+
cache_dir="$HOME/.cache" # Linux-like.
346+
elif [[ -d ~/.cache ]]; then
347+
cache_dir="~/.cache" # Linux-like (fallback).
348+
else
349+
cache_dir="$(pwd)/.cache" # EVG task directory (fallback).
350+
fi
351+
352+
mkdir -p "$cache_dir/mongo-cxx-driver" || exit
353+
cache_dir="$(cd "$cache_dir/mongo-cxx-driver" && pwd)" || exit
354+
355+
printf "MONGO_CXX_DRIVER_CACHE_DIR: %s\n" "$cache_dir" >|expansions.set-cache-dir.yml
356+
- command: expansions.update
357+
type: setup
358+
params:
359+
file: expansions.set-cache-dir.yml
360+
- command: subprocess.exec
361+
type: setup
362+
params:
363+
binary: bash
364+
args:
365+
- -c
366+
- |
367+
set -o errexit
368+
set -o pipefail
369+
370+
if [[ ! -n "${MONGO_CXX_DRIVER_CACHE_DIR}" ]]; then
371+
echo "MONGO_CXX_DRIVER_CACHE_DIR is not defined!" 1>&2
372+
exit 1
373+
fi
374+
375+
valgrind_install_dir="${MONGO_CXX_DRIVER_CACHE_DIR}/valgrind-3.24.0"
376+
mkdir -p "$valgrind_install_dir"
377+
378+
if ! command -v "$valgrind_install_dir/bin/valgrind" 2>/dev/null; then
379+
env \
380+
install_prefix="${MONGO_CXX_DRIVER_CACHE_DIR}/valgrind-3.24.0" \
381+
mongo-cxx-driver/.evergreen/scripts/valgrind-installer.sh
382+
fi
383+
384+
PATH="$valgrind_install_dir/bin:$PATH" command -V valgrind
385+
PATH="$valgrind_install_dir/bin:$PATH" valgrind --version
386+
387+
printf "VALGRIND_INSTALL_DIR: %s\n" "$valgrind_install_dir/bin" >|expansions.valgrind.yml
388+
- command: expansions.update
389+
type: setup
390+
params:
391+
file: expansions.valgrind.yml
328392
install_c_driver:
329393
- command: expansions.update
330394
type: setup
@@ -416,6 +480,38 @@ functions:
416480
export DRIVERS_TOOLS=$(pwd)
417481
418482
.evergreen/atlas_data_lake/run-mongohouse-image.sh
483+
set-cache-dir:
484+
- command: subprocess.exec
485+
type: setup
486+
params:
487+
binary: bash
488+
args:
489+
- -c
490+
- |
491+
if [[ -n "$XDG_CACHE_DIR" ]]; then
492+
cache_dir="$XDG_CACHE_DIR" # XDG Base Directory specification.
493+
elif [[ -n "$LOCALAPPDATA" ]]; then
494+
cache_dir="$LOCALAPPDATA" # Windows.
495+
elif [[ -n "$USERPROFILE" ]]; then
496+
cache_dir="$USERPROFILE/.cache" # Windows (fallback).
497+
elif [[ -d "$HOME/Library/Caches" ]]; then
498+
cache_dir="$HOME/Library/Caches" # MacOS.
499+
elif [[ -n "$HOME" ]]; then
500+
cache_dir="$HOME/.cache" # Linux-like.
501+
elif [[ -d ~/.cache ]]; then
502+
cache_dir="~/.cache" # Linux-like (fallback).
503+
else
504+
cache_dir="$(pwd)/.cache" # EVG task directory (fallback).
505+
fi
506+
507+
mkdir -p "$cache_dir/mongo-cxx-driver" || exit
508+
cache_dir="$(cd "$cache_dir/mongo-cxx-driver" && pwd)" || exit
509+
510+
printf "MONGO_CXX_DRIVER_CACHE_DIR: %s\n" "$cache_dir" >|expansions.set-cache-dir.yml
511+
- command: expansions.update
512+
type: setup
513+
params:
514+
file: expansions.set-cache-dir.yml
419515
setup:
420516
- command: subprocess.exec
421517
type: setup
@@ -517,6 +613,7 @@ functions:
517613
- TEST_WITH_VALGRIND
518614
- use_mongocryptd
519615
- USE_STATIC_LIBS
616+
- VALGRIND_INSTALL_DIR
520617
args:
521618
- -c
522619
- .evergreen/scripts/test.sh

.evergreen/generated_configs/tasks.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4322,6 +4322,7 @@ tasks:
43224322
updates:
43234323
- { key: build_type, value: Debug }
43244324
- func: setup
4325+
- func: install-valgrind
43254326
- func: start_mongod
43264327
vars:
43274328
mongodb_version: "5.0"
@@ -4349,6 +4350,7 @@ tasks:
43494350
updates:
43504351
- { key: build_type, value: Debug }
43514352
- func: setup
4353+
- func: install-valgrind
43524354
- func: start_mongod
43534355
vars:
43544356
mongodb_version: "5.0"
@@ -4378,6 +4380,7 @@ tasks:
43784380
- { key: build_type, value: Debug }
43794381
- { key: USE_STATIC_LIBS, value: "1" }
43804382
- func: setup
4383+
- func: install-valgrind
43814384
- func: start_mongod
43824385
vars:
43834386
mongodb_version: "5.0"
@@ -4406,6 +4409,7 @@ tasks:
44064409
- { key: build_type, value: Debug }
44074410
- { key: USE_STATIC_LIBS, value: "1" }
44084411
- func: setup
4412+
- func: install-valgrind
44094413
- func: start_mongod
44104414
vars:
44114415
mongodb_version: "5.0"
@@ -4434,6 +4438,7 @@ tasks:
44344438
updates:
44354439
- { key: build_type, value: Debug }
44364440
- func: setup
4441+
- func: install-valgrind
44374442
- func: start_mongod
44384443
vars:
44394444
mongodb_version: latest
@@ -4462,6 +4467,7 @@ tasks:
44624467
updates:
44634468
- { key: build_type, value: Debug }
44644469
- func: setup
4470+
- func: install-valgrind
44654471
- func: start_mongod
44664472
vars:
44674473
mongodb_version: latest
@@ -4490,6 +4496,7 @@ tasks:
44904496
- { key: build_type, value: Debug }
44914497
- { key: USE_STATIC_LIBS, value: "1" }
44924498
- func: setup
4499+
- func: install-valgrind
44934500
- func: start_mongod
44944501
vars:
44954502
mongodb_version: latest
@@ -4519,6 +4526,7 @@ tasks:
45194526
- { key: build_type, value: Debug }
45204527
- { key: USE_STATIC_LIBS, value: "1" }
45214528
- func: setup
4529+
- func: install-valgrind
45224530
- func: start_mongod
45234531
vars:
45244532
mongodb_version: latest

.evergreen/scripts/test.sh

Lines changed: 3 additions & 0 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

@@ -274,6 +275,8 @@ else
274275
export UBSAN_OPTIONS="print_stacktrace=1"
275276
export PATH="/usr/lib/llvm-3.8/bin:${PATH:-}"
276277
elif [[ "${TEST_WITH_VALGRIND:-}" == "ON" ]]; then
278+
PATH="${VALGRIND_INSTALL_DIR:?}:${PATH:-}"
279+
valgrind --version
277280
run_test() {
278281
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[@]:?}"
279282
}
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)