• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (c) 2024 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
15cleanup(){
16    rm -rf .gn
17    ln -s build/core/gn/dotfile.gn .gn
18}
19
20trap cleanup EXIT
21
22set -e
23echo $1 $2 $3
24TEST_FILTER=$3
25VARIANTS="default"
26if [ -n "$4" ]; then
27  VARIANTS=$4
28fi
29
30case $3 in
31    0) OUT_DIR="src" ;;
32    1) OUT_DIR="src_test" ;;
33    2) OUT_DIR="test" ;;
34esac
35
36export SOURCE_ROOT_DIR="$PWD"
37
38# set python3
39HOST_DIR="linux-x86"
40HOST_OS="linux"
41NODE_PLATFORM="linux-x64"
42
43PYTHON3_DIR=$(realpath ${SOURCE_ROOT_DIR}/prebuilts/python/${HOST_DIR}/*/ | tail -1)
44PYTHON3=${PYTHON3_DIR}/bin/python3
45PYTHON=${PYTHON3_DIR}/bin/python
46export PATH=${SOURCE_ROOT_DIR}/prebuilts/build-tools/${HOST_DIR}/bin:${PYTHON3_DIR}/bin:$PATH
47
48
49if [[ "$@" =~ "--fast-rebuild" ]]; then
50    rm -rf .gn
51    ln -s build/indep_configs/dotfile.gn .gn
52    ${PYTHON3} ${SOURCE_ROOT_DIR}/build/indep_configs/scripts/gn_ninja_cmd.py -rp ${SOURCE_ROOT_DIR} -v ${VARIANTS} -out ${OUT_DIR} -t ${TEST_FILTER} --fast-rebuild
53    if [ $? -ne 0 ]; then
54        exit 1
55    fi
56    rm -rf .gn
57    ln -s build/core/gn/dotfile.gn .gn
58    exit 0
59fi
60
61mkdir -p out/preloader
62mkdir -p out/$VARIANTS/$OUT_DIR/
63
64rm -rf out/preloader/$VARIANTS
65rm -rf .gn
66mkdir -p out/preloader/$VARIANTS
67echo {} > out/preloader/$VARIANTS/hvigor_compile_hap_whitelist.json
68mkdir -p out/$VARIANTS/$OUT_DIR/build_configs/parts_info
69cp -rf build/indep_configs/mapping/component_mapping.json out/$VARIANTS/$OUT_DIR/build_configs
70ln -s build/indep_configs/dotfile.gn .gn
71
72${PYTHON3} ${SOURCE_ROOT_DIR}/build/indep_configs/scripts/generate_components.py -hp $1 -sp $2 -v ${VARIANTS} -rp ${SOURCE_ROOT_DIR} -t ${TEST_FILTER} -out ${OUT_DIR}
73
74if [ -d "binarys/third_party/rust/crates" ];then
75    echo "rust directory exists"
76    if [ ! -d "third_party/rust/crates" ]; then
77        echo "third_party/rust/crates not exist, copy from binarys."
78        mkdir -p "third_party/rust"
79        cp -r binarys/third_party/rust/crates third_party/rust
80    fi
81fi
82
83if [ -d "binarys/test/testfwk/developer_test" ];then
84    echo "developer_test directory exists"
85    if [ ! -d "test/testfwk/developer_test" ]; then
86        echo "test/testfwk/developer_test not exist, copy from binarys."
87        mkdir -p "test/testfwk"
88        cp -r binarys/test/testfwk/developer_test test/testfwk
89    fi
90fi
91
92if [ -d "binarys/third_party/typescript" ];then
93    echo "typescript directory exists"
94    if [ ! -d "third_party/typescript" ]; then
95        echo "third_party/typescript not exist, copy from binarys."
96        mkdir -p  "third_party"
97        cp -r binarys/third_party/typescript third_party
98    fi
99fi
100${PYTHON3} ${SOURCE_ROOT_DIR}/build/indep_configs/scripts/generate_target_build_gn.py -p $2 -rp ${SOURCE_ROOT_DIR} -t ${TEST_FILTER}
101${PYTHON3} ${SOURCE_ROOT_DIR}/build/indep_configs/scripts/variants_info_handler.py -rp ${SOURCE_ROOT_DIR} -v ${VARIANTS}
102# gn and ninja command
103${PYTHON3} ${SOURCE_ROOT_DIR}/build/indep_configs/scripts/gn_ninja_cmd.py -rp ${SOURCE_ROOT_DIR} -v ${VARIANTS} -out ${OUT_DIR} -t ${TEST_FILTER}
104
105if [ $? -ne 0 ]; then
106  exit 1
107fi
108
109echo -e "\033[0;33myou can use --skip-download to skip download binary dependencies while using hb build command\033[0m"
110exit 0
111