-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathpackage.sh
executable file
·268 lines (234 loc) · 7.04 KB
/
package.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
#!/usr/bin/env bash
#
# Package nebula as deb/rpm package
#
# introduce the args
# -v: The version of package, the version should be match tag name, default value is null
# -n: Package to one or multi-packages, `ON` means one package, `OFF` means multi packages, default value is `ON`
# -s: Whether to strip the package, default value is `FALSE`
# -d: Whether to enable sanitizer, default OFF
# -t: Build type, default Release
# -j: Number of threads, default $(nproc)
# -r: Whether to enable compressed debug info, default ON
# -p: Whether to dump the symbols from binary by dump_syms
# -c: Whether to enable console building, default ON
# -k: Whether to enable breakpad, default OFF
#
# usage: ./package.sh -v <version> -n <ON/OFF> -s <TRUE/FALSE> -c <ON/OFF>
#
set -e
usage="Usage: ${0} -v <version> -n <ON/OFF> -s <TRUE/FALSE> -g <ON/OFF> -j <jobs> -t <BUILD TYPE>"
project_dir="$(cd "$(dirname "$0")" && pwd)/.."
build_dir=${project_dir}/pkg-build
install_prefix=/usr/local/nebula
BUILD_IN_DOCKER=${BUILD_IN_DOCKER:-FALSE}
# default variables when building release.
function _default_release_variables {
version=""
package_one="ON"
strip_enable="TRUE"
enablesanitizer="OFF"
static_sanitizer="OFF"
build_type="RelWithDebInfo"
build_console="OFF"
jobs=$(nproc)
enable_compressed_debug_info="OFF"
dump_symbols="ON"
dump_syms_tool_dir=
system_name=
enable_breakpad="ON"
}
# change default variables. e.g. build release in docker
function _extra_release_variables {
if [[ $BUILD_IN_DOCKER == TRUE ]]; then
package_one="OFF"
enable_compressed_debug_info="ON"
dump_symbols="OFF"
fi
}
_default_release_variables
_extra_release_variables
while getopts v:n:s:d:t:r:p:j:c:k: opt;
do
case $opt in
v)
version=$OPTARG
;;
n)
package_one=$OPTARG
;;
s)
strip_enable=$OPTARG
;;
d)
enablesanitizer="ON"
if [ "$OPTARG" == "static" ]; then
static_sanitizer="ON"
fi
build_type="RelWithDebInfo"
;;
t)
build_type=$OPTARG
;;
c)
build_console=$OPTARG
;;
j)
jobs=$OPTARG
;;
r)
enable_compressed_debug_info=$OPTARG
;;
p)
dump_symbols=$OPTARG
;;
k)
enable_breakpad=$OPTARG
;;
?)
echo "Invalid option, use default arguments"
;;
esac
done
# version is null, get from tag name
[[ -z $version ]] && version=$(git describe --exact-match --abbrev=0 --tags | sed 's/^v//')
# version is null, use UTC date as version
[[ -z $version ]] && version=$(date -u +%Y.%m.%d)-nightly
if [[ -z $version ]]; then
echo "version is null, exit"
echo ${usage}
exit 1
fi
if [[ $strip_enable != TRUE ]] && [[ $strip_enable != FALSE ]]; then
echo "strip enable is wrong, exit"
echo ${usage}
exit 1
fi
cat << EOF
Configuration for this shell:
version: $version
strip_enable: $strip_enable
enablesanitizer: $enablesanitizer
static_sanitizer: $static_sanitizer
build_type: $build_type
build_console: $build_console
branch: $branch
enable_compressed_debug_info: $enable_compressed_debug_info
dump_symbols: $dump_symbols
EOF
function _build_graph {
pushd ${build_dir}
cmake -DCMAKE_BUILD_TYPE=${build_type} \
-DNEBULA_BUILD_VERSION=${version} \
-DENABLE_ASAN=${san} \
-DENABLE_UBSAN=${san} \
-DENABLE_STATIC_ASAN=${ssan} \
-DENABLE_STATIC_UBSAN=${ssan} \
-DCMAKE_INSTALL_PREFIX=${install_prefix} \
-DENABLE_TESTING=OFF \
-DENABLE_CONSOLE_COMPILATION=${build_console} \
-DENABLE_PACK_ONE=${package_one} \
-DENABLE_COMPRESSED_DEBUG_INFO=${enable_compressed_debug_info} \
-DENABLE_PACKAGE_TAR=${package_tar} \
-DENABLE_BREAKPAD=${enable_breakpad} \
${project_dir}
if ! ( make -j ${jobs} ); then
echo ">>> build NebulaGraph failed <<<"
exit 1
fi
popd
echo ">>> build NebulaGraph successfully <<<"
}
# args: <version>
function build {
version=$1
san=$2
ssan=$3
build_type=$4
package_tar=$5
install_prefix=$6
mkdir -p ${build_dir}
_build_graph
}
# args: <strip_enable>
function package {
pushd ${build_dir}
strip_enable=$1
args=""
[[ $strip_enable == TRUE ]] && args="-D CPACK_STRIP_FILES=TRUE -D CPACK_RPM_SPEC_MORE_DEFINE="
if ! ( cpack --verbose $args ); then
echo ">>> package NebulaGraph failed <<<"
exit 1
else
# rename package file
outputDir=$build_dir/cpack_output
mkdir -p ${outputDir}
for pkg_name in $(ls ./*nebula*-${version}*); do
mv ${pkg_name} ${outputDir}/
echo "####### target package file is ${outputDir}/${pkg_name}"
done
fi
popd
}
function _find_dump_syms_tool {
if [[ -x ${build_dir}/third-party/install/bin/dump_syms ]]; then
dump_syms_tool_dir=${build_dir}/third-party/install/bin
elif [[ -x /opt/vesoft/third-party/3.3/bin/dump_syms ]]; then
dump_syms_tool_dir=/opt/vesoft/third-party/3.3/bin
else
echo ">>> Failed to find the dump_syms tool <<<"
exit 1
fi
}
# This is only for releasing the disk resources.
function _strip_unnecessary_binaries {
for bin in $(ls -1 -F ${build_dir}/bin/ | grep -v [/$] | sed -e '/nebula-metad/d;/nebula-graphd/d;/nebula-storaged/d'); do
if ! (strip ${build_dir}/bin/${bin}); then
echo ">>> strip ${bin} failed: $?. <<<"
exit 1
fi
done
}
function dump_syms {
_strip_unnecessary_binaries
_find_dump_syms_tool
dump_syms=${dump_syms_tool_dir}/dump_syms
syms_dir=${build_dir}/symbols/
rm -rf ${syms_dir} && mkdir -p ${syms_dir}
pack=`ls ${build_dir}/cpack_output/`
tmp=${pack#nebula-graph}
ver=${tmp%.*}
hash objcopy &> /dev/null || {
echo "'objcopy' is not installed"
exit 1
}
for bin in nebula-graphd nebula-storaged nebula-metad; do
# Create separate debuginfo for GDB
objcopy --only-keep-debug ${build_dir}/bin/${bin} ${syms_dir}/${bin}${ver}.debug
# Create separate debuginfo for breakpad
if ! (${dump_syms} ${build_dir}/bin/${bin} > ${syms_dir}/${bin}${ver}.sym); then
echo ">>> dump ${bin} symbols failed: $?. <<<"
exit 1
fi
done
}
function add_commit {
hash git &> /dev/null
if [ $? -eq 0 ];then
if [ -d ".git" ];then
git rev-parse --short HEAD > ${build_dir}/cpack_output/commit.txt
fi
fi
}
# The main
build $version $enablesanitizer $static_sanitizer $build_type "OFF" "/usr/local/nebula"
package $strip_enable
if [[ "$dump_symbols" == "ON" ]]; then
echo ">>> start dump symbols <<<"
dump_syms
fi
# tar package
build $version $enablesanitizer $static_sanitizer $build_type "ON" "/"
package $strip_enable
# add commit information
add_commit