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