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 5.8 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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_GE_UT_ONLY_COMPILE="off"
  53. ENABLE_GE_UT="off"
  54. ENABLE_GE_ST="off"
  55. ENABLE_GE_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_GE_UT_ONLY_COMPILE="on"
  65. ENABLE_GE_UT="on"
  66. GE_ONLY="off"
  67. ;;
  68. s)
  69. ENABLE_GE_ST="on"
  70. ;;
  71. t)
  72. ENABLE_GE_UT="on"
  73. GE_ONLY="off"
  74. ;;
  75. c)
  76. ENABLE_GE_COV="on"
  77. GE_ONLY="off"
  78. ;;
  79. h)
  80. usage
  81. exit 0
  82. ;;
  83. j)
  84. THREAD_NUM=$OPTARG
  85. ;;
  86. v)
  87. VERBOSE="VERBOSE=1"
  88. ;;
  89. S)
  90. check_on_off $OPTARG S
  91. ENABLE_GITEE="$OPTARG"
  92. echo "enable download from gitee"
  93. ;;
  94. *)
  95. echo "Undefined option: ${opt}"
  96. usage
  97. exit 1
  98. esac
  99. done
  100. }
  101. checkopts "$@"
  102. git submodule update --init metadef
  103. mk_dir() {
  104. local create_dir="$1" # the target to make
  105. mkdir -pv "${create_dir}"
  106. echo "created ${create_dir}"
  107. }
  108. # Parser build start
  109. echo "---------------- Parser build start ----------------"
  110. # create build path
  111. build_parser()
  112. {
  113. echo "create build directory and build Parser";
  114. mk_dir "${BUILD_PATH}"
  115. cd "${BUILD_PATH}"
  116. CMAKE_ARGS="-DBUILD_PATH=$BUILD_PATH -DGE_ONLY=$GE_ONLY"
  117. if [[ "X$ENABLE_GE_COV" = "Xon" ]]; then
  118. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_COV=ON"
  119. fi
  120. if [[ "X$ENABLE_GE_UT" = "Xon" ]]; then
  121. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_UT=ON"
  122. fi
  123. if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then
  124. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_ST=ON"
  125. fi
  126. if [[ "X$ENABLE_GITEE" = "Xon" ]]; then
  127. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GITEE=ON"
  128. fi
  129. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_OPEN_SRC=True -DCMAKE_INSTALL_PREFIX=${OUTPUT_PATH}"
  130. echo "${CMAKE_ARGS}"
  131. cmake ${CMAKE_ARGS} ..
  132. if [ 0 -ne $? ]
  133. then
  134. echo "execute command: cmake ${CMAKE_ARGS} .. failed."
  135. return 1
  136. fi
  137. make ${VERBOSE} -j${THREAD_NUM} && make install
  138. if [ 0 -ne $? ]
  139. then
  140. echo "execute command: make ${VERBOSE} -j${THREAD_NUM} && make install failed."
  141. return 1
  142. fi
  143. echo "Parser build success!"
  144. }
  145. g++ -v
  146. mk_dir ${OUTPUT_PATH}
  147. build_parser || { echo "Parser build failed."; return; }
  148. echo "---------------- Parser build finished ----------------"
  149. rm -f ${OUTPUT_PATH}/libgmock*.so
  150. rm -f ${OUTPUT_PATH}/libgtest*.so
  151. rm -f ${OUTPUT_PATH}/lib*_stub.so
  152. chmod -R 750 ${OUTPUT_PATH}
  153. find ${OUTPUT_PATH} -name "*.so*" -print0 | xargs -0 chmod 500
  154. echo "---------------- Parser output generated ----------------"
  155. # generate output package in tar form, including ut/st libraries/executables
  156. generate_package()
  157. {
  158. cd "${BASEPATH}"
  159. PARSER_LIB_PATH="lib"
  160. ACL_PATH="acllib/lib64"
  161. FWK_PATH="fwkacllib/lib64"
  162. ATC_PATH="atc/lib64"
  163. COMMON_LIB=("libgraph.so" "libregister.so")
  164. PARSER_LIB=("lib_caffe_parser.so" "libfmk_onnx_parser.so" "libfmk_parser.so" "libparser_common.so")
  165. rm -rf ${OUTPUT_PATH:?}/${FWK_PATH}/
  166. rm -rf ${OUTPUT_PATH:?}/${ACL_PATH}/
  167. rm -rf ${OUTPUT_PATH:?}/${ATC_PATH}/
  168. mk_dir "${OUTPUT_PATH}/${FWK_PATH}"
  169. mk_dir "${OUTPUT_PATH}/${ATC_PATH}"
  170. mk_dir "${OUTPUT_PATH}/${ACL_PATH}"
  171. find output/ -name parser_lib.tar -exec rm {} \;
  172. cd "${OUTPUT_PATH}"
  173. for lib in "${PARSER_LIB[@]}";
  174. do
  175. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${FWK_PATH} \;
  176. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${ATC_PATH} \;
  177. done
  178. for lib in "${COMMON_LIB[@]}";
  179. do
  180. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${FWK_PATH} \;
  181. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "$lib" -exec cp -f {} ${OUTPUT_PATH}/${ATC_PATH} \;
  182. done
  183. find ${OUTPUT_PATH}/${PARSER_LIB_PATH} -maxdepth 1 -name "libc_sec.so" -exec cp -f {} ${OUTPUT_PATH}/${ATC_PATH} \;
  184. tar -cf parser_lib.tar fwkacllib acllib atc
  185. }
  186. if [[ "X$ENABLE_GE_UT" = "Xoff" ]]; then
  187. generate_package
  188. fi
  189. echo "---------------- Parser package archive generated ----------------"