1#!/bin/bash 2# Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15set -e 16source $BASE_HOME/test/xts/tools/lite/buildUtils.sh 17usage() 18{ 19 echo 20 echo "USAGE" 21 echo " ./build.sh product=PRODUCT [platform=PLATFORM] [target=TARGET] xts=XTS" 22 echo 23 echo " product : PRODUCT product name, such as ipcamera or wifiiot" 24 echo " platform : PLATFORM the platform of device" 25 echo " target : TARGET the target for build, such as //xts/acts/communication_lite/wifiaware_test." 26 echo " xts : XTS the name of xts, such as acts/hits etc." 27 echo 28 exit 1 29} 30 31check_python() 32{ 33 python_cmd="" 34 ver=$(python -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major);') 35 if [ "$ver" = "3" ];then 36 python_cmd=python 37 else 38 ver=$(python3 -c 'import platform; major, minor, patch = platform.python_version_tuple(); print(major);') 39 if [ "$ver" = "3" ];then 40 python_cmd=python3 41 fi 42 fi 43 if [ -z "$python_cmd" ];then 44 echo "Enviroment variable 'python3' is required, and python verion must be greater than 3.7" 45 exit 1 46 fi 47} 48 49build_wifiiot() 50{ 51 current_xts=$1 52 current_target=$2 53 xts_root_dir="${suite_root_dir}/${current_xts}" 54 suite_out_dir="${xts_root_dir}/testcases" 55 suite_out_zip="${xts_root_dir}.zip" 56 mkdir -p $DIST_DIR 57 IFS=',' read -r -a array <<< "${current_target}" 58 echo "--------------------------------------------${array[@]}" 59 set -e 60 mkdir -p ${DIST_DIR}/json 61 for element in ${array[*]} 62 do 63 python build.py -p wifiiot_hispark_pegasus@hisilicon -f --test xts ${element} --gn-args build_xts=true 64 suite_build_target=$(echo "${element}" | awk -F "[/:]" '{print $NF}') 65 module_list_file=$suite_out_dir/module_info.json 66 suite_module_name=$(python test/xts/tools/lite/build/utils.py --method_name get_modulename_by_buildtarget --arguments module_list_file=${module_list_file}#build_target=${suite_build_target}) 67 subsystem_name=$(python test/xts/tools/lite/build/utils.py --method_name get_subsystem_name --arguments path=${element}) 68 69 python test/xts/tools/lite/build/utils.py --method_name record_testmodule_info --arguments build_target_name=${suite_module_name}#module_name=${suite_module_name}#subsystem_name=${subsystem_name}#suite_out_dir=${DIST_DIR}/json#same_file=True 70 71 mkdir -p ${suite_out_dir}/${subsystem_name} 72 cp -f ${BASE_HOME}/out/hispark_pegasus/wifiiot_hispark_pegasus/${WIFIIOT_OUTFILE} ${suite_out_dir}/${subsystem_name}/${suite_module_name}.bin 73 rm -f ${suite_out_dir}/${subsystem_name}/*.a 74 cp -rf ${xts_root_dir} ${DIST_DIR} 75 done 76 77 cp -rf ${DIST_DIR}/${current_xts} ${suite_root_dir} 78 rm -f ${suite_out_dir}/.bin 79 cp -rf ${DIST_DIR}/json/module_info.json ${suite_out_dir} 80 cd $suite_root_dir 81 rm -f ${suite_out_zip} 82 zip -rv ${suite_out_zip} ${current_xts} 83 cd $BASE_HOME 84 85} 86 87build_common() 88{ 89 python build.py -p ${PRODUCT}@${PLATFORM} -f --gn-args build_xts=true 90 find_dir_by_name "suites" "${BASE_HOME}/out" ${PRODUCT} 91 suite_root_dir_common="$dir_path_find_by_name" 92 xts_root_dir_common="${suite_root_dir_common}/acts" 93 suite_out_zip_common="${xts_root_dir_common}.zip" 94 mv ${xts_root_dir_common}/testcases/test_component.json $xts_root_dir_common/test_component.json 95 rm -rf ${xts_root_dir_common}/testcases 96 mkdir -p ${xts_root_dir_common}/testcases/${PRODUCT} 97 if [[ "$PRODUCT" == "neptune_iotlink_demo" ]]; then 98 cp -f $(dirname $suite_root_dir_common)/bin/hihope_neptune100.fls ${suite_root_dir_common}/acts/testcases/${PRODUCT}/OHOS_Image.fls 99 python test/xts/tools/lite/build/utils.py --method_name generate_allinone_testjson_by_template --arguments tmpl_file=${BASE_HOME}/test/xts/acts/build_lite/Test.tmpl#module_name=OHOS_Image.fls#product_name=${PRODUCT}#config_file=${xts_root_dir_common}/testcases/${PRODUCT}/OHOS_Image.json 100 else 101 if [[ "$PRODUCT" == "xts_demo" && "$PLATFORM" == "beken" ]]; then 102 cp -f $(dirname $suite_root_dir_common)/build/all_2M.1220.bin ${suite_root_dir_common}/acts/testcases/${PRODUCT}/OHOS_Image.bin 103 elif [[ "$PRODUCT" == "xts_demo" && "$PLATFORM" == "telink" ]]; then 104 cp -f $(dirname $suite_root_dir_common)/bin/xts_demo.bin ${suite_root_dir_common}/acts/testcases/${PRODUCT}/OHOS_Image.bin 105 else 106 cp -f $(dirname $suite_root_dir_common)/OHOS_Image.bin ${suite_root_dir_common}/acts/testcases/${PRODUCT}/OHOS_Image.bin 107 fi 108 python test/xts/tools/lite/build/utils.py --method_name generate_allinone_testjson_by_template --arguments tmpl_file=${BASE_HOME}/test/xts/acts/build_lite/Test.tmpl#module_name=OHOS_Image.bin#product_name=${PRODUCT}#config_file=${xts_root_dir_common}/testcases/${PRODUCT}/OHOS_Image.json 109 fi 110 mv $xts_root_dir_common/test_component.json ${xts_root_dir_common}/testcases/test_component.json 111 echo "{}" > ${xts_root_dir_common}/testcases/module_info.json 112 python test/xts/tools/lite/build/utils.py --method_name record_testmodule_info --arguments build_target_name=OHOS_Image#module_name=OHOS_Image#subsystem_name=${PRODUCT}#suite_out_dir=${xts_root_dir_common}/testcases#same_file=True 113 cd $suite_root_dir_common 114 rm -f ${suite_out_zip_common} 115 zip -rv ${suite_out_zip_common} acts 116 cd $BASE_HOME 117} 118