forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage.sh
executable file
·217 lines (191 loc) · 5.67 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
#!/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 enable compressed debug info, default ON
# -p: Whether dump the symbols from binary by dump_syms
#
# usage: ./package.sh -v <version> -n <ON/OFF> -s <TRUE/FALSE>
#
set -e
version=""
package_one=ON
strip_enable="FALSE"
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
enablesanitizer="OFF"
static_sanitizer="OFF"
build_type="Release"
branch=$(git rev-parse --abbrev-ref HEAD)
jobs=$(nproc)
enable_compressed_debug_info=ON
dump_symbols=OFF
dump_syms_tool_dir=
system_name=
install_prefix=/usr/local/nebula
while getopts v:n:s:b:d:t:r:p:j: 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
;;
j)
jobs=$OPTARG
;;
r)
enable_compressed_debug_info=$OPTARG
;;
p)
dump_symbols=$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
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_PACK_ONE=${package_one} \
-DENABLE_COMPRESSED_DEBUG_INFO=${enable_compressed_debug_info} \
-DENABLE_PACKAGE_TAR=${package_tar} \
${project_dir}
if ! ( make -j ${jobs} ); then
echo ">>> build nebula graph failed <<<"
exit 1
fi
popd
echo ">>> build nebula graph 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 nebula 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/2.0/bin/dump_syms ]]; then
dump_syms_tool_dir=/opt/vesoft/third-party/2.0/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%.*}
for bin in nebula-graphd nebula-storaged nebula-metad; do
if ! (${dump_syms} ${build_dir}/bin/${bin} > ${syms_dir}/${bin}${ver}.sym); then
echo ">>> dump ${bin} symbols failed: $?. <<<"
exit 1
fi
done
}
# 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