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 3.3 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/bin/bash
  2. # Copyright 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. set -e
  16. SCRIPT_BASEDIR=$(realpath "$(dirname "$0")")
  17. PROJECT_BASEDIR=$(dirname "$SCRIPT_BASEDIR")
  18. rename_wheel() {
  19. cd "$PROJECT_BASEDIR/output" || exit
  20. VERSION="$("$PYTHON" -c 'import platform; print(platform.python_version())')"
  21. PACKAGE_LIST=$(ls mindinsight-*-any.whl) || exit
  22. for PACKAGE_ORIG in $PACKAGE_LIST; do
  23. MINDINSIGHT_VERSION=$(echo "$PACKAGE_ORIG" | awk -F"-" '{print $2}')
  24. PYTHON_VERSION_NUM=$(echo "$VERSION" | awk -F"." '{print $1$2}')
  25. PYTHON_VERSION_TAG="cp$PYTHON_VERSION_NUM"
  26. PYTHON_ABI_TAG="cp${PYTHON_VERSION_NUM}m"
  27. OS_NAME=$(uname | tr '[:upper:]' '[:lower:]')
  28. MACHINE_TAG="${OS_NAME}_$(uname -i)"
  29. PACKAGE_NEW="mindinsight-$MINDINSIGHT_VERSION-$PYTHON_VERSION_TAG-$PYTHON_ABI_TAG-$MACHINE_TAG.whl"
  30. mv "$PACKAGE_ORIG" "$PACKAGE_NEW"
  31. done
  32. }
  33. write_checksum() {
  34. cd "$PROJECT_BASEDIR/output" || exit
  35. PACKAGE_LIST=$(ls mindinsight-*.whl) || exit
  36. for PACKAGE_NAME in $PACKAGE_LIST; do
  37. sha256sum -b "$PACKAGE_NAME" >"$PACKAGE_NAME.sha256"
  38. done
  39. }
  40. build_wheel() {
  41. cd "$PROJECT_BASEDIR" || exit
  42. if [ $# -gt 0 ]; then
  43. if [ "$1" = "clean" ]; then
  44. echo "start cleaning mindinsight"
  45. clean_files
  46. echo "clean mindinsight done"
  47. else
  48. echo "unknown command: $1"
  49. fi
  50. exit
  51. fi
  52. echo "start building mindinsight"
  53. clean_files
  54. if command -v python3; then
  55. PYTHON=python3
  56. elif command -v python; then
  57. PYTHON=python
  58. else
  59. command python3
  60. fi
  61. if ! "$PYTHON" -c 'import sys; assert sys.version_info >= (3, 7)' &>/dev/null; then
  62. echo "Python 3.7 or higher is required. You are running $("$PYTHON" -V)"
  63. exit 1
  64. fi
  65. rm -rf output
  66. "$PYTHON" setup.py bdist_wheel
  67. if [ ! -x "dist" ]; then
  68. echo "Build failed"
  69. exit 1
  70. fi
  71. mv dist output
  72. rename_wheel
  73. write_checksum
  74. clean_files
  75. echo "Build success, output directory is: $PROJECT_BASEDIR/output"
  76. }
  77. clean_files() {
  78. cd "$PROJECT_BASEDIR" || exit
  79. rm -rf build/lib
  80. rm -rf build/bdist.*
  81. rm -rf mindinsight.egg-info
  82. }
  83. show_usage() {
  84. echo "Build mindinsight"
  85. echo ""
  86. echo "usage: build.sh [-h] [clean]"
  87. echo ""
  88. echo "options:"
  89. echo " -h show this help message and exit"
  90. echo " clean clean build files"
  91. }
  92. check_opts() {
  93. while getopts ':h' OPT; do
  94. case "$OPT" in
  95. h)
  96. show_usage
  97. exit 0
  98. ;;
  99. \?)
  100. show_usage
  101. exit 1
  102. ;;
  103. esac
  104. done
  105. }
  106. check_opts "$@"
  107. build_wheel "$@"