-
Notifications
You must be signed in to change notification settings - Fork 325
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·524 lines (476 loc) · 12.8 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·524 lines (476 loc) · 12.8 KB
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
#!/usr/bin/env bash
set -uo pipefail
readonly TOPDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly DEP_INIT_DIR="${TOPDIR}/deps/init"
readonly DEVTOOLS_DIR="${TOPDIR}/deps/3rd/usr/local/oceanbase/devtools"
readonly -a ALL_ARGS=("$@")
function echo_log
{
echo "[build.sh] $*"
}
function echo_err
{
echo "[build.sh][ERROR] $*" >&2
}
function fail
{
echo_err "$*"
exit 2
}
function usage
{
cat <<'EOF'
Usage:
./build.sh -h
./build.sh init [--android]
./build.sh clean
./build.sh release [--init] [--android] [-DName=Value ...]
./build.sh release [--init] [--android] [-DName=Value ...] --make [MakeOptions]
./build.sh sanity [--init] [-DName=Value ...]
./build.sh sanity [--init] [-DName=Value ...] --make [MakeOptions]
./build.sh {rpm|deb|tgz} [--init] [-DName=Value ...]
./build.sh {rpm|deb|tgz} [--init] [-DName=Value ...] --make [MakeOptions]
Supported compatibility build:
Release (RelWithDebInfo, -O2), Unity compilation, seekdb production binary,
and RPM, DEB, or TGZ packaging profiles derived from that Release build.
RPM and DEB packaging require Linux; TGZ supports Linux and macOS.
Sanity is a Linux-only CMake RelWithDebInfo Unity build with memory
instrumentation enabled.
Host platforms: Linux and macOS. Android cross-compilation: arm64-v8a.
Windows x64 uses build.ps1.
Examples:
./build.sh release --init
cd build_release && make -j80
./build.sh release --make -j80
./build.sh sanity --init
cd build_sanity && make -j32 seekdb
./build.sh sanity --make -j32
./build.sh rpm --init
cd build_rpm && make -j80
./build.sh rpm --make -j80 rpm
./build.sh deb --init --make -j80 deb
./build.sh tgz --init --make -j16 tgz
./build.sh release --android --init --make -j16
On Linux, CMake also provides module unit-test targets and the pretest aggregate.
See docs/developer-guide/en/unittest.md for build and test commands.
EOF
}
function print_command
{
printf '[build.sh] command: %q' "$0"
if (( ${#ALL_ARGS[@]} > 0 )); then
printf ' %q' "${ALL_ARGS[@]}"
fi
printf '\n'
}
function require_host
{
case "$(uname -s)" in
Linux|Darwin)
;;
*)
fail "build.sh supports Linux and macOS; use build.ps1 on Windows"
;;
esac
}
function cpu_count
{
if command -v nproc >/dev/null 2>&1; then
nproc
elif [[ "$(uname -s)" == "Darwin" ]]; then
sysctl -n hw.ncpu
else
getconf _NPROCESSORS_ONLN
fi
}
function find_cmake
{
if [[ "$(uname -s)" == "Linux" && -x "${DEVTOOLS_DIR}/bin/cmake" ]]; then
printf '%s\n' "${DEVTOOLS_DIR}/bin/cmake"
elif command -v cmake >/dev/null 2>&1; then
command -v cmake
else
return 1
fi
}
function do_init
{
local android_build=$1
local start_time end_time elapsed
local status=0
if [[ ! -f "${DEP_INIT_DIR}/dep_create.sh" ]]; then
echo_err "dependency initializer not found: ${DEP_INIT_DIR}/dep_create.sh"
return 1
fi
start_time="$(date +%s)"
(
cd "${DEP_INIT_DIR}" &&
ANDROID_BUILD="${android_build}" bash dep_create.sh
) || status=$?
if (( status != 0 )); then
echo_err "dependency initialization failed with status ${status}"
return "${status}"
fi
end_time="$(date +%s)"
elapsed=$((end_time - start_time))
echo_log "dependency initialization completed in $((elapsed / 60))m$((elapsed % 60))s"
}
function release_build_dir
{
local android_build=$1
if [[ "${android_build}" == true ]]; then
printf '%s\n' "${TOPDIR}/build_android_release"
else
printf '%s\n' "${TOPDIR}/build_release"
fi
}
function remove_managed_build_dir
{
local build_dir=$1
case "${build_dir}" in
"${TOPDIR}/build_debug"|"${TOPDIR}/build_release"|"${TOPDIR}/build_sanity"|"${TOPDIR}/build_android_release"|"${TOPDIR}/build_rpm"|"${TOPDIR}/build_deb"|"${TOPDIR}/build_tgz")
;;
*)
fail "refusing to clean unexpected path: ${build_dir}"
;;
esac
if [[ -d "${build_dir}" ]]; then
"$(find_cmake)" -E remove_directory "${build_dir}"
fi
}
function configure_cmake
{
local build_label=$1
local android_build=$2
local build_dir=$3
shift 3
local cmake_command
local lld_option=ON
local -a cmake_args=(
-S "${TOPDIR}"
-B "${build_dir}"
-G "Unix Makefiles"
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-DOB_ENABLE_UNITY=ON
)
cmake_command="$(find_cmake)" || fail "cmake not found; initialize dependencies or install CMake 3.20+"
# The bundled lld is unavailable on historical EL6 environments.
if [[ "$(uname -s)" == "Linux" ]] && grep -qE 'release 6([^0-9]|$)' /etc/issue 2>/dev/null; then
lld_option=OFF
echo_log "lld disabled on release 6 compatibility host"
fi
cmake_args+=("-DOB_USE_LLD=${lld_option}")
if [[ "${android_build}" == true ]]; then
local ndk_home="${ANDROID_NDK_HOME:-${HOME}/Library/Android/sdk/ndk/27.3.13750724}"
if [[ ! -f "${ndk_home}/build/cmake/android.toolchain.cmake" ]]; then
fail "Android NDK not found: ${ndk_home}; set ANDROID_NDK_HOME"
fi
cmake_args+=(
"-DCMAKE_TOOLCHAIN_FILE=${ndk_home}/build/cmake/android.toolchain.cmake"
-DANDROID_ABI=arm64-v8a
-DANDROID_PLATFORM=android-28
)
fi
# Replace the former Bazel-backed build_release entry point in place. A
# normal CMake directory is incrementally reconfigured and kept intact.
if [[ -f "${build_dir}/.seekdb_bazel_release" ]]; then
echo_log "replacing legacy Bazel compatibility directory: ${build_dir}"
remove_managed_build_dir "${build_dir}"
fi
echo_log "configuring CMake ${build_label} build: ${build_dir}"
"${cmake_command}" "${cmake_args[@]}" "$@"
}
function do_release
{
local need_init=false
local need_make=false
local collecting_make_args=false
local android_build=false
local build_dir
local -a cmake_args=()
local -a make_args=()
while (( $# > 0 )); do
case "$1" in
--init)
need_init=true
;;
--android)
android_build=true
;;
--make)
if [[ "${need_make}" == true ]]; then
fail "--make may only be specified once"
fi
need_make=true
collecting_make_args=true
;;
--coverage|--ob-make)
fail "$1 is outside the CMake compatibility boundary"
;;
-D*)
if [[ "${collecting_make_args}" == true ]]; then
fail "CMake options must appear before --make: $1"
fi
cmake_args+=("$1")
;;
release)
if [[ "${collecting_make_args}" == true ]]; then
make_args+=("$1")
fi
;;
*)
if [[ "${collecting_make_args}" == true ]]; then
make_args+=("$1")
else
fail "unexpected release argument: $1"
fi
;;
esac
shift
done
require_host
if [[ "${need_init}" == true ]]; then
do_init "${android_build}" || exit $?
fi
build_dir="$(release_build_dir "${android_build}")"
if (( ${#cmake_args[@]} > 0 )); then
configure_cmake release "${android_build}" "${build_dir}" "${cmake_args[@]}" || exit $?
else
configure_cmake release "${android_build}" "${build_dir}" || exit $?
fi
if [[ "${need_make}" == true ]]; then
if (( ${#make_args[@]} == 0 )); then
make_args=(-j"$(cpu_count)")
fi
make -C "${build_dir}" "${make_args[@]}" seekdb
fi
}
function do_sanity
{
local need_init=false
local need_make=false
local collecting_make_args=false
local build_dir="${TOPDIR}/build_sanity"
local -a cmake_args=()
local -a make_args=()
while (( $# > 0 )); do
case "$1" in
--init)
need_init=true
;;
--make)
if [[ "${need_make}" == true ]]; then
fail "--make may only be specified once"
fi
need_make=true
collecting_make_args=true
;;
--android|--coverage|--ob-make)
fail "$1 is outside the CMake Sanity build boundary"
;;
-D*)
if [[ "${collecting_make_args}" == true ]]; then
fail "CMake options must appear before --make: $1"
fi
cmake_args+=("$1")
;;
*)
if [[ "${collecting_make_args}" == true ]]; then
make_args+=("$1")
else
fail "unexpected sanity argument: $1"
fi
;;
esac
shift
done
require_host
[[ "$(uname -s)" == "Linux" ]] || fail "Sanity builds are supported only on Linux"
if [[ "${need_init}" == true ]]; then
do_init false || exit $?
fi
configure_cmake sanity false "${build_dir}" \
"${cmake_args[@]}" -DENABLE_SANITY=ON || exit $?
if [[ "${need_make}" == true ]]; then
if (( ${#make_args[@]} == 0 )); then
make_args=(-j"$(cpu_count)")
fi
make -C "${build_dir}" "${make_args[@]}" seekdb
fi
}
function do_package
{
local package_type=$1
shift
local package_label
local package_option
local need_init=false
local need_make=false
local collecting_make_args=false
local build_dir="${TOPDIR}/build_${package_type}"
local -a cmake_args=()
local -a make_args=()
local -a package_cmake_args=()
case "${package_type}" in
rpm)
package_label=RPM
package_option=OB_BUILD_RPM
;;
deb)
package_label=DEB
package_option=OB_BUILD_DEB
;;
tgz)
package_label=TGZ
package_option=OB_BUILD_TGZ
;;
*)
fail "unsupported package type: ${package_type}"
;;
esac
while (( $# > 0 )); do
case "$1" in
--init)
need_init=true
;;
--make)
if [[ "${need_make}" == true ]]; then
fail "--make may only be specified once"
fi
need_make=true
collecting_make_args=true
;;
--android|--coverage|--ob-make)
fail "$1 is outside the CMake ${package_label} compatibility boundary"
;;
-D*)
if [[ "${collecting_make_args}" == true ]]; then
fail "CMake options must appear before --make: $1"
fi
cmake_args+=("$1")
;;
*)
if [[ "${collecting_make_args}" == true ]]; then
make_args+=("$1")
else
fail "unexpected ${package_type} argument: $1"
fi
;;
esac
shift
done
require_host
if [[ "${package_type}" == "rpm" || "${package_type}" == "deb" ]]; then
[[ "$(uname -s)" == "Linux" ]] ||
fail "${package_label} packaging is supported only on Linux"
fi
if [[ "${package_type}" == "deb" && "${need_make}" == true ]]; then
command -v dpkg-deb >/dev/null 2>&1 ||
fail "dpkg-deb is required to build a DEB package"
fi
if [[ "${need_init}" == true ]]; then
do_init false || exit $?
fi
package_cmake_args=(
-DOB_BUILD_PACKAGE=ON
"-D${package_option}=ON"
-DOB_STATIC_LINK_LGPL_DEPS=ON
-DDEFAULT_LOG_LEVEL=OB_LOG_LEVEL_DBA_WARN
-DDEFAULT_LOG_FILE_SIZE_MB=16
)
if [[ "${package_type}" == "tgz" ]]; then
package_cmake_args+=(
-DENABLE_AUTO_FDO=OFF
-DENABLE_THIN_LTO=ON
-DENABLE_HOTFUNC=OFF
)
else
package_cmake_args+=(
-DENABLE_AUTO_FDO=ON
-DENABLE_THIN_LTO=ON
-DENABLE_HOTFUNC=ON
)
fi
if (( ${#cmake_args[@]} > 0 )); then
package_cmake_args=("${cmake_args[@]}" "${package_cmake_args[@]}")
fi
configure_cmake "${package_type}" false "${build_dir}" "${package_cmake_args[@]}" || exit $?
if [[ "${need_make}" == true ]]; then
if (( ${#make_args[@]} > 0 )); then
make -C "${build_dir}" -j"$(cpu_count)" "${make_args[@]}"
else
make -C "${build_dir}" -j"$(cpu_count)"
fi
fi
}
function do_clean
{
local build_dir
local found=false
for build_dir in \
"${TOPDIR}/build_debug" \
"${TOPDIR}/build_release" \
"${TOPDIR}/build_sanity" \
"${TOPDIR}/build_android_release" \
"${TOPDIR}/build_rpm" \
"${TOPDIR}/build_deb" \
"${TOPDIR}/build_tgz"; do
if [[ -d "${build_dir}" ]]; then
remove_managed_build_dir "${build_dir}"
echo_log "removed ${build_dir}"
found=true
fi
done
if [[ "${found}" == false ]]; then
echo_log "nothing to clean"
fi
}
function do_init_command
{
local android_build=false
if (( $# > 1 )); then
fail "init accepts only --android"
fi
if (( $# == 1 )); then
[[ "$1" == "--android" ]] || fail "unexpected init argument: $1"
android_build=true
fi
require_host
do_init "${android_build}"
}
function main
{
print_command
case "${1:-}" in
-h|--help)
(( $# == 1 )) || fail "$1 does not accept arguments"
usage
;;
init)
do_init_command "${@:2}"
;;
clean)
(( $# == 1 )) || fail "clean does not accept arguments"
require_host
do_clean
;;
release)
do_release "${@:2}"
;;
sanity)
do_sanity "${@:2}"
;;
rpm|deb|tgz)
do_package "$1" "${@:2}"
;;
"")
usage
exit 2
;;
*)
fail "unsupported build type or command: $1 (maintained modes: release, sanity, rpm, deb, tgz)"
;;
esac
}
main "$@"