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 17 18echo "++++++++++++++++++++++++++++++++++++++++" 19date +%F' '%H:%M:%S 20echo $@ 21 22function help() { 23 echo 24 echo "Usage:" 25 echo " ./build.sh --product-name {product-name} [options]" 26 echo 27 echo "Examples:" 28 echo " ./build.sh --product-name Hi3516DV300 --ccache" 29 echo 30 echo "options" 31 echo " --ccache use ccache, default: false" 32 echo " --jobs N run N jobs in parallel" 33 echo " --build-target build target name" 34 35 echo " --gn-args gn args" 36 echo " --export-para export env" 37 echo " --help, -h print help info" 38 echo 39 exit 1 40} 41 42export source_root_dir=$(cd $(dirname $0);pwd) 43 44while [[ ! -f "${source_root_dir}/.gn" ]]; do 45 source_root_dir="$(dirname "${source_root_dir}")" 46 if [[ "${source_root_dir}" == "/" ]]; then 47 echo "Cannot find source tree containing $(pwd)" 48 exit 1 49 fi 50done 51 52if [[ "${source_root_dir}x" == "x" ]]; then 53 echo "Error: source_root_dir cannot be empty." 54 exit 1 55fi 56 57case $(uname -s) in 58 Darwin) 59 HOST_DIR="darwin-x86" 60 HOST_OS="mac" 61 ;; 62 Linux) 63 HOST_DIR="linux-x86" 64 HOST_OS="linux" 65 ;; 66 *) 67 echo "Unsupported host platform: $(uname -s)" 68 RET=1 69 exit $RET 70esac 71 72# set python3 73PYTHON3_DIR=${source_root_dir}/prebuilts/python/${HOST_DIR}/3.9.2/ 74PYTHON3=${PYTHON3_DIR}/bin/python3 75PYTHON=${PYTHON3_DIR}/bin/python 76if [[ ! -f "${PYTHON3}" ]]; then 77 echo -e "\033[33m Please execute the build/prebuilts_download.sh \033[0m" 78 exit 1 79else 80 if [[ ! -f "${PYTHON}" ]]; then 81 ln -s "${PYTHON3}" "${PYTHON}" 82 fi 83fi 84 85export PATH=${source_root_dir}/prebuilts/build-tools/${HOST_DIR}/bin:${PYTHON3_DIR}/bin:$PATH 86 87${PYTHON3} ${source_root_dir}/build/scripts/tools_checker.py 88 89${PYTHON3} ${source_root_dir}/build/scripts/entry.py --source-root-dir ${source_root_dir} $@ 90 91if [[ "$?" -ne 0 ]]; then 92 echo -e "\033[31m=====build ${product_name} error=====\033[0m" 93 exit 1 94fi 95echo -e "\033[32m=====build ${product_name} successful=====\033[0m" 96 97date +%F' '%H:%M:%S 98echo "++++++++++++++++++++++++++++++++++++++++" 99