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