• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16
17echo "++++++++++++++++++++++++++++++++++++++++"
18date +%F' '%H:%M:%S
19echo $@
20
21function help() {
22  echo
23  echo "Usage:"
24  echo "  ./build.sh --product-name {product-name} [options]"
25  echo
26  echo "Examples:"
27  echo "  ./build.sh --product-name Hi3516DV300 --ccache"
28  echo
29  echo "options"
30  echo "  --ccache          use ccache, default: false"
31  echo "  --jobs N          run N jobs in parallel"
32  echo "  --build-target    build target name"
33
34  echo "  --gn-args         gn args"
35  echo "  --export-para     export env"
36  echo "  --help, -h        print help info"
37  echo
38  exit 1
39}
40
41
42script_path=$(cd $(dirname $0);pwd)
43
44source_root_dir="${script_path}"
45while [[ ! -f "${source_root_dir}/.gn" ]]; do
46    source_root_dir="$(dirname "${source_root_dir}")"
47    if [[ "${source_root_dir}" == "/" ]]; then
48        echo "Cannot find source tree containing $(pwd)"
49        exit 1
50    fi
51done
52
53build_params=""
54
55while test $# -gt 0
56do
57  case "$1" in
58  --product-name)
59    shift
60    product_name="$1"
61    ;;
62  --help | -h)
63    help
64    exit 0
65    ;;
66  *)
67    build_params+=" $1"
68    ;;
69  esac
70  shift
71done
72
73
74if [[ "${source_root_dir}x" == "x" ]]; then
75  echo "Error: source_root_dir cannot be empty."
76  exit 1
77fi
78if [[ ! -d "${source_root_dir}" ]]; then
79  echo "Error: source_root_dir is incorrect."
80  exit 1
81fi
82if [[ "${product_name}x" == "x" ]]; then
83  echo -e "\033[31mError: the product name should be specified!\033[0m"
84  help
85  exit 1
86fi
87
88
89case $(uname -s) in
90    Darwin)
91        HOST_DIR="darwin-x86"
92        HOST_OS="mac"
93        ;;
94    Linux)
95        HOST_DIR="linux-x86"
96        HOST_OS="linux"
97        ;;
98    *)
99        echo "Unsupported host platform: $(uname -s)"
100        RET=1
101        exit $RET
102esac
103
104# set python3
105PYTHON3=${source_root_dir}/prebuilts/python/${HOST_DIR}/3.8.5/bin/python3
106
107if [[ ! -f "${PYTHON3}" ]]; then
108  echo -e "\033[33m Please execute the build/prebuilts_download.sh \033[0m"
109  exit 1
110fi
111
112${PYTHON3} ${source_root_dir}/build/scripts/tools_checker.py
113
114export OHOS_ROOT_PATH="${source_root_dir}"
115export PYTHON3="${PYTHON3}"
116export USE_OHOS_INIT=true
117export BUILD_IMAGE=true
118
119cd ${source_root_dir}
120
121# preloader
122${PYTHON3} ${source_root_dir}/build/loader/preloader/preloader.py \
123  --product-name ${product_name} \
124  --source-root-dir ${source_root_dir} \
125  --products-config-dir "productdefine/common/products" \
126  --preloader-output-root-dir "out/build_configs"
127
128source ${source_root_dir}/out/build_configs/${product_name}/preloader/build.prop
129
130# call build
131${source_root_dir}/build/build_scripts/build_${system_type}.sh \
132  --product-name ${product_name} \
133  --device-name ${device_name} \
134  --target-os ${target_os} \
135  --target-cpu ${target_cpu} \
136  ${build_params}
137
138if [[ "${PIPESTATUS[0]}" -ne 0 ]]; then
139    echo -e "\033[31m=====build ${product_name} error.\033[0m"
140    exit 1
141fi
142echo -e "\033[32m=====build ${product_name} successful.\033[0m"
143
144date +%F' '%H:%M:%S
145echo "++++++++++++++++++++++++++++++++++++++++"
146