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 6.7 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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. else
  139. make ${VERBOSE} -j${THREAD_NUM} && make install
  140. fi
  141. if [ 0 -ne $? ]
  142. then
  143. echo "execute command: make ${VERBOSE} -j${THREAD_NUM} && make install failed."
  144. return 1
  145. fi
  146. echo "Parser build success!"
  147. }
  148. g++ -v
  149. mk_dir ${OUTPUT_PATH}
  150. build_parser || { echo "Parser build failed."; return; }
  151. echo "---------------- Parser build finished ----------------"
  152. rm -f ${OUTPUT_PATH}/libgmock*.so
  153. rm -f ${OUTPUT_PATH}/libgtest*.so
  154. rm -f ${OUTPUT_PATH}/lib*_stub.so
  155. chmod -R 750 ${OUTPUT_PATH}
  156. find ${OUTPUT_PATH} -name "*.so*" -print0 | xargs -0 chmod 500
  157. echo "---------------- Parser output generated ----------------"
  158. if [[ "X$ENABLE_PARSER_UT" = "Xon" || "X$ENABLE_PARSER_COV" = "Xon" ]]; then
  159. cp ${BUILD_PATH}/tests/ut/parser/ut_parser ${OUTPUT_PATH}
  160. RUN_TEST_CASE=${OUTPUT_PATH}/ut_parser && ${RUN_TEST_CASE}
  161. if [[ "$?" -ne 0 ]]; then
  162. echo "!!! UT FAILED, PLEASE CHECK YOUR CHANGES !!!"
  163. echo -e "\033[31m${RUN_TEST_CASE}\033[0m"
  164. exit 1;
  165. fi
  166. echo "Generating coverage statistics, please wait..."
  167. cd ${BASEPATH}
  168. rm -rf ${BASEPATH}/cov
  169. mkdir ${BASEPATH}/cov
  170. lcov -c -d build/tests/ut/parser -o cov/tmp.info
  171. lcov -r cov/tmp.info '*/output/*' '*/build/opensrc/*' '*/build/proto/*' '*/third_party/*' '*/tests/*' '/usr/local/*' '*/metadef/inc/*' -o cov/coverage.info
  172. cd ${BASEPATH}/cov
  173. genhtml coverage.info
  174. fi
  175. # generate output package in tar form, including ut/st libraries/executables
  176. generate_package()
  177. {
  178. cd "${BASEPATH}"
  179. PARSER_LIB_PATH="lib"
  180. ACL_PATH="acllib/lib64"
  181. FWK_PATH="fwkacllib/lib64"
  182. ATC_PATH="atc/lib64"
  183. COMMON_LIB=("libgraph.so" "libregister.so" "liberror_manager.so")
  184. PARSER_LIB=("lib_caffe_parser.so" "libfmk_onnx_parser.so" "libfmk_parser.so" "libparser_common.so")
  185. rm -rf ${OUTPUT_PATH:?}/${FWK_PATH}/
  186. rm -rf ${OUTPUT_PATH:?}/${ACL_PATH}/
  187. rm -rf ${OUTPUT_PATH:?}/${ATC_PATH}/
  188. mk_dir "${OUTPUT_PATH}/${FWK_PATH}"
  189. mk_dir "${OUTPUT_PATH}/${ATC_PATH}"
  190. mk_dir "${OUTPUT_PATH}/${ACL_PATH}"
  191. find output/ -name parser_lib.tar -exec rm {} \;
  192. cd "${OUTPUT_PATH}"
  193. for lib in "${PARSER_LIB[@]}";
  194. do
  195. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${FWK_PATH} \;
  196. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${ATC_PATH} \;
  197. done
  198. for lib in "${COMMON_LIB[@]}";
  199. do
  200. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${FWK_PATH} \;
  201. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${ATC_PATH} \;
  202. done
  203. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "libc_sec.so" -exec cp -f {} ${OUTPUT_PATH}/${ATC_PATH} \;
  204. tar -cf parser_lib.tar fwkacllib acllib atc
  205. }
  206. if [[ "X$ENABLE_PARSER_UT" = "Xoff" ]]; then
  207. generate_package
  208. fi
  209. echo "---------------- Parser package archive generated ----------------"