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     acts, hats, dcts"
23    echo "                  target_arch      : TARGET_ARCH      arm64 or arm, default value is arm"
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"
27    echo "                  product_name     : PRODUCT_NAME     the name of product. such as 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_TOOLS_DIR=${BASE_HOME}/prebuilts/build-tools/linux-x86/bin
36    OUT_DIR=${BASE_HOME}/out
37    BUILD_SHELL=${BASE_HOME}/build.sh
38    # build all parts for all products by default
39    BUILD_TARGET=""
40    GN_ARGS="is_dbt_test=true include_all=false"
41    TARGET_ARCH=arm
42    BUILD_VARIANT=release
43    UPLOAD_API_INFO=False
44    SYSTEM_SIZE=standard
45    PRODUCT_NAME=""
46    PR_PARTH_LIST=""
47    USE_MUSL=false
48    export PATH=${BASE_HOME}/prebuilts/python/linux-x86/3.8.3/bin:$PATH
49
50
51    system_build_params="build_xts=true"
52
53    while [ -n "$1" ]; do
54        var="$1"
55        OPTIONS=${var%%=*}
56        PARAM=${var#*=}
57        echo "OPTIONS=$OPTIONS"
58        echo "PARAM=$PARAM"
59        echo "-------------------"
60        case "$OPTIONS" in
61        suite)            BUILD_TARGET="$PARAM"
62                          ;;
63        target_arch)      TARGET_ARCH="$PARAM"
64                          ;;
65        variant)          BUILD_VARIANT="$PARAM"
66                          ;;
67        use_musl)         USE_MUSL="$PARAM"
68                          ;;
69        target_subsystem) export target_subsystem=${PARAM}
70                          ;;
71        system_size)      SYSTEM_SIZE="$PARAM"
72                          ;;
73        product_name)     PRODUCT_NAME="$PARAM"
74                          ;;
75        pr_path_list)     PR_PARTH_LIST="$PARAM"
76                          ;;
77        upload_api_info)  UPLOAD_API_INFO=$(echo $PARAM |tr [a-z] [A-Z])
78                          ;;
79        cache_type)       CACHE_TYPE="$PARAM"
80                          ;;
81        *)   usage
82             break;;
83        esac
84        shift
85    done
86    if [ "$SYSTEM_SIZE" = "standard" ]; then
87        BUILD_TARGET=${BUILD_TARGET:-"test/xts/acts:xts_acts"}
88        PRODUCT_NAME=${PRODUCT_NAME:-"Hi3516DV300"}
89    else
90        BUILD_TARGET=${BUILD_TARGET:-"acts acts_ivi acts_intellitv acts_wearable"}
91        PRODUCT_NAME=${PRODUCT_NAME:-"arm64"}
92    fi
93}
94
95do_make() {
96    BUILD_TARGET=$(echo "$BUILD_TARGET" | sed 's/,/ /g')
97    echo "BUILD_TARGET: $BUILD_TARGET"
98    cd $BASE_HOME
99    ACTS_ROOT="$BASE_HOME/test/xts/acts"
100
101    ${BASE_HOME}/prebuilts/python/linux-x86/current/bin/python3 -B ${ACTS_ROOT}/check_hvigor.py
102    if [ "$?" != 0 ]; then
103        exit 1
104    fi
105
106    rm -rf "$BASE_HOME/test/xts/autogen_apiobjs"
107    export XTS_SUITENAME=acts
108    if [ "$SYSTEM_SIZE" = "standard" ]; then
109        MUSL_ARGS=""
110        if [ "$PRODUCT_NAME" = "m40" ]; then
111            if [ "$USE_MUSL" = "false" ]; then
112                MUSL_ARGS="--gn-args use_musl=false --gn-args use_custom_libcxx=true --gn-args use_custom_clang=true"
113            fi
114        fi
115        CACHE_ARG=""
116    
117        if [ "$CACHE_TYPE" == "xcache" ];then
118            CACHE_ARG="--ccache false --xcache true"
119        fi
120        if [ "$PR_PARTH_LIST" != "" ]; then
121            system_build_params+=" pr_path_list=$PR_PARTH_LIST"
122        fi
123        ./build.sh --product-name $PRODUCT_NAME --gn-args $system_build_params --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 $CACHE_ARG --gn-args skip_generate_module_list_file=true
124    else
125       if [ "$BUILD_TARGET" = "acts acts_ivi acts_intellitv acts_wearable" ]; then
126         ./build.sh --product-name $PRODUCT_NAME --gn-args $system_build_params --build-target "acts" --build-target "acts_ivi" --build-target "acts_intellitv" --build-target "acts_wearable" --build-target "deploy_testtools"
127       else
128         ./build.sh --product-name $PRODUCT_NAME --gn-args $system_build_params --build-target $BUILD_TARGET --build-target "deploy_testtools"
129       fi
130    fi
131    ret=$?
132
133    rm -rf "$BASE_HOME/test/xts/autogen_apiobjs"
134    if [ "$ret" != 0 ]; then
135        echo "build error"
136        exit 1
137    fi
138}
139parse_cmdline $@
140do_make
141exit 0