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.1 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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. BASEPATH=$(cd "$(dirname $0)"; pwd)
  18. OUTPUT_PATH="${BASEPATH}/output"
  19. export BUILD_PATH="${BASEPATH}/build/"
  20. # print usage message
  21. usage()
  22. {
  23. echo "Usage:"
  24. echo "sh build.sh [-j[n]] [-h] [-v] [-s] [-t] [-u] [-c] [-S on|off]"
  25. echo ""
  26. echo "Options:"
  27. echo " -h Print usage"
  28. echo " -u Only compile ut, not execute"
  29. echo " -s Build st"
  30. echo " -j[n] Set the number of threads used for building Parser, default is 8"
  31. echo " -t Build and execute ut"
  32. echo " -c Build ut with coverage tag"
  33. echo " -v Display build command"
  34. echo " -S Enable enable download cmake compile dependency from gitee , default off"
  35. echo "to be continued ..."
  36. }
  37. # check value of input is 'on' or 'off'
  38. # usage: check_on_off arg_value arg_name
  39. check_on_off()
  40. {
  41. if [[ "X$1" != "Xon" && "X$1" != "Xoff" ]]; then
  42. echo "Invalid value $1 for option -$2"
  43. usage
  44. exit 1
  45. fi
  46. }
  47. # parse and set options
  48. checkopts()
  49. {
  50. VERBOSE=""
  51. THREAD_NUM=8
  52. # ENABLE_PARSER_UT_ONLY_COMPILE="off"
  53. ENABLE_PARSER_UT="off"
  54. ENABLE_PARSER_ST="off"
  55. ENABLE_PARSER_COV="off"
  56. GE_ONLY="on"
  57. ENABLE_GITEE="off"
  58. # Process the options
  59. while getopts 'ustchj:vS:' opt
  60. do
  61. OPTARG=$(echo ${OPTARG} | tr '[A-Z]' '[a-z]')
  62. case "${opt}" in
  63. u)
  64. ENABLE_PARSER_UT="on"
  65. GE_ONLY="off"
  66. ;;
  67. s)
  68. ENABLE_PARSER_ST="on"
  69. ;;
  70. t)
  71. ENABLE_PARSER_UT="on"
  72. GE_ONLY="off"
  73. ;;
  74. c)
  75. ENABLE_PARSER_COV="on"
  76. GE_ONLY="off"
  77. ;;
  78. h)
  79. usage
  80. exit 0
  81. ;;
  82. j)
  83. THREAD_NUM=$OPTARG
  84. ;;
  85. v)
  86. VERBOSE="VERBOSE=1"
  87. ;;
  88. S)
  89. check_on_off $OPTARG S
  90. ENABLE_GITEE="$OPTARG"
  91. echo "enable download from gitee"
  92. ;;
  93. *)
  94. echo "Undefined option: ${opt}"
  95. usage
  96. exit 1
  97. esac
  98. done
  99. }
  100. checkopts "$@"
  101. git submodule update --init metadef
  102. mk_dir() {
  103. local create_dir="$1" # the target to make
  104. mkdir -pv "${create_dir}"
  105. echo "created ${create_dir}"
  106. }
  107. # Parser build start
  108. echo "---------------- Parser build start ----------------"
  109. # create build path
  110. build_parser()
  111. {
  112. echo "create build directory and build Parser";
  113. mk_dir "${BUILD_PATH}"
  114. cd "${BUILD_PATH}"
  115. CMAKE_ARGS="-DBUILD_PATH=$BUILD_PATH -DGE_ONLY=$GE_ONLY"
  116. if [[ "X$ENABLE_PARSER_COV" = "Xon" ]]; then
  117. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_PARSER_COV=ON"
  118. fi
  119. if [[ "X$ENABLE_PARSER_UT" = "Xon" ]]; then
  120. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_PARSER_UT=ON"
  121. fi
  122. if [[ "X$ENABLE_PARSER_ST" = "Xon" ]]; then
  123. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_PARSER_ST=ON"
  124. fi
  125. if [[ "X$ENABLE_GITEE" = "Xon" ]]; then
  126. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GITEE=ON"
  127. fi
  128. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_OPEN_SRC=True -DCMAKE_INSTALL_PREFIX=${OUTPUT_PATH}"
  129. echo "${CMAKE_ARGS}"
  130. cmake ${CMAKE_ARGS} ..
  131. if [ 0 -ne $? ]
  132. then
  133. echo "execute command: cmake ${CMAKE_ARGS} .. failed."
  134. return 1
  135. fi
  136. if [ "X$ENABLE_PARSER_UT" = "Xon" ]; then
  137. make ut_parser -j8
  138. elif [ "X$ENABLE_PARSER_ST" = "Xon" ]; then
  139. make st_parser -j8
  140. else
  141. make ${VERBOSE} -j${THREAD_NUM} && make install
  142. fi
  143. if [ 0 -ne $? ]
  144. then
  145. echo "execute command: make ${VERBOSE} -j${THREAD_NUM} && make install failed."
  146. return 1
  147. fi
  148. echo "Parser build success!"
  149. }
  150. g++ -v
  151. mk_dir ${OUTPUT_PATH}
  152. build_parser || { echo "Parser build failed."; return; }
  153. echo "---------------- Parser build finished ----------------"
  154. rm -f ${OUTPUT_PATH}/libgmock*.so
  155. rm -f ${OUTPUT_PATH}/libgtest*.so
  156. rm -f ${OUTPUT_PATH}/lib*_stub.so
  157. chmod -R 750 ${OUTPUT_PATH}
  158. find ${OUTPUT_PATH} -name "*.so*" -print0 | xargs -0 chmod 500
  159. echo "---------------- Parser output generated ----------------"
  160. if [[ "X$ENABLE_PARSER_UT" = "Xon" || "X$ENABLE_PARSER_COV" = "Xon" ]]; then
  161. cp ${BUILD_PATH}/tests/ut/parser/ut_parser ${OUTPUT_PATH}
  162. RUN_TEST_CASE=${OUTPUT_PATH}/ut_parser && ${RUN_TEST_CASE}
  163. if [[ "$?" -ne 0 ]]; then
  164. echo "!!! UT FAILED, PLEASE CHECK YOUR CHANGES !!!"
  165. echo -e "\033[31m${RUN_TEST_CASE}\033[0m"
  166. exit 1;
  167. fi
  168. echo "Generating coverage statistics, please wait..."
  169. cd ${BASEPATH}
  170. rm -rf ${BASEPATH}/cov
  171. mkdir ${BASEPATH}/cov
  172. lcov -c -d build/tests/ut/parser -o cov/tmp.info
  173. lcov -r cov/tmp.info '*/output/*' '*/build/opensrc/*' '*/build/proto/*' '*/third_party/*' '*/tests/*' '/usr/local/*' '*/metadef/inc/*' -o cov/coverage.info
  174. cd ${BASEPATH}/cov
  175. genhtml coverage.info
  176. fi
  177. if [[ "X$ENABLE_PARSER_ST" = "Xon" ]]; then
  178. cp ${BUILD_PATH}/tests/st/st_parser ${OUTPUT_PATH}
  179. RUN_TEST_CASE=${OUTPUT_PATH}/st_parser && ${RUN_TEST_CASE}
  180. if [[ "$?" -ne 0 ]]; then
  181. echo "!!! ST FAILED, PLEASE CHECK YOUR CHANGES !!!"
  182. echo -e "\033[31m${RUN_TEST_CASE}\033[0m"
  183. exit 1;
  184. fi
  185. echo "Generating coverage statistics, please wait..."
  186. cd ${BASEPATH}
  187. rm -rf ${BASEPATH}/cov
  188. mkdir ${BASEPATH}/cov
  189. lcov -c -d build/tests/st -o cov/tmp.info
  190. lcov -r cov/tmp.info '*/output/*' '*/build/opensrc/*' '*/build/proto/*' '*/third_party/*' '*/tests/*' '/usr/local/*' '*/metadef/inc/*' -o cov/coverage.info
  191. cd ${BASEPATH}/cov
  192. genhtml coverage.info
  193. fi
  194. # generate output package in tar form, including ut/st libraries/executables for cann
  195. generate_package()
  196. {
  197. cd "${BASEPATH}"
  198. PARSER_LIB_PATH="lib"
  199. COMPILER_PATH="compiler/lib64"
  200. COMMON_LIB=("libgraph.so" "libregister.so" "liberror_manager.so")
  201. PARSER_LIB=("lib_caffe_parser.so" "libfmk_onnx_parser.so" "libfmk_parser.so" "libparser_common.so")
  202. rm -rf ${OUTPUT_PATH:?}/${COMPILER_PATH}/
  203. mk_dir "${OUTPUT_PATH}/${COMPILER_PATH}"
  204. find output/ -name parser_lib.tar -exec rm {} \;
  205. cd "${OUTPUT_PATH}"
  206. for lib in "${PARSER_LIB[@]}";
  207. do
  208. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${COMPILER_PATH} \;
  209. done
  210. for lib in "${COMMON_LIB[@]}";
  211. do
  212. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${COMPILER_PATH} \;
  213. done
  214. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "libc_sec.so" -exec cp -f {} ${OUTPUT_PATH}/${COMPILER_PATH} \;
  215. tar -cf parser_lib.tar compiler
  216. }
  217. if [[ "X$ENABLE_PARSER_UT" = "Xoff" && "X$ENABLE_PARSER_ST" = "Xoff" ]]; then
  218. generate_package
  219. fi
  220. echo "---------------- Parser package archive generated ----------------"