1#!/bin/bash
2
3# Copyright (C) 2021 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    echo
20    echo "USAGE"
21    echo "       ./build.sh [suite=BUILD_TARGET] [target_os=TARGET_OS] [target_arch=TARGET_ARCH] [variant=BUILD_VARIANT] [target_subsystem=TARGET_SUBSYSTEM]"
22    echo "                  suite            : BUILD_TARGET       cts/hit/vts and so on, default value is hit"
23    echo "                  target_arch      : TARGET_ARCH      arm64 or arm32, default value is arm64"
24    echo "                  variant          : BUILD_VARIANT    release or debug, default value is debug"
25    echo "                  target_subsystem : TARGET_SUBSYSTEM the target subsystem to build"
26    echo "                  system_size      : SYSTEM_SIZE      standard, large and son on, large is for L3-L5, standard is for L2 default value is large"
27    echo "                  product_name     : PRODUCT_NAME     the name of product. such as hikey960, Hi3516DV300, and so on."
28    echo
29    exit 1
30}
31
32parse_cmdline() {
33    BASE_HOME=$(dirname $(cd $(dirname $0); pwd))
34    BASE_HOME=${BASE_HOME}/../..
35    # build all parts for all products by default
36    BUILD_TARGET=""
37    TARGET_PLATFORM=all
38    TARGET_ARCH=arm
39    BUILD_VARIANT=release
40    UPLOAD_API_INFO=False
41    SYSTEM_SIZE=standard
42    PRODUCT_NAME=""
43    USE_MUSL=false
44    export PATH=${BASE_HOME}/prebuilts/python/linux-x86/3.8.3/bin:$PATH
45
46    while [ -n "$1" ]; do
47        var="$1"
48        OPTIONS=${var%%=*}
49        PARAM=${var#*=}
50        echo "OPTIONS=$OPTIONS, PARAM=$PARAM"
51        case "$OPTIONS" in
52        suite)            BUILD_TARGET="$PARAM"
53                          ;;
54        target_arch)      TARGET_ARCH="$PARAM"
55                          ;;
56        variant)          BUILD_VARIANT="$PARAM"
57                          ;; 
58        use_musl)         USE_MUSL="$PARAM"
59                          ;;
60	    target_platform)  TARGET_PLATFORM="$PARAM"
61                          ;;
62        target_subsystem) export target_subsystem=${PARAM}
63                          ;;
64        system_size)      SYSTEM_SIZE="$PARAM"
65                          ;;
66        product_name)     PRODUCT_NAME="$PARAM"
67                          ;;
68        upload_api_info)  UPLOAD_API_INFO=$(echo $PARAM | tr [a-z] [A-Z])
69                          ;;
70        cache_type)       CACHE_TYPE="$PARAM"
71                          ;;
72        *)
73            usage
74            break ;;
75        esac
76        shift
77    done
78    if [ "$SYSTEM_SIZE" = "standard" ]; then
79        BUILD_TARGET=${BUILD_TARGET:-"test/xts/hats:xts_hats"}
80        PRODUCT_NAME=${PRODUCT_NAME:-"Hi3516DV300"}
81    else
82        BUILD_TARGET=${BUILD_TARGET:-"hats hats_ivi hats_intellitv hats_wearable"}
83        PRODUCT_NAME=${PRODUCT_NAME:-"arm64"}
84    fi
85}
86
87do_make() {
88    cd $BASE_HOME
89    HATS_ROOT="$BASE_HOME/test/xts/hats"
90
91    ${BASE_HOME}/prebuilts/python/linux-x86/current/bin/python3 -B ${HATS_ROOT}/check_hvigor.py
92    if [ "$?" != 0 ]; then
93        exit 1
94    fi
95
96    rm -rf "$BASE_HOME/test/xts/autogen_apiobjs"
97    export XTS_SUITENAME=hats
98    if [ "$SYSTEM_SIZE" = "standard" ]; then
99        MUSL_ARGS=""
100        if [ "$PRODUCT_NAME" = "m40" ]; then
101            if [ "$USE_MUSL" = "false" ]; then
102                MUSL_ARGS="--gn-args use_musl=false --gn-args use_custom_libcxx=true --gn-args use_custom_clang=true"
103            fi
104        fi
105        CACHE_ARG=""
106        if [ "$CACHE_TYPE" == "xcache" ]; then
107            CACHE_ARG="--ccache false --xcache true"
108        fi
109        ./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
110    else
111        if [ "$BUILD_TARGET" = "hats hats_ivi hats_intellitv hats_wearable" ]; then
112            ./build.sh --product-name $PRODUCT_NAME --gn-args build_xts=true --build-target "hats" --build-target "hats_ivi" --build-target "hats_intellitv" --build-target "hats_wearable" --build-target "deploy_testtools"
113        else
114            ./build.sh --product-name $PRODUCT_NAME --gn-args build_xts=true --build-target $BUILD_TARGET --build-target "deploy_testtools"
115        fi
116    fi
117    ret=$?
118
119    rm -rf "$BASE_HOME/test/xts/autogen_apiobjs"
120    if [ "$ret" != 0 ]; then
121        echo "build error"
122        exit 1
123    fi
124}
125parse_cmdline $@
126do_make
127exit 0
128