forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·244 lines (217 loc) · 6.83 KB
/
build.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/bin/bash
TOPDIR=`readlink -f \`dirname $0\``
BUILD_SH=$TOPDIR/build.sh
DEP_DIR=${TOPDIR}/deps/3rd/usr/local/oceanbase/deps/devel
TOOLS_DIR=${TOPDIR}/deps/3rd/usr/local/oceanbase/devtools
CMAKE_COMMAND="${TOOLS_DIR}/bin/cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1"
CPU_CORES=`grep -c ^processor /proc/cpuinfo`
KERNEL_RELEASE=`grep -Po 'release [0-9]{1}' /etc/issue 2>/dev/null`
ALL_ARGS=("$@")
BUILD_ARGS=()
MAKE_ARGS=(-j $CPU_CORES)
NEED_MAKE=false
NEED_INIT=false
LLD_OPTION=ON
ASAN_OPTION=ON
STATIC_LINK_LGPL_DEPS_OPTION=ON
echo "$0 ${ALL_ARGS[@]}"
function echo_log() {
echo -e "[build.sh] $@"
}
function echo_err() {
echo -e "[build.sh][ERROR] $@" 1>&2
}
function usage
{
echo -e "Usage:"
echo -e "\t./build.sh -h"
echo -e "\t./build.sh init"
echo -e "\t./build.sh clean"
echo -e "\t./build.sh [BuildType] [--init] [--make [MakeOptions]]"
echo -e "\nOPTIONS:"
echo -e "\tBuildType => debug(default), release, errsim, dissearray, rpm"
echo -e "\tMakeOptions => Options to make command, default: -j N"
echo -e "\nExamples:"
echo -e "\t# Build by debug mode and make with -j24."
echo -e "\t./build.sh debug --make -j24"
echo -e "\n\t# Init and build with release mode but not compile."
echo -e "\t./build.sh release --init"
echo -e "\n\t# Build with rpm mode and make with default arguments."
echo -e "\t./build.sh rpm --make"
}
# parse arguments
function parse_args
{
for i in "${ALL_ARGS[@]}"; do
if [[ "$i" == "--init" ]]
then
NEED_INIT=true
elif [[ "$i" == "--make" ]]
then
NEED_MAKE=make
elif [[ $NEED_MAKE == false ]]
then
BUILD_ARGS+=("$i")
else
MAKE_ARGS+=("$i")
fi
done
if [[ "$KERNEL_RELEASE" == "release 6" ]]; then
echo_log '[NOTICE] lld is disabled in kernel release 6'
LLD_OPTION="OFF"
fi
}
# try call command make, if use give --make in command line.
function try_make
{
if [[ $NEED_MAKE != false ]]
then
$NEED_MAKE "${MAKE_ARGS[@]}"
fi
}
# try call init if --init given.
function try_init
{
if [[ $NEED_INIT == true ]]
then
do_init || exit $?
fi
}
# create build directory and cd it.
function prepare_build_dir
{
TYPE=$1
mkdir -p $TOPDIR/build_$TYPE && cd $TOPDIR/build_$TYPE
}
# dep_create
function do_init
{
time1_ms=$(echo $[$(date +%s%N)/1000000])
(cd $TOPDIR/deps/init && bash dep_create.sh)
if [ $? -ne 0 ]; then
exit $?
fi
time2_ms=$(echo $[$(date +%s%N)/1000000])
cost_time_ms=$(($time2_ms - $time1_ms))
cost_time_s=`expr $cost_time_ms / 1000`
let min=cost_time_s/60
let sec=cost_time_s%60
echo_log "use dep_create.sh to create deps cost time: ${min}m${sec}s"
}
# make build directory && cmake && make (if need)
function do_build
{
if [ ! -f ${TOOLS_DIR}/bin/cmake ]; then
echo_log "[NOTICE] Your workspace has not initialized dependencies, please append '--init' args to initialize dependencies"
exit 1
fi
TYPE=$1; shift
prepare_build_dir $TYPE || return
${CMAKE_COMMAND} ${TOPDIR} "$@"
if [ $? -ne 0 ]; then
echo_err "Failed to generate Makefile"
exit 1
fi
}
# clean build directories
function do_clean
{
echo_log "cleaning..."
find . -maxdepth 1 -type d -name 'build_*' | grep -v 'build_ccls' | xargs rm -rf
}
# build - configurate project and prepare to compile, by calling make
function build
{
set -- "${BUILD_ARGS[@]}"
case "x$1" in
xrelease)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOB_USE_LLD=$LLD_OPTION
;;
xrelease_no_unity)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOB_USE_LLD=$LLD_OPTION -DOB_ENABLE_UNITY=OFF
;;
xrelease_asan)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOB_USE_LLD=$LLD_OPTION -DOB_USE_ASAN=$ASAN_OPTION
;;
xdebug)
do_build "$@" -DCMAKE_BUILD_TYPE=Debug -DOB_USE_LLD=$LLD_OPTION
;;
xdebug_no_unity)
do_build "$@" -DCMAKE_BUILD_TYPE=Debug -DOB_USE_LLD=$LLD_OPTION -DOB_ENABLE_UNITY=OFF
;;
xccls)
do_build "$@" -DCMAKE_BUILD_TYPE=Debug -DOB_USE_LLD=$LLD_OPTION -DOB_BUILD_CCLS=ON
# build soft link for ccls
ln -sf ${TOPDIR}/build_ccls/compile_commands.json ${TOPDIR}/compile_commands.json
;;
xperf)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_AUTO_FDO=ON -DENABLE_THIN_LTO=ON -DOB_USE_LLD=$LLD_OPTION -DENABLE_PERF_MODE=ON
;;
xdebug_asan)
do_build "$@" -DCMAKE_BUILD_TYPE=Debug -DOB_USE_LLD=$LLD_OPTION -DOB_USE_ASAN=$ASAN_OPTION
;;
xerrsim_asan)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOB_ERRSIM=ON -DOB_USE_LLD=$LLD_OPTION -DOB_USE_ASAN=$ASAN_OPTION
;;
xerrsim_debug)
do_build "$@" -DCMAKE_BUILD_TYPE=Debug -DOB_ERRSIM=ON -DOB_USE_LLD=$LLD_OPTION
;;
xerrsim)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOB_ERRSIM=ON -DOB_USE_LLD=$LLD_OPTION
;;
xdissearray)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOB_DIS_SEARRAY=ON -DOB_USE_LLD=$LLD_OPTION
;;
xtrans_module_test)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DTRANS_MODULE_TEST=ON -DOB_USE_LLD=$LLD_OPTION
;;
xenable_latch_diagnose)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_LATCH_DIAGNOSE=ON -DOB_USE_LLD=$LLD_OPTION
;;
xenable_memory_diagnosis)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_DEBUG_LOG=ON -DENABLE_MEMORY_DIAGNOSIS=ON -DOB_USE_LLD=$LLD_OPTION
;;
xenable_obj_leak_check)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_DEBUG_LOG=ON -DENABLE_OBJ_LEAK_CHECK=ON -DOB_USE_LLD=$LLD_OPTION
;;
xrpm)
STATIC_LINK_LGPL_DEPS_OPTION=OFF
do_build "$@" -DOB_BUILD_RPM=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOB_USE_LLD=$LLD_OPTION -DENABLE_FATAL_ERROR_HANG=OFF -DENABLE_AUTO_FDO=ON -DENABLE_THIN_LTO=ON -DOB_STATIC_LINK_LGPL_DEPS=$STATIC_LINK_LGPL_DEPS_OPTION
;;
xenable_smart_var_check)
do_build "$@" -DCMAKE_BUILD_TYPE=Debug -DOB_USE_LLD=$LLD_OPTION -DENABLE_SMART_VAR_CHECK=ON -DOB_ENABLE_AVX2=ON
;;
xcoverage)
do_build "$@" -DCMAKE_BUILD_TYPE=Debug -DOB_USE_LLD=$LLD_OPTION -DWITH_COVERAGE=ON
;;
xsanity)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOB_USE_LLD=$LLD_OPTION -DENABLE_SANITY=ON
;;
*)
BUILD_ARGS=(debug "${BUILD_ARGS[@]}")
build
;;
esac
}
function main
{
case "$1" in
-h)
usage
;;
init)
parse_args
do_init
;;
clean)
do_clean
;;
*)
parse_args
try_init
build
try_make
;;
esac
}
main "$@"