19762338dSopenharmony_ci#!/bin/bash
29762338dSopenharmony_ci
39762338dSopenharmony_ci# Copyright (C) 2021 Huawei Device Co., Ltd.
49762338dSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
59762338dSopenharmony_ci# you may not use this file except in compliance with the License.
69762338dSopenharmony_ci# You may obtain a copy of the License at
79762338dSopenharmony_ci#
89762338dSopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
99762338dSopenharmony_ci#
109762338dSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
119762338dSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
129762338dSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139762338dSopenharmony_ci# See the License for the specific language governing permissions and
149762338dSopenharmony_ci# limitations under the License.
159762338dSopenharmony_ci
169762338dSopenharmony_ciset -e
179762338dSopenharmony_ci
189762338dSopenharmony_ciusage() {
199762338dSopenharmony_ci    echo
209762338dSopenharmony_ci    echo "USAGE"
219762338dSopenharmony_ci    echo "       ./build.sh [suite=BUILD_TARGET] [target_os=TARGET_OS] [target_arch=TARGET_ARCH] [variant=BUILD_VARIANT] [target_subsystem=TARGET_SUBSYSTEM]"
229762338dSopenharmony_ci    echo "                  suite            : BUILD_TARGET       cts/hit/vts and so on, default value is hit"
239762338dSopenharmony_ci    echo "                  target_arch      : TARGET_ARCH      arm64 or arm32, default value is arm64"
249762338dSopenharmony_ci    echo "                  variant          : BUILD_VARIANT    release or debug, default value is debug"
259762338dSopenharmony_ci    echo "                  target_subsystem : TARGET_SUBSYSTEM the target subsystem to build"
269762338dSopenharmony_ci    echo "                  system_size      : SYSTEM_SIZE      standard, large and son on, large is for L3-L5, standard is for L2 default value is large"
279762338dSopenharmony_ci    echo "                  product_name     : PRODUCT_NAME     the name of product. such as hikey960, Hi3516DV300, and so on."
289762338dSopenharmony_ci    echo
299762338dSopenharmony_ci    exit 1
309762338dSopenharmony_ci}
319762338dSopenharmony_ci
329762338dSopenharmony_ciparse_cmdline() {
339762338dSopenharmony_ci    BASE_HOME=$(dirname $(cd $(dirname $0); pwd))
349762338dSopenharmony_ci    BASE_HOME=${BASE_HOME}/../..
359762338dSopenharmony_ci    # build all parts for all products by default
369762338dSopenharmony_ci    BUILD_TARGET=""
379762338dSopenharmony_ci    TARGET_PLATFORM=all
389762338dSopenharmony_ci    TARGET_ARCH=arm
399762338dSopenharmony_ci    BUILD_VARIANT=release
409762338dSopenharmony_ci    UPLOAD_API_INFO=False
419762338dSopenharmony_ci    SYSTEM_SIZE=standard
429762338dSopenharmony_ci    PRODUCT_NAME=""
439762338dSopenharmony_ci    USE_MUSL=false
449762338dSopenharmony_ci    export PATH=${BASE_HOME}/prebuilts/python/linux-x86/3.8.3/bin:$PATH
459762338dSopenharmony_ci
469762338dSopenharmony_ci    while [ -n "$1" ]; do
479762338dSopenharmony_ci        var="$1"
489762338dSopenharmony_ci        OPTIONS=${var%%=*}
499762338dSopenharmony_ci        PARAM=${var#*=}
509762338dSopenharmony_ci        echo "OPTIONS=$OPTIONS, PARAM=$PARAM"
519762338dSopenharmony_ci        case "$OPTIONS" in
529762338dSopenharmony_ci        suite)            BUILD_TARGET="$PARAM"
539762338dSopenharmony_ci                          ;;
549762338dSopenharmony_ci        target_arch)      TARGET_ARCH="$PARAM"
559762338dSopenharmony_ci                          ;;
569762338dSopenharmony_ci        variant)          BUILD_VARIANT="$PARAM"
579762338dSopenharmony_ci                          ;; 
589762338dSopenharmony_ci        use_musl)         USE_MUSL="$PARAM"
599762338dSopenharmony_ci                          ;;
609762338dSopenharmony_ci	    target_platform)  TARGET_PLATFORM="$PARAM"
619762338dSopenharmony_ci                          ;;
629762338dSopenharmony_ci        target_subsystem) export target_subsystem=${PARAM}
639762338dSopenharmony_ci                          ;;
649762338dSopenharmony_ci        system_size)      SYSTEM_SIZE="$PARAM"
659762338dSopenharmony_ci                          ;;
669762338dSopenharmony_ci        product_name)     PRODUCT_NAME="$PARAM"
679762338dSopenharmony_ci                          ;;
689762338dSopenharmony_ci        upload_api_info)  UPLOAD_API_INFO=$(echo $PARAM | tr [a-z] [A-Z])
699762338dSopenharmony_ci                          ;;
709762338dSopenharmony_ci        cache_type)       CACHE_TYPE="$PARAM"
719762338dSopenharmony_ci                          ;;
729762338dSopenharmony_ci        *)
739762338dSopenharmony_ci            usage
749762338dSopenharmony_ci            break ;;
759762338dSopenharmony_ci        esac
769762338dSopenharmony_ci        shift
779762338dSopenharmony_ci    done
789762338dSopenharmony_ci    if [ "$SYSTEM_SIZE" = "standard" ]; then
799762338dSopenharmony_ci        BUILD_TARGET=${BUILD_TARGET:-"test/xts/hats:xts_hats"}
809762338dSopenharmony_ci        PRODUCT_NAME=${PRODUCT_NAME:-"Hi3516DV300"}
819762338dSopenharmony_ci    else
829762338dSopenharmony_ci        BUILD_TARGET=${BUILD_TARGET:-"hats hats_ivi hats_intellitv hats_wearable"}
839762338dSopenharmony_ci        PRODUCT_NAME=${PRODUCT_NAME:-"arm64"}
849762338dSopenharmony_ci    fi
859762338dSopenharmony_ci}
869762338dSopenharmony_ci
879762338dSopenharmony_cido_make() {
889762338dSopenharmony_ci    cd $BASE_HOME
899762338dSopenharmony_ci    HATS_ROOT="$BASE_HOME/test/xts/hats"
909762338dSopenharmony_ci
919762338dSopenharmony_ci    ${BASE_HOME}/prebuilts/python/linux-x86/current/bin/python3 -B ${HATS_ROOT}/check_hvigor.py
929762338dSopenharmony_ci    if [ "$?" != 0 ]; then
939762338dSopenharmony_ci        exit 1
949762338dSopenharmony_ci    fi
959762338dSopenharmony_ci
969762338dSopenharmony_ci    rm -rf "$BASE_HOME/test/xts/autogen_apiobjs"
979762338dSopenharmony_ci    export XTS_SUITENAME=hats
989762338dSopenharmony_ci    if [ "$SYSTEM_SIZE" = "standard" ]; then
999762338dSopenharmony_ci        MUSL_ARGS=""
1009762338dSopenharmony_ci        if [ "$PRODUCT_NAME" = "m40" ]; then
1019762338dSopenharmony_ci            if [ "$USE_MUSL" = "false" ]; then
1029762338dSopenharmony_ci                MUSL_ARGS="--gn-args use_musl=false --gn-args use_custom_libcxx=true --gn-args use_custom_clang=true"
1039762338dSopenharmony_ci            fi
1049762338dSopenharmony_ci        fi
1059762338dSopenharmony_ci        CACHE_ARG=""
1069762338dSopenharmony_ci        if [ "$CACHE_TYPE" == "xcache" ]; then
1079762338dSopenharmony_ci            CACHE_ARG="--ccache false --xcache true"
1089762338dSopenharmony_ci        fi
1099762338dSopenharmony_ci        ./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
1109762338dSopenharmony_ci    else
1119762338dSopenharmony_ci        if [ "$BUILD_TARGET" = "hats hats_ivi hats_intellitv hats_wearable" ]; then
1129762338dSopenharmony_ci            ./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"
1139762338dSopenharmony_ci        else
1149762338dSopenharmony_ci            ./build.sh --product-name $PRODUCT_NAME --gn-args build_xts=true --build-target $BUILD_TARGET --build-target "deploy_testtools"
1159762338dSopenharmony_ci        fi
1169762338dSopenharmony_ci    fi
1179762338dSopenharmony_ci    ret=$?
1189762338dSopenharmony_ci
1199762338dSopenharmony_ci    rm -rf "$BASE_HOME/test/xts/autogen_apiobjs"
1209762338dSopenharmony_ci    if [ "$ret" != 0 ]; then
1219762338dSopenharmony_ci        echo "build error"
1229762338dSopenharmony_ci        exit 1
1239762338dSopenharmony_ci    fi
1249762338dSopenharmony_ci}
1259762338dSopenharmony_ciparse_cmdline $@
1269762338dSopenharmony_cido_make
1279762338dSopenharmony_ciexit 0
128