|
[ Source navigation ] [ Diff markup ] [ Identifier search ] |
|||
|
Warning, file /build.sh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #!/bin/bash 0002 # Copyright (c) 2021 Huawei Device Co., Ltd. 0003 # Licensed under the Apache License, Version 2.0 (the "License"); 0004 # you may not use this file except in compliance with the License. 0005 # You may obtain a copy of the License at 0006 # 0007 # http://www.apache.org/licenses/LICENSE-2.0 0008 # 0009 # Unless required by applicable law or agreed to in writing, software 0010 # distributed under the License is distributed on an "AS IS" BASIS, 0011 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0012 # See the License for the specific language governing permissions and 0013 # limitations under the License. 0014 0015 set -e 0016 set +e 0017 echo -e "\n\033[32m\t*********Welcome to OpenHarmony!*********\033[0m\n" 0018 echo -e "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 0019 function check_shell_environment() { 0020 case $(uname -s) in 0021 Linux) 0022 shell_result=$(/bin/sh -c 'echo ${BASH_VERSION}') 0023 if [ -n "${shell_result}" ]; then 0024 echo -e "\033[32mSystem shell: bash ${shell_result}\033[0m" 0025 else 0026 echo -e "\033[33m Your system shell isn't bash, we recommend you to use bash, because some commands may not be supported in other shells, such as pushd and shopt are not supported in dash. \n You can follow these tips to modify the system shell to bash on Ubuntu: \033[0m" 0027 echo -e "\033[33m [1]:Open the Terminal tool and execute the following command: sudo dpkg-reconfigure dash \n [2]:Enter the password and select <no> \033[0m" 0028 fi 0029 ;; 0030 Darwin) 0031 echo -e "\033[31m[OHOS ERROR] Darwin system is not supported yet\033[0m" 0032 ;; 0033 *) 0034 echo -e "\033[31m[OHOS ERROR] Unsupported this system: $(uname -s)\033[0m" 0035 exit 1 0036 esac 0037 } 0038 0039 check_shell_environment 0040 0041 echo -e "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 0042 echo -e "\033[32mCurrent time: $(date +%F' '%H:%M:%S)\033[0m" 0043 echo -e "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 0044 echo -e "\033[32mBuild args: $@\033[0m" 0045 echo -e "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" 0046 0047 export SOURCE_ROOT_DIR=$(cd $(dirname $0);pwd) 0048 0049 while [[ ! -f "${SOURCE_ROOT_DIR}/.gn" ]]; do 0050 SOURCE_ROOT_DIR="$(dirname "${SOURCE_ROOT_DIR}")" 0051 if [[ "${SOURCE_ROOT_DIR}" == "/" ]]; then 0052 echo -e "\033[31m[OHOS ERROR] Cannot find source tree containing $(pwd)\033[0m" 0053 exit 1 0054 fi 0055 done 0056 0057 if [[ "${SOURCE_ROOT_DIR}x" == "x" ]]; then 0058 echo -e "\033[31m[OHOS ERROR] SOURCE_ROOT_DIR cannot be empty.\033[0m" 0059 exit 1 0060 fi 0061 0062 0063 host_cpu_prefix="" 0064 0065 case $(uname -m) in 0066 *x86_64) 0067 host_cpu_prefix="x86" 0068 ;; 0069 *arm*) 0070 host_cpu_prefix="arm64" 0071 ;; 0072 *) 0073 echo "\033[31m[OHOS ERROR] Unsupported host arch: $(uname -m)\033[0m" 0074 RET=1 0075 exit $RET 0076 esac 0077 0078 case $(uname -s) in 0079 Darwin) 0080 HOST_DIR="darwin-x86" 0081 PYTHON_DIR="darwin-$host_cpu_prefix" 0082 HOST_OS="mac" 0083 NODE_PLATFORM="darwin-x64" 0084 ;; 0085 Linux) 0086 HOST_DIR="linux-x86" 0087 PYTHON_DIR="linux-$host_cpu_prefix" 0088 HOST_OS="linux" 0089 NODE_PLATFORM="linux-x64" 0090 ;; 0091 *) 0092 echo "\033[31m[OHOS ERROR] Unsupported host platform: $(uname -s)\033[0m" 0093 RET=1 0094 exit $RET 0095 esac 0096 0097 # set python3 0098 PYTHON3_DIR=$(realpath ${SOURCE_ROOT_DIR}/prebuilts/python/${PYTHON_DIR}/*/ | tail -1) 0099 PYTHON3=${PYTHON3_DIR}/bin/python3 0100 PYTHON=${PYTHON3_DIR}/bin/python 0101 if [[ ! -f "${PYTHON3}" ]]; then 0102 echo -e "\033[31m[OHOS ERROR] Please execute the build/prebuilts_download.sh \033[0m" 0103 exit 1 0104 else 0105 if [[ ! -f "${PYTHON}" ]]; then 0106 ln -sf "${PYTHON3}" "${PYTHON}" 0107 fi 0108 fi 0109 0110 export PATH=${SOURCE_ROOT_DIR}/prebuilts/build-tools/${HOST_DIR}/bin:${PYTHON3_DIR}/bin:$PATH 0111 0112 # set nodejs and ohpm 0113 EXPECTED_NODE_VERSION="14.21.1" 0114 export PATH=${SOURCE_ROOT_DIR}/prebuilts/build-tools/common/nodejs/node-v${EXPECTED_NODE_VERSION}-${NODE_PLATFORM}/bin:$PATH 0115 export NODE_HOME=${SOURCE_ROOT_DIR}/prebuilts/build-tools/common/nodejs/node-v${EXPECTED_NODE_VERSION}-${NODE_PLATFORM} 0116 export PATH=${SOURCE_ROOT_DIR}/prebuilts/build-tools/common/oh-command-line-tools/ohpm/bin:$PATH 0117 echo "[OHOS INFO] Current Node.js version is $(node -v)" 0118 NODE_VERSION=$(node -v) 0119 if [ "$NODE_VERSION" != "v$EXPECTED_NODE_VERSION" ]; then 0120 echo -e "\033[31m[OHOS ERROR] Node.js version mismatch. Expected $EXPECTED_NODE_VERSION but found $NODE_VERSION\033[0m" >&2 0121 exit 1 0122 fi 0123 echo -e "\033[32m[OHOS INFO] Node.js version check passed!\033[0m" 0124 npm config set registry https://repo.huaweicloud.com/repository/npm/ 0125 npm config set @ohos:registry https://repo.harmonyos.com/npm/ 0126 npm config set strict-ssl false 0127 npm config set lockfile false 0128 cat $HOME/.npmrc | grep 'lockfile=false' > /dev/null || echo 'lockfile=false' >> $HOME/.npmrc > /dev/null 0129 0130 function init_ohpm() { 0131 TOOLS_INSTALL_DIR="${SOURCE_ROOT_DIR}/prebuilts/build-tools/common" 0132 pushd ${TOOLS_INSTALL_DIR} > /dev/null 0133 if [[ ! -f "${TOOLS_INSTALL_DIR}/oh-command-line-tools/ohpm/bin/ohpm" ]]; then 0134 echo "[OHOS INFO] download oh-command-line-tools" 0135 wget https://repo.huaweicloud.com/harmonyos/ohpm/5.0.2/oh-command-line-tools-20240715.zip -O ohcommandline-tools-linux.zip 0136 unzip ohcommandline-tools-linux.zip 0137 fi 0138 OHPM_HOME=${TOOLS_INSTALL_DIR}/oh-command-line-tools/ohpm/bin 0139 chmod +x ${OHPM_HOME}/ohpm 0140 export PATH=${OHPM_HOME}:$PATH 0141 chmod +x ${OHPM_HOME}/init 0142 ${OHPM_HOME}/init > /dev/null 0143 echo "[OHOS INFO] Current ohpm version is $(ohpm -v)" 0144 ohpm config set registry https://repo.harmonyos.com/ohpm/ 0145 ohpm config set strict_ssl false 0146 ohpm config set log_level debug 0147 popd > /dev/null 0148 if [[ -d "$HOME/.hvigor" ]]; then 0149 rm -rf $HOME/.hvigor/daemon $HOME/.hvigor/wrapper 0150 fi 0151 mkdir -p $HOME/.hvigor/wrapper/tools 0152 echo '{"dependencies": {"pnpm": "7.30.0"}}' > $HOME/.hvigor/wrapper/tools/package.json 0153 pushd $HOME/.hvigor/wrapper/tools > /dev/null 0154 echo "[OHOS INFO] installing pnpm..." 0155 npm install --silent > /dev/null 0156 popd > /dev/null 0157 mkdir -p $HOME/.ohpm 0158 echo '{"devDependencies":{"@ohos/hypium":"1.0.6"}}' > $HOME/.ohpm/oh-package.json5 0159 pushd $HOME/.ohpm > /dev/null 0160 echo "[OHOS INFO] installing hypium..." 0161 ohpm install > /dev/null 0162 popd > /dev/null 0163 } 0164 0165 if [[ "$*" != *ohos-sdk* ]]; then 0166 echo "[OHOS INFO] Ohpm initialization started..." 0167 init_ohpm 0168 if [[ "$?" -ne 0 ]]; then 0169 echo -e "\033[31m[OHOS ERROR] ohpm initialization failed!\033[0m" 0170 exit 1 0171 fi 0172 echo -e "\033[32m[OHOS INFO] ohpm initialization successful!\033[0m" 0173 fi 0174 echo -e "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" 0175 0176 echo -e "\033[32m[OHOS INFO] Start building...\033[0m\n" 0177 function build_sdk() { 0178 ROOT_PATH=${SOURCE_ROOT_DIR} 0179 SDK_PREBUILTS_PATH=${ROOT_PATH}/prebuilts/ohos-sdk 0180 0181 pushd ${ROOT_PATH} > /dev/null 0182 echo -e "[OHOS INFO] building the latest ohos-sdk..." 0183 ./build.py --product-name ohos-sdk $ccache_args $xcache_args --load-test-config=false --get-warning-list=false --stat-ccache=false --compute-overlap-rate=false --deps-guard=false --generate-ninja-trace=false --gn-args skip_generate_module_list_file=true sdk_platform=linux ndk_platform=linux use_cfi=false use_thin_lto=false enable_lto_O0=true sdk_check_flag=false enable_ndk_doxygen=false archive_ndk=false sdk_for_hap_build=true enable_archive_sdk=false enable_notice_collection=false enable_process_notice=false 0184 if [[ "$?" -ne 0 ]]; then 0185 echo -e "\033[31m[OHOS ERROR] ohos-sdk build failed! You can try to use '--no-prebuilt-sdk' to skip the build of ohos-sdk.\033[0m" 0186 exit 1 0187 fi 0188 if [ -d "${ROOT_PATH}/prebuilts/ohos-sdk/linux" ]; then 0189 rm -rf ${ROOT_PATH}/prebuilts/ohos-sdk/linux 0190 fi 0191 mkdir -p ${SDK_PREBUILTS_PATH} 0192 mv ${ROOT_PATH}/out/sdk/ohos-sdk/linux ${SDK_PREBUILTS_PATH}/ 0193 mkdir -p ${SDK_PREBUILTS_PATH}/linux/native 0194 mv ${ROOT_PATH}/out/sdk/sdk-native/os-irrelevant/* ${SDK_PREBUILTS_PATH}/linux/native/ 0195 mv ${ROOT_PATH}/out/sdk/sdk-native/os-specific/linux/* ${SDK_PREBUILTS_PATH}/linux/native/ 0196 pushd ${SDK_PREBUILTS_PATH}/linux > /dev/null 0197 api_version=$(grep apiVersion toolchains/oh-uni-package.json | awk '{print $2}' | sed -r 's/\",?//g') || api_version="11" 0198 mkdir -p $api_version 0199 for i in */; do 0200 if [ -d "$i" ] && [ "$i" != "$api_version/" ]; then 0201 mv $i $api_version 0202 fi 0203 done 0204 popd > /dev/null 0205 popd > /dev/null 0206 } 0207 if [[ ! -d "${SOURCE_ROOT_DIR}/prebuilts/ohos-sdk/linux" && "$*" != *ohos-sdk* && "$*" != *"--no-prebuilt-sdk"* || "${@}" =~ "--prebuilt-sdk" ]]; then 0208 echo -e "\033[33m[OHOS INFO] The OHOS-SDK was not detected, so the SDK compilation will be prioritized automatically. You can also control whether to execute this process by using '--no-prebuilt-sdk' and '--prebuilt-sdk'.\033[0m" 0209 if [[ "${@}" =~ "--ccache=false" || "${@}" =~ "--ccache false" ]]; then 0210 ccache_args="--ccache=false" 0211 else 0212 ccache_args="--ccache=true" 0213 fi 0214 if [[ "${@}" =~ "--xcache=true" || "${@}" =~ "--xcache true" || "${@}" =~ "--xcache" ]]; then 0215 xcache_args="--xcache=true" 0216 else 0217 xcache_args="--xcache=false" 0218 fi 0219 build_sdk 0220 if [[ "$?" -ne 0 ]]; then 0221 echo -e "\033[31m[OHOS ERROR] ohos-sdk build failed, please remove the out/sdk directory and try again!\033[0m" 0222 exit 1 0223 fi 0224 fi 0225 0226 ${PYTHON3} ${SOURCE_ROOT_DIR}/build/scripts/tools_checker.py 0227 0228 flag=true 0229 args_list=$@ 0230 for var in $@ 0231 do 0232 OPTIONS=${var%%=*} 0233 PARAM=${var#*=} 0234 if [[ "$OPTIONS" == "using_hb_new" && "$PARAM" == "false" ]]; then 0235 flag=false 0236 ${PYTHON3} ${SOURCE_ROOT_DIR}/build/scripts/entry.py --source-root-dir ${SOURCE_ROOT_DIR} $args_list 0237 break 0238 fi 0239 done 0240 if [[ ${flag} == "true" ]]; then 0241 ${PYTHON3} ${SOURCE_ROOT_DIR}/build/hb/main.py build $args_list 0242 fi 0243 0244 if [[ "$?" -ne 0 ]]; then 0245 echo -e "\033[31m=====build ${product_name} error=====\033[0m" 0246 exit 1 0247 fi 0248 echo -e "\033[32m=====build ${product_name} successful=====\033[0m" 0249 0250 date +%F' '%H:%M:%S 0251 echo "++++++++++++++++++++++++++++++++++++++++"
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] |
本网站由冷钦街制作 主页 |
蜀ICP备2022028677 |