You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.sh 7.8 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #!/bin/bash
  2. # Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # ============================================================================
  16. set -e
  17. echo "ASCEND_CUSTOM_PATH=${ASCEND_CUSTOM_PATH}"
  18. echo "BUILD_METADEF=${BUILD_METADEF}"
  19. if [ ! ${BUILD_METADEF} ] ; then
  20. BUILD_METADEF=ON
  21. fi
  22. if [ "X$BUILD_METADEF" = "XON" ]; then
  23. git submodule update --init metadef
  24. fi
  25. BASEPATH=$(cd "$(dirname $0)"; pwd)
  26. OUTPUT_PATH="${BASEPATH}/output"
  27. BUILD_PATH="${BASEPATH}/build/"
  28. ASCEND_OPENSDK_DIR=${ASCEND_CUSTOM_PATH}/opensdk/opensdk
  29. PREFIX_PATH="${ASCEND_OPENSDK_DIR}/cmake;\
  30. ${ASCEND_OPENSDK_DIR}/c_sec;\
  31. ${ASCEND_OPENSDK_DIR}/json;\
  32. ${ASCEND_OPENSDK_DIR}/openssl;\
  33. ${ASCEND_OPENSDK_DIR}/zlib;\
  34. ${ASCEND_OPENSDK_DIR}/protoc;\
  35. ${ASCEND_OPENSDK_DIR}/protoc_grpc;\
  36. ${ASCEND_OPENSDK_DIR}/grpc;\
  37. ${ASCEND_OPENSDK_DIR}/protobuf_static;\
  38. ${ASCEND_OPENSDK_DIR}/ascend_protobuf;\
  39. ${ASCEND_OPENSDK_DIR}/ascend_protobuf_static;\
  40. ${ASCEND_OPENSDK_DIR}/gtest_shared/lib/cmake/GTest;\
  41. ${ASCEND_OPENSDK_DIR}/gtest_shared/lib64/cmake/GTest"
  42. # print usage message
  43. usage()
  44. {
  45. echo "Usage:"
  46. echo "sh build.sh [-j[n]] [-h] [-v] [-s] [-t] [-u] [-c] [-S on|off]"
  47. echo ""
  48. echo "Options:"
  49. echo " -h Print usage"
  50. echo " -u Only compile ut, not execute"
  51. echo " -s Build st"
  52. echo " -j[n] Set the number of threads used for building Parser, default is 8"
  53. echo " -t Build and execute ut"
  54. echo " -c Build ut with coverage tag"
  55. echo " -v Display build command"
  56. echo " -S Enable enable download cmake compile dependency from gitee , default off"
  57. echo "to be continued ..."
  58. }
  59. # check value of input is 'on' or 'off'
  60. # usage: check_on_off arg_value arg_name
  61. check_on_off()
  62. {
  63. if [[ "X$1" != "Xon" && "X$1" != "Xoff" ]]; then
  64. echo "Invalid value $1 for option -$2"
  65. usage
  66. exit 1
  67. fi
  68. }
  69. # parse and set options
  70. checkopts()
  71. {
  72. VERBOSE=""
  73. THREAD_NUM=8
  74. ENABLE_PARSER_UT="off"
  75. ENABLE_PARSER_ST="off"
  76. ENABLE_PARSER_COV="off"
  77. ENABLE_GITEE="off"
  78. # Process the options
  79. while getopts 'ustchj:vS:' opt
  80. do
  81. OPTARG=$(echo ${OPTARG} | tr '[A-Z]' '[a-z]')
  82. case "${opt}" in
  83. u)
  84. ENABLE_PARSER_UT="on"
  85. ;;
  86. s)
  87. ENABLE_PARSER_ST="on"
  88. ;;
  89. t)
  90. ENABLE_PARSER_UT="on"
  91. ;;
  92. c)
  93. ENABLE_PARSER_COV="on"
  94. ;;
  95. h)
  96. usage
  97. exit 0
  98. ;;
  99. j)
  100. THREAD_NUM=$OPTARG
  101. ;;
  102. v)
  103. VERBOSE="VERBOSE=1"
  104. ;;
  105. S)
  106. check_on_off $OPTARG S
  107. ENABLE_GITEE="$OPTARG"
  108. echo "enable download from gitee"
  109. ;;
  110. *)
  111. echo "Undefined option: ${opt}"
  112. usage
  113. exit 1
  114. esac
  115. done
  116. }
  117. checkopts "$@"
  118. mk_dir() {
  119. local create_dir="$1" # the target to make
  120. mkdir -pv "${create_dir}"
  121. echo "created ${create_dir}"
  122. }
  123. # Parser build start
  124. echo "---------------- Parser build start ----------------"
  125. # create build path
  126. build_parser()
  127. {
  128. echo "create build directory and build Parser";
  129. mk_dir "${BUILD_PATH}"
  130. cd "${BUILD_PATH}"
  131. cmake -D ENABLE_OPEN_SRC=True \
  132. -D ENABLE_PARSER_COV=${ENABLE_PARSER_COV} \
  133. -D ENABLE_PARSER_UT=${ENABLE_PARSER_UT} \
  134. -D ENABLE_PARSER_ST=${ENABLE_PARSER_ST} \
  135. -D ENABLE_GITEE=${ENABLE_GITEE} \
  136. -D BUILD_METADEF=${BUILD_METADEF} \
  137. -D BUILD_WITHOUT_AIR=True \
  138. -D ASCEND_OPENSDK_DIR=${ASCEND_OPENSDK_DIR} \
  139. -D CMAKE_BUILD_TYPE=Release \
  140. -D CMAKE_INSTALL_PREFIX=${OUTPUT_PATH} \
  141. -D CMAKE_MODULE_PATH=${ASCEND_OPENSDK_DIR}/cmake/modules \
  142. -D CMAKE_PREFIX_PATH=${PREFIX_PATH} \
  143. -D protoc_ROOT=${ASCEND_OPENSDK_DIR}/protoc \
  144. -D protobuf_grpc_ROOT=${ASCEND_OPENSDK_DIR}/grpc \
  145. -D protobuf_static_ROOT=${ASCEND_OPENSDK_DIR}/protobuf_static \
  146. -D ascend_protobuf_shared_ROOT=${ASCEND_OPENSDK_DIR}/ascend_protobuf \
  147. -D ascend_protobuf_static_ROOT=${ASCEND_OPENSDK_DIR}/ascend_protobuf_static \
  148. ..
  149. if [ 0 -ne $? ]
  150. then
  151. echo "execute command: cmake .. failed."
  152. return 1
  153. fi
  154. if [ "X$ENABLE_PARSER_UT" = "Xon" ]; then
  155. make ut_parser -j8
  156. elif [ "X$ENABLE_PARSER_ST" = "Xon" ]; then
  157. make st_parser -j8
  158. else
  159. make ${VERBOSE} -j${THREAD_NUM} && make install
  160. fi
  161. if [ 0 -ne $? ]
  162. then
  163. echo "execute command: make ${VERBOSE} -j${THREAD_NUM} && make install failed."
  164. return 1
  165. fi
  166. echo "Parser build success!"
  167. }
  168. g++ -v
  169. mk_dir ${OUTPUT_PATH}
  170. build_parser || { echo "Parser build failed."; return; }
  171. echo "---------------- Parser build finished ----------------"
  172. if [[ "X$ENABLE_PARSER_UT" = "Xon" || "X$ENABLE_PARSER_COV" = "Xon" ]]; then
  173. cp ${BUILD_PATH}/tests/ut/parser/ut_parser ${OUTPUT_PATH}
  174. RUN_TEST_CASE=${OUTPUT_PATH}/ut_parser && ${RUN_TEST_CASE}
  175. if [[ "$?" -ne 0 ]]; then
  176. echo "!!! UT FAILED, PLEASE CHECK YOUR CHANGES !!!"
  177. echo -e "\033[31m${RUN_TEST_CASE}\033[0m"
  178. exit 1;
  179. fi
  180. echo "Generating coverage statistics, please wait..."
  181. cd ${BASEPATH}
  182. rm -rf ${BASEPATH}/cov
  183. mkdir ${BASEPATH}/cov
  184. lcov -c -d build/tests/ut/parser -o cov/tmp.info
  185. lcov -r cov/tmp.info '*/output/*' '*/build/opensrc/*' '*/build/proto/*' '*/third_party/*' '*/tests/*' '/usr/local/*' '*/metadef/inc/*' -o cov/coverage.info
  186. cd ${BASEPATH}/cov
  187. genhtml coverage.info
  188. fi
  189. if [[ "X$ENABLE_PARSER_ST" = "Xon" ]]; then
  190. cp ${BUILD_PATH}/tests/st/st_parser ${OUTPUT_PATH}
  191. RUN_TEST_CASE=${OUTPUT_PATH}/st_parser && ${RUN_TEST_CASE}
  192. if [[ "$?" -ne 0 ]]; then
  193. echo "!!! ST FAILED, PLEASE CHECK YOUR CHANGES !!!"
  194. echo -e "\033[31m${RUN_TEST_CASE}\033[0m"
  195. exit 1;
  196. fi
  197. echo "Generating coverage statistics, please wait..."
  198. cd ${BASEPATH}
  199. rm -rf ${BASEPATH}/cov
  200. mkdir ${BASEPATH}/cov
  201. lcov -c -d build/tests/st -o cov/tmp.info
  202. lcov -r cov/tmp.info '*/output/*' '*/build/opensrc/*' '*/build/proto/*' '*/third_party/*' '*/tests/*' '/usr/local/*' '*/metadef/inc/*' -o cov/coverage.info
  203. cd ${BASEPATH}/cov
  204. genhtml coverage.info
  205. fi
  206. # generate output package in tar form, including ut/st libraries/executables for cann
  207. generate_package()
  208. {
  209. cd "${BASEPATH}"
  210. PARSER_LIB_PATH="lib"
  211. COMPILER_PATH="compiler/lib64"
  212. COMMON_LIB=("libgraph.so" "libregister.so" "liberror_manager.so")
  213. PARSER_LIB=("lib_caffe_parser.so" "libfmk_onnx_parser.so" "libfmk_parser.so" "libparser_common.so")
  214. rm -rf ${OUTPUT_PATH:?}/${COMPILER_PATH}/
  215. mk_dir "${OUTPUT_PATH}/${COMPILER_PATH}"
  216. find output/ -name parser_lib.tar -exec rm {} \;
  217. cd "${OUTPUT_PATH}"
  218. for lib in "${PARSER_LIB[@]}";
  219. do
  220. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${COMPILER_PATH} \;
  221. done
  222. for lib in "${COMMON_LIB[@]}";
  223. do
  224. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${COMPILER_PATH} \;
  225. done
  226. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "libc_sec.so" -exec cp -f {} ${OUTPUT_PATH}/${COMPILER_PATH} \;
  227. tar -cf parser_lib.tar compiler
  228. }
  229. if [[ "X$ENABLE_PARSER_UT" = "Xoff" && "X$ENABLE_PARSER_ST" = "Xoff" ]]; then
  230. generate_package
  231. fi
  232. echo "---------------- Parser package archive generated ----------------"