15f9996aaSopenharmony_ci#!/bin/bash
25f9996aaSopenharmony_ci# Copyright (c) 2024 Huawei Device Co., Ltd.
35f9996aaSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
45f9996aaSopenharmony_ci# you may not use this file except in compliance with the License.
55f9996aaSopenharmony_ci# You may obtain a copy of the License at
65f9996aaSopenharmony_ci#
75f9996aaSopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
85f9996aaSopenharmony_ci#
95f9996aaSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
105f9996aaSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
115f9996aaSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125f9996aaSopenharmony_ci# See the License for the specific language governing permissions and
135f9996aaSopenharmony_ci# limitations under the License.
145f9996aaSopenharmony_ci
155f9996aaSopenharmony_ciset -e
165f9996aaSopenharmony_ciecho $1 $2 $3
175f9996aaSopenharmony_ciTEST_FILTER=$3
185f9996aaSopenharmony_ciVARIANTS="default"
195f9996aaSopenharmony_ciif [ -n "$4" ]; then
205f9996aaSopenharmony_ci  VARIANTS=$4
215f9996aaSopenharmony_cifi
225f9996aaSopenharmony_ci# keep the logs of hpm
235f9996aaSopenharmony_cifind out/$VARIANTS -type f -not -name '*.log' -delete
245f9996aaSopenharmony_cirm -rf out/preloader/$VARIANTS
255f9996aaSopenharmony_cirm -rf .gn
265f9996aaSopenharmony_ci
275f9996aaSopenharmony_cimkdir -p out/preloader
285f9996aaSopenharmony_cimkdir -p out/$VARIANTS/build_configs/parts_info
295f9996aaSopenharmony_cicp -rf build/indep_configs/mapping/component_mapping.json out/$VARIANTS/build_configs
305f9996aaSopenharmony_ciln -s build/indep_configs/dotfile.gn .gn
315f9996aaSopenharmony_ci
325f9996aaSopenharmony_ciexport SOURCE_ROOT_DIR="$PWD"
335f9996aaSopenharmony_ci
345f9996aaSopenharmony_ci# set python3
355f9996aaSopenharmony_ciHOST_DIR="linux-x86"
365f9996aaSopenharmony_ciHOST_OS="linux"
375f9996aaSopenharmony_ciNODE_PLATFORM="linux-x64"
385f9996aaSopenharmony_ci
395f9996aaSopenharmony_ciPYTHON3_DIR=$(realpath ${SOURCE_ROOT_DIR}/prebuilts/python/${HOST_DIR}/*/ | tail -1)
405f9996aaSopenharmony_ciPYTHON3=${PYTHON3_DIR}/bin/python3
415f9996aaSopenharmony_ciPYTHON=${PYTHON3_DIR}/bin/python
425f9996aaSopenharmony_ciexport PATH=${SOURCE_ROOT_DIR}/prebuilts/build-tools/${HOST_DIR}/bin:${PYTHON3_DIR}/bin:$PATH
435f9996aaSopenharmony_ci
445f9996aaSopenharmony_ci${PYTHON3} ${SOURCE_ROOT_DIR}/build/indep_configs/scripts/generate_components.py -hp $1 -sp $2 -v ${VARIANTS} -rp ${SOURCE_ROOT_DIR} -t ${TEST_FILTER}
455f9996aaSopenharmony_ciif [ -d "binarys/third_party/rust" ];then
465f9996aaSopenharmony_ci    echo "rust directory exists"
475f9996aaSopenharmony_ci    if [ -d "third_party/rust" ]; then
485f9996aaSopenharmony_ci        echo "third_party/rust exists"
495f9996aaSopenharmony_ci        cp -r binarys/third_party/rust/crates third_party/rust
505f9996aaSopenharmony_ci    else
515f9996aaSopenharmony_ci        mkdir -p "third_party/rust"
525f9996aaSopenharmony_ci        cp -r binarys/third_party/rust/crates third_party/rust
535f9996aaSopenharmony_ci    fi
545f9996aaSopenharmony_cielse
555f9996aaSopenharmony_ci    echo "rust directory exists"
565f9996aaSopenharmony_cifi
575f9996aaSopenharmony_ci${PYTHON3} ${SOURCE_ROOT_DIR}/build/indep_configs/scripts/generate_target_build_gn.py -p $2 -rp ${SOURCE_ROOT_DIR} -t ${TEST_FILTER}
585f9996aaSopenharmony_ci${PYTHON3} ${SOURCE_ROOT_DIR}/build/indep_configs/scripts/variants_info_handler.py -rp ${SOURCE_ROOT_DIR} -v ${VARIANTS}
595f9996aaSopenharmony_ci# gn and ninja command
605f9996aaSopenharmony_ci${PYTHON3} ${SOURCE_ROOT_DIR}/build/indep_configs/scripts/gn_ninja_cmd.py -rp ${SOURCE_ROOT_DIR} -v ${VARIANTS}
615f9996aaSopenharmony_ci
625f9996aaSopenharmony_ciif [ $? -ne 0 ]; then
635f9996aaSopenharmony_ci  exit 1
645f9996aaSopenharmony_cifi
655f9996aaSopenharmony_ci
665f9996aaSopenharmony_cirm -rf .gn
675f9996aaSopenharmony_ciln -s build/core/gn/dotfile.gn .gn
685f9996aaSopenharmony_ci
695f9996aaSopenharmony_ciexit 0
70