1#!/bin/bash
2
3# Copyright (C) 2022 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16set -e
17
18usage()
19{
20    echo
21    echo "USAGE"
22    echo "       ./build.sh [suite=BUILD_TARGET] [target_os=TARGET_OS] [target_arch=TARGET_ARCH] [variant=BUILD_VARIANT] [target_subsystem=TARGET_SUBSYSTEM]"
23    echo "                  target_platform  : TARGET_PLATFORM  the target platform, such as phone or ivi; Default to phone"
24    echo "                  suite            : BUILD_TARGET       cts/hit/vts and so on, default value is hit"
25    echo "                  target_arch      : TARGET_ARCH      arm64 or arm32, default value is arm64"
26    echo "                  variant          : BUILD_VARIANT    release or debug. The default value is debug."
27    echo "                  target_subsystem : TARGET_SUBSYSTEM the target subsystem to build"
28    echo "                  system_size      : SYSTEM_SIZE      standard, large, and son on. Wherein,large is for L3-L5, and standard is for L2. The default value is large."
29    echo "                  product_name     : PRODUCT_NAME     product name,for example,hikey960,Hi3516DV300,and so on."
30    echo
31    exit 1
32}
33
34
35parse_cmdline()
36{
37    BASE_HOME=$(dirname $(cd $(dirname $0); pwd))
38    BASE_HOME=${BASE_HOME}/../..
39    BUILD_TOOLS_DIR=${BASE_HOME}/prebuilts/build-tools/linux-x86/bin
40    OUT_DIR=${BASE_HOME}/out
41    BUILD_SHELL=${BASE_HOME}/build.sh
42    # build all parts for all products by default
43    BUILD_TARGET=""
44    TARGET_PLATFORM=all
45    GN_ARGS="is_dbt_test=true include_all=false"
46    TARGET_ARCH=arm
47    BUILD_VARIANT=release
48    UPLOAD_API_INFO=False
49    SYSTEM_SIZE=large
50    PRODUCT_NAME=""
51    USE_MUSL=false
52    export PATH=${BASE_HOME}/prebuilts/python/linux-x86/3.8.3/bin:$PATH
53
54    while [ -n "$1" ]
55    do
56        var="$1"
57        OPTIONS=${var%%=*}
58        PARAM=${var#*=}
59        echo "OPTIONS=$OPTIONS"
60        echo "PARAM=$PARAM"
61        echo "-------------------"
62        case "$OPTIONS" in
63        suite)            BUILD_TARGET="$PARAM"
64                          ;;
65        target_arch)      TARGET_ARCH="$PARAM"
66                          ;;
67        variant)          BUILD_VARIANT="$PARAM"
68                          ;;
69	    target_platform)  TARGET_PLATFORM="$PARAM"
70                          ;;
71        use_musl)         USE_MUSL="$PARAM"
72                          ;;                         
73        target_subsystem) export target_subsystem=${PARAM}
74                          ;;
75        system_size)      SYSTEM_SIZE="$PARAM"
76                          ;;
77        product_name)     PRODUCT_NAME="$PARAM"
78                          ;;
79        upload_api_info)  UPLOAD_API_INFO=$(echo $PARAM |tr [a-z] [A-Z])
80                          ;;
81        cache_type)       CACHE_TYPE="$PARAM"
82                          ;;
83        *)   usage
84             break;;
85        esac
86        shift
87    done
88    if [ "$SYSTEM_SIZE" = "standard" ]; then
89       BUILD_TARGET=${BUILD_TARGET:-"test/xts/dcts:xts_dcts"}
90       PRODUCT_NAME=${PRODUCT_NAME:-"Hi3516DV300"}
91    else
92       BUILD_TARGET=${BUILD_TARGET:-"dcts dcts_ivi dcts_intellitv dcts_wearable"}
93       PRODUCT_NAME=${PRODUCT_NAME:-"arm64"}
94    fi
95}
96
97
98do_make()
99{
100    cd $BASE_HOME
101    HATS_ROOT="$BASE_HOME/test/xts/dcts"
102
103    rm -rf "$BASE_HOME/test/xts/autogen_apiobjs"
104    export XTS_SUITENAME=dcts
105    if [ "$SYSTEM_SIZE" = "standard" ]; then
106        MUSL_ARGS=""
107        if [ "$PRODUCT_NAME" = "m40" ]; then
108            if [ "$USE_MUSL" = "false" ]; then
109                        MUSL_ARGS="--gn-args use_musl=false --gn-args use_custom_libcxx=true --gn-args use_custom_clang=true"			
110		    fi
111        fi
112	CACHE_ARG=""
113	if [ "$CACHE_TYPE" == "xcache" ];then
114            CACHE_ARG="--ccache false --xcache true"
115        fi
116       ./build.sh --product-name $PRODUCT_NAME --gn-args build_xts=true --build-target $BUILD_TARGET --build-target "deploy_testtools" --gn-args is_standard_system=true $MUSL_ARGS --target-cpu $TARGET_ARCH --get-warning-list=false --stat-ccache=true --compute-overlap-rate=false --deps-guard=false --generate-ninja-trace=false  $CACHE_ARG --gn-args skip_generate_module_list_file=true
117    else
118       if [ "$BUILD_TARGET" = "dcts dcts_ivi dcts_intellitv dcts_wearable" ]; then
119         ./build.sh --product-name $PRODUCT_NAME --gn-args build_xts=true --build-target "dcts" --build-target "dcts_ivi" --build-target "dcts_intellitv" --build-target "dcts_wearable" --build-target "deploy_testtools"
120       else
121         ./build.sh --product-name $PRODUCT_NAME --gn-args build_xts=true --build-target $BUILD_TARGET --build-target "deploy_testtools"
122       fi
123    fi
124    ret=$?
125
126    rm -rf "$BASE_HOME/test/xts/autogen_apiobjs"
127    if [ "$ret" != 0 ]; then
128        echo "build error"
129        exit 1
130    fi
131}
132parse_cmdline $@
133do_make
134exit 0
135