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 15set -e 16echo $1 $2 $3 17TEST_FILTER=$3 18VARIANTS="default" 19if [ -n "$4" ]; then 20 VARIANTS=$4 21fi 22 23case $3 in 24 0) OUT_DIR="src" ;; 25 1) OUT_DIR="src_test" ;; 26 2) OUT_DIR="test" ;; 27esac 28 29mkdir -p out/preloader 30mkdir -p out/$VARIANTS/$OUT_DIR/ 31 32if [[ ! "$@" =~ "--keep-out" ]]; then 33 # keep the logs of hpm 34 find out/$VARIANTS -type f -not -name '*.log' -delete 35 find out/$VARIANTS -type d -empty -delete 36fi 37rm -rf out/preloader/$VARIANTS 38rm -rf .gn 39 40mkdir -p out/$VARIANTS/$OUT_DIR/build_configs/parts_info 41cp -rf build/indep_configs/mapping/component_mapping.json out/$VARIANTS/$OUT_DIR/build_configs 42ln -s build/indep_configs/dotfile.gn .gn 43 44export SOURCE_ROOT_DIR="$PWD" 45 46# set python3 47HOST_DIR="linux-x86" 48HOST_OS="linux" 49NODE_PLATFORM="linux-x64" 50 51PYTHON3_DIR=$(realpath ${SOURCE_ROOT_DIR}/prebuilts/python/${HOST_DIR}/*/ | tail -1) 52PYTHON3=${PYTHON3_DIR}/bin/python3 53PYTHON=${PYTHON3_DIR}/bin/python 54export PATH=${SOURCE_ROOT_DIR}/prebuilts/build-tools/${HOST_DIR}/bin:${PYTHON3_DIR}/bin:$PATH 55 56${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} 57 58 59if [ -d "binarys/third_party/rust/crates" ];then 60 echo "rust directory exists" 61 if [ ! -d "third_party/rust/crates" ]; then 62 echo "third_party/rust/crates not exist, copy from binarys." 63 mkdir -p "third_party/rust" 64 cp -r binarys/third_party/rust/crates third_party/rust 65 fi 66fi 67 68if [ -d "binarys/test/testfwk/developer_test" ];then 69 echo "developer_test directory exists" 70 if [ ! -d "test/testfwk/developer_test" ]; then 71 echo "test/testfwk/developer_test not exist, copy from binarys." 72 mkdir -p "test/testfwk" 73 cp -r binarys/test/testfwk/developer_test test/testfwk 74 fi 75fi 76 77if [ -d "binarys/third_party/typescript" ];then 78 echo "typescript directory exists" 79 if [ ! -d "third_party/typescript" ]; then 80 echo "third_party/typescript not exist, copy from binarys." 81 mkdir -p "third_party" 82 cp -r binarys/third_party/typescript third_party 83 fi 84fi 85${PYTHON3} ${SOURCE_ROOT_DIR}/build/indep_configs/scripts/generate_target_build_gn.py -p $2 -rp ${SOURCE_ROOT_DIR} -t ${TEST_FILTER} 86${PYTHON3} ${SOURCE_ROOT_DIR}/build/indep_configs/scripts/variants_info_handler.py -rp ${SOURCE_ROOT_DIR} -v ${VARIANTS} 87# gn and ninja command 88${PYTHON3} ${SOURCE_ROOT_DIR}/build/indep_configs/scripts/gn_ninja_cmd.py -rp ${SOURCE_ROOT_DIR} -v ${VARIANTS} -out ${OUT_DIR} -t ${TEST_FILTER} 89 90if [ $? -ne 0 ]; then 91 exit 1 92fi 93 94rm -rf .gn 95ln -s build/core/gn/dotfile.gn .gn 96 97exit 0 98