-
Notifications
You must be signed in to change notification settings - Fork 0
/
is_debug.sh
executable file
·128 lines (110 loc) · 2.96 KB
/
is_debug.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#~/bin/bash
show_snippet() {
echo ""
echo "Code snippet:"
echo "ffi = require('ffi') ffi.cdef('int is_debug;') ffi.C.is_debug = 1"
}
usage() {
echo "Inject or remove global int is_debug variable to tarantool source."
echo "Usage:"
echo "$0 set - inject variable"
echo "$0 set make - inject variable and make"
echo "$0 unset - remove injection"
echo "$0 unset make - remove injection and make"
echo "$0 <anything else - show current status and this help"
show_snippet
exit 0
}
error() {
echo "$@" 1>&2
exit 1
}
do_show=false
do_set=false
do_unset=false
do_make=false
if [[ $# > 2 ]]; then
usage
fi
if [[ $# == 0 ]]; then
do_show=true
else
if [[ "$1" == "set" ]]; then
do_set=true
elif [[ "$1" == "unset" ]]; then
do_unset=true
else
usage
fi
if [[ $# == 2 ]]; then
if [[ "$2" == "make" ]]; then
do_make=true
else
usage
fi
fi
fi
builddir=`realpath .`
if ! [[ -f "$builddir/CMakeCache.txt" ]]; then
error "Tarantool build was not found in '$builddir'"
fi
line=$(grep "^tarantool_SOURCE_DIR:STATIC=" "$builddir/CMakeCache.txt")
if ! [[ "$line" =~ ^tarantool_SOURCE_DIR:STATIC=(.*)$ ]]; then
error "Tarantool build was not found in '$builddir'"
fi
sourcedir="${BASH_REMATCH[1]}"
exports_file="$sourcedir/extra/exports"
main_file="$sourcedir/src/main.cc"
exports_string="is_debug"
main_string="int is_debug;"
if ! [[ -f "$exports_file" ]]; then
error "Exports file was not found: $exports_file"
fi
if ! [[ -f "$main_file" ]]; then
error "Main file was not found: $main_file"
fi
if grep -xq "$exports_string" "$exports_file"; then
is_in_exports=true
echo "'$exports_string' IS in exports file"
else
is_in_exports=false
echo "'$exports_string' is NOT in exports file"
fi
if grep -xq "$main_string" "$main_file"; then
is_in_main=true
echo "'$main_string' IS in main file"
else
is_in_main=false
echo "'$main_string' is NOT in main file"
fi
if [[ $do_show == true ]]; then
show_snippet
exit 0
fi
echo "--------------"
if [[ $do_set == true ]]; then
if [[ $is_in_exports == false ]]; then
echo "$exports_string" >> "$exports_file"
echo "'$exports_string' was injected to exports file"
fi
if [[ $is_in_main == false ]]; then
echo "$main_string" >> "$main_file"
echo "'$main_string' was injected to main file"
fi
else
if [[ $is_in_exports == true ]]; then
grep -vx "$exports_string" "$exports_file" > ./is_debug.tmp
mv ./is_debug.tmp "$exports_file"
echo "'$exports_string' was removed from exports file"
fi
if [[ $is_in_main == true ]]; then
grep -vx "$main_string" "$main_file" > ./is_debug.tmp
mv ./is_debug.tmp "$main_file"
echo "'$main_string' was removed from main file"
fi
fi
if [[ $do_make == true ]]; then
make -j
fi
show_snippet
echo "Done"