-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
218 lines (189 loc) · 5.67 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
#!/bin/bash
# Copyright 2019-2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
set -e
BASEPATH=$(cd "$(dirname $0)"; pwd)
OUTPUT_PATH="${BASEPATH}/output"
export BUILD_PATH="${BASEPATH}/build/"
# print usage message
usage()
{
echo "Usage:"
echo "sh build.sh [-j[n]] [-h] [-v] [-s] [-t] [-u] [-c] [-S on|off]"
echo ""
echo "Options:"
echo " -h Print usage"
echo " -u Only compile ut, not execute"
echo " -s Build st"
echo " -j[n] Set the number of threads used for building Parser, default is 8"
echo " -t Build and execute ut"
echo " -c Build ut with coverage tag"
echo " -v Display build command"
echo " -S Enable enable download cmake compile dependency from gitee , default off"
echo "to be continued ..."
}
# check value of input is 'on' or 'off'
# usage: check_on_off arg_value arg_name
check_on_off()
{
if [[ "X$1" != "Xon" && "X$1" != "Xoff" ]]; then
echo "Invalid value $1 for option -$2"
usage
exit 1
fi
}
# parse and set options
checkopts()
{
VERBOSE=""
THREAD_NUM=8
# ENABLE_GE_UT_ONLY_COMPILE="off"
ENABLE_GE_UT="off"
ENABLE_GE_ST="off"
ENABLE_GE_COV="off"
GE_ONLY="on"
ENABLE_GITEE="off"
# Process the options
while getopts 'ustchj:vS:' opt
do
OPTARG=$(echo ${OPTARG} | tr '[A-Z]' '[a-z]')
case "${opt}" in
u)
# ENABLE_GE_UT_ONLY_COMPILE="on"
ENABLE_GE_UT="on"
GE_ONLY="off"
;;
s)
ENABLE_GE_ST="on"
;;
t)
ENABLE_GE_UT="on"
GE_ONLY="off"
;;
c)
ENABLE_GE_COV="on"
GE_ONLY="off"
;;
h)
usage
exit 0
;;
j)
THREAD_NUM=$OPTARG
;;
v)
VERBOSE="VERBOSE=1"
;;
S)
check_on_off $OPTARG S
ENABLE_GITEE="$OPTARG"
echo "enable download from gitee"
;;
*)
echo "Undefined option: ${opt}"
usage
exit 1
esac
done
}
checkopts "$@"
git submodule update --init metadef
mk_dir() {
local create_dir="$1" # the target to make
mkdir -pv "${create_dir}"
echo "created ${create_dir}"
}
# Parser build start
echo "---------------- Parser build start ----------------"
# create build path
build_parser()
{
echo "create build directory and build Parser";
mk_dir "${BUILD_PATH}"
cd "${BUILD_PATH}"
CMAKE_ARGS="-DBUILD_PATH=$BUILD_PATH -DGE_ONLY=$GE_ONLY"
if [[ "X$ENABLE_GE_COV" = "Xon" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_COV=ON"
fi
if [[ "X$ENABLE_GE_UT" = "Xon" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_UT=ON"
fi
if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_ST=ON"
fi
if [[ "X$ENABLE_GITEE" = "Xon" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GITEE=ON"
fi
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_OPEN_SRC=True -DCMAKE_INSTALL_PREFIX=${OUTPUT_PATH}"
echo "${CMAKE_ARGS}"
cmake ${CMAKE_ARGS} ..
if [ 0 -ne $? ]
then
echo "execute command: cmake ${CMAKE_ARGS} .. failed."
return 1
fi
make ${VERBOSE} -j${THREAD_NUM} && make install
if [ 0 -ne $? ]
then
echo "execute command: make ${VERBOSE} -j${THREAD_NUM} && make install failed."
return 1
fi
echo "Parser build success!"
}
g++ -v
mk_dir ${OUTPUT_PATH}
build_parser || { echo "Parser build failed."; return; }
echo "---------------- Parser build finished ----------------"
rm -f ${OUTPUT_PATH}/libgmock*.so
rm -f ${OUTPUT_PATH}/libgtest*.so
rm -f ${OUTPUT_PATH}/lib*_stub.so
chmod -R 750 ${OUTPUT_PATH}
find ${OUTPUT_PATH} -name "*.so*" -print0 | xargs -0 chmod 500
echo "---------------- Parser output generated ----------------"
# generate output package in tar form, including ut/st libraries/executables
generate_package()
{
cd "${BASEPATH}"
PARSER_LIB_PATH="lib"
ACL_PATH="acllib/lib64"
FWK_PATH="fwkacllib/lib64"
ATC_PATH="atc/lib64"
COMMON_LIB=("libgraph.so" "libregister.so")
PARSER_LIB=("lib_caffe_parser.so" "libfmk_onnx_parser.so" "libfmk_parser.so" "libparser_common.so")
rm -rf ${OUTPUT_PATH:?}/${FWK_PATH}/
rm -rf ${OUTPUT_PATH:?}/${ACL_PATH}/
rm -rf ${OUTPUT_PATH:?}/${ATC_PATH}/
mk_dir "${OUTPUT_PATH}/${FWK_PATH}"
mk_dir "${OUTPUT_PATH}/${ATC_PATH}"
mk_dir "${OUTPUT_PATH}/${ACL_PATH}"
find output/ -name parser_lib.tar -exec rm {} \;
cd "${OUTPUT_PATH}"
for lib in "${PARSER_LIB[@]}";
do
find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${FWK_PATH} \;
find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${ATC_PATH} \;
done
for lib in "${COMMON_LIB[@]}";
do
find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${FWK_PATH} \;
find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${ATC_PATH} \;
done
find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "libc_sec.so" -exec cp -f {} ${OUTPUT_PATH}/${ATC_PATH} \;
tar -cf parser_lib.tar fwkacllib acllib atc
}
if [[ "X$ENABLE_GE_UT" = "Xoff" ]]; then
generate_package
fi
echo "---------------- Parser package archive generated ----------------"