forked from hluk/CopyQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sanitize.sh
executable file
·63 lines (49 loc) · 1.29 KB
/
sanitize.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
set -e
sanitizers="address,leak,bounds,bool,enum,null,undefined"
export CXX_FLAGS="$CXX_FLAGS -fno-omit-frame-pointer -mllvm -asan-use-private-alias=1"
build_dir=build-sanitize
utils_dir=$(dirname "$(readlink -f "$0")")
src_dir=$utils_dir/..
steps=(
clean
cmake
ninja
run
)
if [ -n "$CLANG_ROOT" ]; then
export PATH=$CLANG_ROOT:$PATH
fi
CXX=${CXX:-clang++}
export ASAN_SYMBOLIZER_PATH=${ASAN_SYMBOLIZER_PATH:-$(which llvm-symbolizer)}
export ASAN_OPTIONS=${ASAN_OPTIONS:-"detect_leaks=1 detect_stack_use_after_return=1 print_stats=1 use_odr_indicator=1"}
echo "=== Using sanitizers (directory \"$build_dir\") ==="
step=2
if [ -d "$build_dir" ]; then
echo "Select starting point:"
select step in "${steps[@]}"; do step=$REPLY; break; done
fi
has_step () {
[[ $step -le $1 ]]
}
has_step "${#steps[*]}"
if has_step 1; then
rm -r "$build_dir" || exit 1
fi
mkdir -p "$build_dir"
cd "$build_dir"
if has_step 2; then
cmake \
-DCMAKE_INSTALL_PREFIX="$PWD/install" \
-DCMAKE_CXX_COMPILER="$CXX" \
-DCMAKE_CXX_FLAGS="$CXX_FLAGS -fsanitize=$sanitizers" \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_GENERATOR=Ninja \
"$src_dir"
fi
if has_step 3; then
ninja install
fi
if has_step 4; then
./copyq -s test1 "$@"
fi