1#!/bin/bash 2# Copyright (c) 2021 Huawei Device Co., Ltd. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15set -e 16set +e 17echo "++++++++++++++++++++++++++++++++++++++++" 18function check_shell_environment() { 19 case $(uname -s) in 20 Linux) 21 shell_result=$(/bin/sh -c 'echo ${BASH_VERSION}') 22 if [ -n "${shell_result}" ]; then 23 echo "The system shell is bash ${shell_result}" 24 else 25 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" 26 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" 27 fi 28 ;; 29 Darwin) 30 echo "Darwin system is not supported yet" 31 ;; 32 *) 33 echo "Unsupported this system: $(uname -s)" 34 exit 1 35 esac 36} 37 38check_shell_environment 39 40echo "++++++++++++++++++++++++++++++++++++++++" 41date +%F' '%H:%M:%S 42echo $@ 43 44function help() { 45 echo 46 echo "Usage:" 47 echo " ./build.sh --product-name {product-name} [options]" 48 echo 49 echo "Examples:" 50 echo " ./build.sh --product-name rk3568 --ccache" 51 echo 52 echo "options" 53 echo " --ccache use ccache, default: false" 54 echo " --jobs N run N jobs in parallel" 55 echo " --build-target build target name" 56 57 echo " --gn-args specifies gn build arguments, eg: --gn-args=\"foo=\"bar\" enable=true blah=7\"" 58 echo " --export-para export env" 59 echo " --help, -h print help info" 60 echo " --source-root-dir source root directory" 61 echo " --product-name build product name" 62 echo " --device-name build device name" 63 echo " --target-cpu select cpu" 64 echo " --target-os target os" 65 echo " --compile-config compile config" 66 echo " --ninja args ninja args" 67 echo " --verbose, -v show all command lines while building" 68 echo " --keep-ninja-going keeps ninja going until 1000000 jobs fail" 69 echo " --sparse-image sparse image, default: true" 70 echo " --build-only-gn only do gn parse, do not run ninja" 71 echo " --fast-rebuild it will skip prepare, preloader, gn_gen steps so we can enable it only" 72 echo " --log-level specifies the log level during compilation, three levels are optional: debug, info and error, default: info" 73 echo " --device-type specifies device type" 74 echo " --build-variant specifies device operating mode" 75 echo " --share-ccache it is customized path to place ccache, which allow one ccache shared with many project" 76 echo " --disable-post-build it will skip post build process, you can enable it if you do not need post build. Post build include post_build.patch_ohos_para, 77 post_build.package_image(), stat_ccache(), generate_ninja_trace(start_time), get_warning_list(), compute_overlap_rate()" 78 echo " --disable-package-image it will skip compress image process, you can enable it if you do not need compress image" 79 exit 1 80} 81 82export source_root_dir=$(cd $(dirname $0);pwd) 83 84while [[ ! -f "${source_root_dir}/.gn" ]]; do 85 source_root_dir="$(dirname "${source_root_dir}")" 86 if [[ "${source_root_dir}" == "/" ]]; then 87 echo "Cannot find source tree containing $(pwd)" 88 exit 1 89 fi 90done 91 92if [[ "${source_root_dir}x" == "x" ]]; then 93 echo "Error: source_root_dir cannot be empty." 94 exit 1 95fi 96 97case $(uname -s) in 98 Darwin) 99 HOST_DIR="darwin-x86" 100 HOST_OS="mac" 101 ;; 102 Linux) 103 HOST_DIR="linux-x86" 104 HOST_OS="linux" 105 ;; 106 *) 107 echo "Unsupported host platform: $(uname -s)" 108 RET=1 109 exit $RET 110esac 111 112# set python3 113PYTHON3_DIR=${source_root_dir}/prebuilts/python/${HOST_DIR}/3.9.2/ 114PYTHON3=${PYTHON3_DIR}/bin/python3 115PYTHON=${PYTHON3_DIR}/bin/python 116if [[ ! -f "${PYTHON3}" ]]; then 117 echo -e "\033[33m Please execute the build/prebuilts_download.sh \033[0m" 118 exit 1 119else 120 if [[ ! -f "${PYTHON}" ]]; then 121 ln -sf "${PYTHON3}" "${PYTHON}" 122 fi 123fi 124 125export PATH=${source_root_dir}/prebuilts/build-tools/${HOST_DIR}/bin:${PYTHON3_DIR}/bin:$PATH 126 127${PYTHON3} ${source_root_dir}/build/scripts/tools_checker.py 128 129${PYTHON3} ${source_root_dir}/build/scripts/entry.py --source-root-dir ${source_root_dir} $@ 130 131if [[ "$?" -ne 0 ]]; then 132 echo -e "\033[31m=====build ${product_name} error=====\033[0m" 133 exit 1 134fi 135echo -e "\033[32m=====build ${product_name} successful=====\033[0m" 136 137date +%F' '%H:%M:%S 138echo "++++++++++++++++++++++++++++++++++++++++" 139