|
1 | 1 | #!/bin/sh |
| 2 | +# |
| 3 | +# Copyright (c) 2022 MIEK |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
2 | 14 |
|
3 | | -pip3 install build |
4 | | -rm -rf ./dist |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +BUILD_DIST_DIR_PATH=./dist |
| 24 | +BUILD_PACKAGE_DIR_PATH=./packages |
| 25 | +MAIN_PACKAGE_DIR_PATH=./ |
| 26 | + |
| 27 | +ensure_installed_build_toolbox() { |
| 28 | + echo "checking build toolbox..." |
| 29 | + |
| 30 | + if [ -z "$(which python3)" ] |
| 31 | + then |
| 32 | + echo 'error: Python3 must be installed' |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | + |
| 36 | + if [ -z "$(which pip3)" ] |
| 37 | + then |
| 38 | + echo 'error: PIP3 must be installed' |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | + |
| 42 | + pip3 install build -q |
| 43 | + if [ ! $? -eq 0 ] |
| 44 | + then |
| 45 | + echo "error: failed to install build toolbox" |
| 46 | + fi |
| 47 | +} |
| 48 | + |
| 49 | +clean_build_packages() { |
| 50 | + if [ -d "${BUILD_DIST_DIR_PATH}" ] |
| 51 | + then |
| 52 | + echo "cleaning build packages..." |
| 53 | + rm -rf "${BUILD_DIST_DIR_PATH}" |
| 54 | + fi |
| 55 | +} |
| 56 | + |
| 57 | +get_package_name() { |
| 58 | + if [ $1 = $MAIN_PACKAGE_DIR_PATH ] |
| 59 | + then |
| 60 | + echo 'main' |
| 61 | + else |
| 62 | + basename $1 |
| 63 | + fi |
| 64 | +} |
5 | 65 |
|
6 | 66 | build_package() { |
7 | | - python3 -m build ./packages/$1 -o ./dist |
| 67 | + package_name=$(get_package_name "${1}") |
| 68 | + |
| 69 | + echo "building package: ${package_name}" |
| 70 | + python3 -m build "${1}" -o "${BUILD_DIST_DIR_PATH}" > /dev/null |
| 71 | + |
| 72 | + if [ ! $? -eq 0 ] |
| 73 | + then |
| 74 | + echo "error: failed to build package: ${package_name}" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | +} |
| 78 | + |
| 79 | +build_all_packages() { |
| 80 | + echo "building all packages..." |
| 81 | + for package_path in $BUILD_PACKAGE_DIR_PATH/* |
| 82 | + do |
| 83 | + build_package $package_path & |
| 84 | + done |
| 85 | + |
| 86 | + wait |
| 87 | + build_package $MAIN_PACKAGE_DIR_PATH |
| 88 | + |
| 89 | + echo 'all packages are build' |
8 | 90 | } |
9 | 91 |
|
10 | | -build_package tencent-cloud-sdk-auth |
11 | | -build_package tencent-cloud-sdk-common |
12 | | -build_package tencent-cloud-sdk-core |
13 | | -build_package tencent-cloud-sdk-serverless-database |
14 | | -build_package tencent-cloud-sdk-serverless-functions |
15 | | -build_package .. |
| 92 | +ensure_installed_build_toolbox |
| 93 | +clean_build_packages |
| 94 | +build_all_packages |
0 commit comments