-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·281 lines (247 loc) · 6.56 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/bin/bash
# readlink -f cannot work on mac
TOPDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
BUILD_SH=$TOPDIR/build.sh
CMAKE_COMMAND="cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 --log-level=STATUS"
ALL_ARGS=("$@")
BUILD_ARGS=()
MAKE_ARGS=()
MAKE=make
echo "$0 ${ALL_ARGS[@]}"
function usage
{
echo "Usage:"
echo "./build.sh -h"
echo "./build.sh init # Initialize and install dependencies"
echo "./build.sh clean # Clean up build directories"
echo "./build.sh gen_parser # Generate parser files"
echo "./build.sh style # Apply coding style to source files"
echo "./build.sh test [test_case] # Run tests, optionally specify a test case"
echo "./build.sh [BuildType] [--make [MakeOptions]]"
echo ""
echo "OPTIONS:"
echo " -h Show this help message"
echo " init Initialize and install dependencies"
echo " clean Clean up all build directories"
echo " gen_parser Generate parser files in src/observer/sql/parser"
echo " style Apply coding style to source files in ./src"
echo " test [test_case] Run tests, optionally specify a test case to run"
echo " [BuildType] Specify build type: debug (default), release, relwithdebinfo, minsizerel"
echo " --make [MakeOptions] Options to pass to the make command, default: -jN"
echo ""
echo "Examples:"
echo "# Show help."
echo "./build.sh -h"
echo ""
echo "# Initialize the project and install dependencies."
echo "./build.sh init"
echo ""
echo "# Clean up all build directories."
echo "./build.sh clean"
echo ""
echo "# Generate parser files."
echo "./build.sh gen_parser"
echo ""
echo "# Apply coding style to source files."
echo "./build.sh style"
echo ""
echo "# Run all tests."
echo "./build.sh test"
echo ""
echo "# Run a specific test case."
echo "./build.sh test my_test_case"
echo ""
echo "# Build in debug mode (default) and make with -j24."
echo "./build.sh debug --make -j24"
echo ""
echo "# Build in release mode."
echo "./build.sh release"
}
function parse_args
{
make_start=false
for arg in "${ALL_ARGS[@]}"; do
if [[ "$arg" == "--make" ]]
then
make_start=true
elif [[ $make_start == false ]]
then
BUILD_ARGS+=("$arg")
else
MAKE_ARGS+=("$arg")
fi
done
}
# try call command make, if use give --make in command line.
function try_make
{
if [[ $MAKE != false ]]
then
# use single thread `make` if concurrent building failed
$MAKE "${MAKE_ARGS[@]}" || $MAKE
fi
}
# create build directory and cd it.
function prepare_build_dir
{
TYPE=$1
mkdir -p $TOPDIR/build_$TYPE && cd $TOPDIR/build_$TYPE
}
function do_init
{
git submodule update --init || return
current_dir=$PWD
MAKE_COMMAND="make --silent"
# build libevent
cd ${TOPDIR}/deps/3rd/libevent && \
mkdir -p build && \
cd build && \
${CMAKE_COMMAND} .. -DEVENT__DISABLE_OPENSSL=ON -DEVENT__LIBRARY_TYPE=BOTH && \
${MAKE_COMMAND} -j4 && \
make install
# build googletest
cd ${TOPDIR}/deps/3rd/googletest && \
mkdir -p build && \
cd build && \
${CMAKE_COMMAND} .. && \
${MAKE_COMMAND} -j4 && \
${MAKE_COMMAND} install
# build google benchmark
cd ${TOPDIR}/deps/3rd/benchmark && \
mkdir -p build && \
cd build && \
${CMAKE_COMMAND} .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBENCHMARK_ENABLE_TESTING=OFF -DBENCHMARK_INSTALL_DOCS=OFF -DBENCHMARK_ENABLE_GTEST_TESTS=OFF -DBENCHMARK_USE_BUNDLED_GTEST=OFF -DBENCHMARK_ENABLE_ASSEMBLY_TESTS=OFF && \
${MAKE_COMMAND} -j4 && \
${MAKE_COMMAND} install
# build jsoncpp
cd ${TOPDIR}/deps/3rd/jsoncpp && \
mkdir -p build && \
cd build && \
${CMAKE_COMMAND} -DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF .. && \
${MAKE_COMMAND} && \
${MAKE_COMMAND} install
cd $current_dir
}
function do_musl_init
{
git clone https://github.com/ronchaine/libexecinfo deps/3rd/libexecinfo || return
current_dir=$PWD
MAKE_COMMAND="make --silent"
cd ${TOPDIR}/deps/3rd/libexecinfo && \
${MAKE_COMMAND} install && \
${MAKE_COMMAND} clean && rm ${TOPDIR}/deps/3rd/libexecinfo/libexecinfo.so.* && \
cd ${current_dir}
}
function prepare_build_dir
{
TYPE=$1
mkdir -p ${TOPDIR}/build_${TYPE}
rm -f build
echo "create soft link for build_${TYPE}, linked by directory named build"
ln -s build_${TYPE} build
cd ${TOPDIR}/build_${TYPE}
}
function do_build
{
TYPE=$1; shift
prepare_build_dir $TYPE || return
echo "${CMAKE_COMMAND} ${TOPDIR} $@"
${CMAKE_COMMAND} -S ${TOPDIR} $@
}
function do_clean
{
echo "clean build_* dirs"
find . -maxdepth 1 -type d -name 'build_*' | xargs rm -rf
}
function build
{
set -- "${BUILD_ARGS[@]}"
# 将传递的所有参数转换为小写
BUILD_TYPE=$(echo "$1" | tr '[:upper:]' '[:lower:]')
case "x$BUILD_TYPE" in
xrelease)
do_build "$@" -DCMAKE_BUILD_TYPE=Release
;;
xrelwithdebinfo)
do_build "$@" -DCMAKE_BUILD_TYPE=RelWithDebInfo
;;
xdebug)
do_build "$@" -DCMAKE_BUILD_TYPE=Debug
;;
xminsizerel)
do_build "$@" -DCMAKE_BUILD_TYPE=MinSizeRel
;;
*)
BUILD_ARGS=(debug "${BUILD_ARGS[@]}")
build
;;
esac
}
function gen_parser
{
echo "generate parser..."
cd ${TOPDIR}/src/observer/sql/parser
./gen_parser.sh
echo "generate parser done"
cd ${TOPDIR}
}
function style
{
# Check if .clang-format file exists
if [ ! -f .clang-format ]; then
echo "Error: .clang-format file not found in the current directory."
exit 1
fi
# 设置要格式化的文件扩展名
EXTENSIONS=("c" "h" "cpp" "hpp")
# 查找并格式化文件
for ext in "${EXTENSIONS[@]}"; do
find ./src -type f -name "*.$ext" -exec clang-format -i {} +
done
echo "Formatting complete!"
}
function run_tests {
echo "Running test(s)..."
cd ${TOPDIR}/test/case || exit
if [[ -z "$1" ]]; then
# 如果没有提供测试用例名,直接执行
python3 miniob_test.py
else
# 如果提供了测试用例名,执行带参数的命令
TEST_CASE="$1"
echo "Running test case: $TEST_CASE"
python3 miniob_test.py --test-cases="$TEST_CASE"
fi
}
function main
{
case "$1" in
-h)
usage
;;
init)
do_init
;;
musl)
do_musl_init
;;
clean)
do_clean
;;
gen_parser)
gen_parser
;;
style)
style
;;
test)
run_tests "$2"
;;
*)
parse_args
build
try_make
;;
esac
}
main "$@"