1f6603c60Sopenharmony_ci#!/bin/bash
2f6603c60Sopenharmony_ci
3f6603c60Sopenharmony_ci# Copyright (C) 2021 Huawei Device Co., Ltd.
4f6603c60Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
5f6603c60Sopenharmony_ci# you may not use this file except in compliance with the License.
6f6603c60Sopenharmony_ci# You may obtain a copy of the License at
7f6603c60Sopenharmony_ci#
8f6603c60Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
9f6603c60Sopenharmony_ci#
10f6603c60Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
11f6603c60Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
12f6603c60Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f6603c60Sopenharmony_ci# See the License for the specific language governing permissions and
14f6603c60Sopenharmony_ci# limitations under the License.
15f6603c60Sopenharmony_ci
16f6603c60Sopenharmony_ciset -e
17f6603c60Sopenharmony_ci
18f6603c60Sopenharmony_ciparse_target_subsystem()
19f6603c60Sopenharmony_ci{
20f6603c60Sopenharmony_ci    XTS_HOME=$(dirname $(cd $(dirname $0); pwd))
21f6603c60Sopenharmony_ci    BASE_HOME=${XTS_HOME}/../..
22f6603c60Sopenharmony_ci    target_subsystem_config=${XTS_HOME}/tools/config/precise_compilation.json
23f6603c60Sopenharmony_ci    xts_enter_config=${BASE_HOME}/.repo/manifests/matrix_product.csv
24f6603c60Sopenharmony_ci    xts_targets=""
25f6603c60Sopenharmony_ci    repositorys=$1
26f6603c60Sopenharmony_ci    match_status=true
27f6603c60Sopenharmony_ci    repo_lst=($(echo $repositorys | tr "," "\n"))
28f6603c60Sopenharmony_ci    row=dayu200_xts
29f6603c60Sopenharmony_ci    row_number=$(awk -F',' -v target="$row" 'NR==1{for(i=1;i<=NF;i++){if($i==target){print i;exit}}}' "$xts_enter_config")
30f6603c60Sopenharmony_ci    for repo in "${repo_lst[@]}"
31f6603c60Sopenharmony_ci    do
32f6603c60Sopenharmony_ci        echo $repo
33f6603c60Sopenharmony_ci        # 是否配置xts门禁,若无,跳过
34f6603c60Sopenharmony_ci        line_number=$(awk -F',' -v target="$repo" '$1 == target {print NR}' "$xts_enter_config")
35f6603c60Sopenharmony_ci        content=$(awk -F',' -v c=$row_number  -v r=$line_number 'NR==r {print $c}' "$xts_enter_config")
36f6603c60Sopenharmony_ci        echo $content
37f6603c60Sopenharmony_ci        if [ ! "$content" = "Y" ]||[ -z "$content" ]; then
38f6603c60Sopenharmony_ci            continue
39f6603c60Sopenharmony_ci        fi
40f6603c60Sopenharmony_ci        # 仓名映射target名
41f6603c60Sopenharmony_ci        jq_cmd="cat $target_subsystem_config | jq -r '.[] | select( .name == \"${repo}\") | .buildTarget'"
42f6603c60Sopenharmony_ci        xts_target=$(eval $jq_cmd)
43f6603c60Sopenharmony_ci        if [[ -z "${xts_target}" ]];then
44f6603c60Sopenharmony_ci            match_status=false
45f6603c60Sopenharmony_ci        fi
46f6603c60Sopenharmony_ci        # precise_compilation.json匹配到的才添加,数组中不存在才添加(去重)
47f6603c60Sopenharmony_ci        if [[ -n "${xts_target}" && !("$xts_targets" =~ "$xts_target") ]];then
48f6603c60Sopenharmony_ci            xts_targets+="$xts_target,"
49f6603c60Sopenharmony_ci        fi
50f6603c60Sopenharmony_ci    done
51f6603c60Sopenharmony_ci        # 去掉末尾,
52f6603c60Sopenharmony_ci        xts_targets=$(echo "$xts_targets" | sed 's/,$//')
53f6603c60Sopenharmony_ci        echo "xts_targets: $xts_targets"
54f6603c60Sopenharmony_ci}
55f6603c60Sopenharmony_ci
56f6603c60Sopenharmony_cidefine_cache_type() {
57f6603c60Sopenharmony_ci    echo $CACHE_TYPE
58f6603c60Sopenharmony_ci}
59f6603c60Sopenharmony_cidefine_cache_type
60f6603c60Sopenharmony_ci
61f6603c60Sopenharmony_ciparse_args()
62f6603c60Sopenharmony_ci{   
63f6603c60Sopenharmony_ci    while [ -n "$1" ]
64f6603c60Sopenharmony_ci    do
65f6603c60Sopenharmony_ci        var="$1"
66f6603c60Sopenharmony_ci        OPTIONS=${var%%=*}
67f6603c60Sopenharmony_ci        PARAM=${var#*=}
68f6603c60Sopenharmony_ci        if [[ "$OPTIONS" == "cache_type" && "$PARAM" != "$OPTIONS" ]]; then
69f6603c60Sopenharmony_ci            CACHE_TYPE="$PARAM"
70f6603c60Sopenharmony_ci        fi
71f6603c60Sopenharmony_ci        shift
72f6603c60Sopenharmony_ci    done
73f6603c60Sopenharmony_ci}
74f6603c60Sopenharmony_ci
75f6603c60Sopenharmony_cipr_list=$1
76f6603c60Sopenharmony_cishift
77f6603c60Sopenharmony_ciremaining_params=$@
78f6603c60Sopenharmony_ci
79f6603c60Sopenharmony_cido_make()
80f6603c60Sopenharmony_ci{
81f6603c60Sopenharmony_ci    cd $BASE_HOME
82f6603c60Sopenharmony_ci    if [[ "${match_status}" == false || "$xts_targets" =~ "xts_acts" ]];then
83f6603c60Sopenharmony_ci        if [ -z "$CACHE_TYPE" ]; then
84f6603c60Sopenharmony_ci	        ./test/xts/acts/build.sh product_name=rk3568 system_size=standard $remaining_params
85f6603c60Sopenharmony_ci        else
86f6603c60Sopenharmony_ci            ./test/xts/acts/build.sh product_name=rk3568 system_size=standard $remaining_params cache_type=$CACHE_TYPE
87f6603c60Sopenharmony_ci        fi
88f6603c60Sopenharmony_ci    else
89f6603c60Sopenharmony_ci        if [ -z "$CACHE_TYPE" ]; then
90f6603c60Sopenharmony_ci            ./test/xts/acts/build.sh product_name=rk3568 system_size=standard suite=${xts_targets} $remaining_params
91f6603c60Sopenharmony_ci        else
92f6603c60Sopenharmony_ci            ./test/xts/acts/build.sh product_name=rk3568 system_size=standard suite=${xts_targets} $remaining_params cache_type=$CACHE_TYPE
93f6603c60Sopenharmony_ci        fi
94f6603c60Sopenharmony_ci    fi
95f6603c60Sopenharmony_ci}
96f6603c60Sopenharmony_ciecho $@
97f6603c60Sopenharmony_ciparse_target_subsystem $pr_list
98f6603c60Sopenharmony_ciif [ $# -eq 0 ];then
99f6603c60Sopenharmony_ci    echo "no args; pass cache deal"
100f6603c60Sopenharmony_cielse    
101f6603c60Sopenharmony_ci    parse_args $@
102f6603c60Sopenharmony_cifi
103f6603c60Sopenharmony_cido_make
104f6603c60Sopenharmony_ciexit 0
105