1#!/bin/bash
2
3CUR_PATH=$(cd $(dirname $0) && pwd)
4BASE_PATH=$(dirname ${CUR_PATH})
5
6#时间统计
7startTime=`date +%Y%m%d-%H:%M:%S`
8startTime_s=`date +%s`
9
10#npm
11npm config set @ohos:registry=https://repo.harmonyos.com/npm/
12
13#ohpm
14#ohpm config set @ohos:registry=https://repo.harmonyos.com/ohpm/
15
16TEST_HAP_PATH=entry/build/default/outputs/ohosTest/entry-ohosTest-unsigned.hap
17HAP_PATH=entry/build/default/outputs/default/entry-default-unsigned.hap
18STAGE_TEST_HAP_PATH=product/build/default/outputs/ohosTest/product-ohosTest-unsigned.hap
19STAGE_HAP_PATH=product/build/default/outputs/default/product-default-unsigned.hap
20TIME=16
21RESOLVE=0
22
23arg_sign="true"
24arg_sdk_path=${BASE_PATH}/sdk
25arg_full_sdk_path=${BASE_PATH}/sdk-full
26arg_help="0"
27arg_compile_dir=""
28arg_jdk=""
29arg_node=""
30arg_ohpm="false"
31arg_p=""
32
33url=""
34tag_url='url='
35name=""
36tag_name='name='
37branch=""
38tag_branch='branch='
39tag_full_list='fullSdkAssembleList='
40tag_basic_list='basicSignList='
41basic_list=()
42full_list=()
43core_list=()
44tag_core_list='coreSignList='
45system_app_list=()
46tag_system_app_list='systemAppList='
47normal_list=()
48public_list=()
49#没测试用例
50simple_list=() 
51
52function print_help() {
53  cat <<EOF
54  use assembleHap [options] <mainclass> [args...]
55
56    --p=config path
57    --sign=true/false - Whether the signature (default:$arg_sign)
58    --sdk_path=[public sdk absolute address] (default:$arg_sdk_path)
59    --full_sdk_path=[full sdk absolute address] (default:$arg_full_sdk_path)
60    --ohpm=true/false -whether use ohpm (default:$arg_ohpm)  
61    --help  - prints help screen
62
63EOF
64}
65
66function parse_arguments() {
67        local helperKey="";
68        local helperValue="";
69        local current="";
70
71        while [ "$1" != "" ]; do
72                current=$1;
73                helperKey=${current#*--};
74                helperKey=${helperKey%%=*};
75                helperKey=$(echo "$helperKey" | tr '-' '_');
76                helperValue=${current#*=};
77                if [ "$helperValue" == "$current" ]; then
78                        helperValue="1";
79                fi
80                # echo "eval arg_$helperKey=\"$helperValue\"";
81
82                eval "arg_$helperKey=\"$helperValue\"";
83                shift
84        done
85}
86
87parse_arguments ${@};
88
89if [ "$arg_help" != "0" ]; then
90        print_help;
91        exit 1;
92fi
93
94if [ "$arg_p" == "" ]; then
95        echo "--p cannot be empty"
96        exit 1
97fi
98
99if [ "$arg_jdk" != "" ]; then
100        export JAVA_HOME=${arg_jdk}
101        export PATH=$JAVA_HOME/bin:$PATH
102fi
103
104if [ "$arg_node" != "" ]; then
105        export NODE_HOME=${arg_node}
106        export PATH=$NODE_HOME:$PATH
107fi
108
109function clear_dir(){
110        if [ ! -d "$1" ]; then
111                mkdir -p $1
112        else
113                rm -rf $1/*
114        fi
115}
116function clear_file(){
117        if [ -f "$1" ]; then
118                rm $1
119        fi
120        touch $1
121}
122
123function del_dir(){
124        if [ -d "$1" ]; then
125                rm -rf $1/*
126        fi
127}
128function del_file(){
129        if [ -f "$1" ]; then
130                rm $1
131        fi
132}
133
134function is_project_root(){
135        if [[ -f $1"/build-profile.json5" && -f $1"/hvigorfile.js" ]] || [[ -f $1"/build-profile.json5" && -f $1"/hvigorfile.ts" ]]; then
136                while read line
137                do
138                        if [[ ${line} =~ "srcPath" ]]; then
139                                pa=${line%\"*}
140                                pa=${pa##*\".}
141                                if [ -d "$1/AppScope" ]; then
142                                        is_entry=`cat $1${pa}/src/main/module.json5 | sed 's/ //g' | grep "\"type\":\"entry\""`
143                                        is_feature=`cat $1${pa}/src/main/module.json5 | sed 's/ //g' | grep "\"type\":\"feature\""`
144                                        if [[ "${is_entry}" != "" || "${is_feature}" != "" ]]; then
145                                                if [[ -d $1${pa}"/src/ohosTest" ]]; then
146                                                        return 0
147                                                fi
148                                        fi
149                                else
150                                        is_entry=`cat $1${pa}/src/main/config.json | sed 's/ //g' | grep "\"moduleType\":\"entry\""`
151                                        is_feature=`cat $1${pa}/src/main/config.json | sed 's/ //g' | grep "\"moduleType\":\"feature\""`
152                                        if [[ "${is_entry}" != "" || "${is_feature}" != "" ]]; then
153                                                if [[ -d $1${pa}"/src/ohosTest" ]]; then
154                                                        return 0
155                                                fi
156                                        fi
157                                fi
158                        fi
159                done < $1"/build-profile.json5"
160                return 1
161        else
162                return 2
163        fi
164}
165
166function read_project(){
167        if [ -d "$1" ]
168        then
169                # 是项目工程根目录则记录当前路径 否则递归判断
170                is_project_root $1
171		res=$?
172                if [ ${res} -eq 0 ]; then
173			public_list[${#public_list[*]}]=${1#*compile-tool/projects/${name}/}
174                elif [ ${res} -eq 1 ]; then
175                        simple_list[${#simple_list[*]}]=${1#*compile-tool/projects/${name}/}
176		elif [ ${res} -eq 2 ]; then
177                        for file in `ls $1`
178                        do
179                                read_project "${1}/${file}"
180                        done
181                fi
182        fi
183}
184
185function exclude_full_project(){
186	if [ ${#full_list[*]} -eq 0 ]; then
187		return
188	fi
189	diff_list=()
190	full_true_list=()
191	f=0
192	t=0
193	flag=0
194	for item1 in "${public_list[@]}"; do
195		for item2 in "${full_list[@]}"; do
196			if [[ "${item1}" == "${item2}" ]]; then
197				full_true_list[f]=${item2}
198				f=$((f+1))
199				flag=1
200				break
201			fi
202		done
203		if [ ${flag} -eq 0 ]; then
204			diff_list[t]=${item1}
205			t=$((t+1))
206		else
207			flag=0
208		fi
209	done
210	public_list=(${diff_list[@]})
211	full_list=(${full_true_list[@]})
212	echo "use public sdk project numbers =  "${#public_list[@]}
213	echo "use full sdk project numbers =  "${#full_list[@]}
214}
215
216function del_module_name(){
217        local name=${1}
218        for i in "${!module_name[@]}"
219        do
220                if [[ "${module_name[i]}" == "${name}" ]]; then
221                        unset module_name[i]
222                        echo "移除"${name}" , 剩余 : "${module_name[@]} >> ${compile_result_error}/${hap}".log" 2>&1
223                        return 0
224                fi
225        done
226        return 1
227}
228
229function load_dep(){
230        local cur_m_n=${1}
231	local cur_module
232        for cur_module in ${module_list[@]}
233        do
234                if [[ "${cur_module}" =~ "${cur_m_n}" ]]; then
235                        del_module_name ${cur_m_n}
236                        for m_n_1 in ${module_name[@]}
237                        do
238                                rr=$(cat ${cur_module}"/package.json" | grep "${m_n_1}")
239                                if [[ "${rr}" != "" ]]; then
240                                        load_dep ${m_n_1}
241                                fi
242                        done
243                        cd ${cur_module}
244                        echo ${cur_module}" 执行npm install" >> ${compile_result_error}/${hap}".log" 2>&1
245                        npm i >> ${compile_result_error}/${hap}".log" 2>&1
246                fi
247        done
248}
249
250function load_oh_dep(){
251        local cur_m_n=${1}
252	local cur_module
253        for cur_module in ${module_list[@]}
254        do
255                if [[ "${cur_module}" =~ "${cur_m_n}" ]]; then
256                        del_module_name ${cur_m_n}
257                        for m_n_1 in ${module_name[@]}
258                        do
259                                rr=$(cat ${cur_module}"/oh-package.json5" | grep "${m_n_1}")
260                                if [[ "${rr}" != "" ]]; then
261                                        load_oh_dep ${m_n_1}
262                                fi
263                        done
264                        cd ${cur_module}
265                        echo ${cur_module}" 执行ohpm install" >> ${compile_result_error}/${hap}".log" 2>&1
266                        if [[ -e "oh-package.json5" ]]; then
267                                ohpm i >> ${compile_result_error}/${hap}".log" 2>&1
268                        else   
269                                ohpm init >> ${compile_result_error}/${hap}".log" 2>&1
270                                ohpm install >> ${compile_result_error}/${hap}".log" 2>&1
271                        fi      
272                fi
273        done
274}
275
276
277function compile(){
278        # echo "compile $1"
279        hap=${1////_}
280        project_path=${BASE_PATH}/projects/${name}/${1}
281	compile_result=${2}
282	compile_result_error=${3}
283	nosign_hap_result=${4}
284        compile_result_success=${5}
285        if [ ! -d "${project_path}" ]; then
286                echo "${project_path} 路径不存在"
287                return
288        fi
289        
290        if [ -e "${project_path}/local.properties" ]; then
291                rm ${project_path}"/local.properties"
292        fi
293        
294        # echo "sdk.dir="${arg_full_sdk_path} >> ${project_path}"/local.properties" 2>&1
295        cd ${project_path}
296        if [[ -e "${project_path}/package.json" ]]; then
297                sed -i 's/\"@ohos\/hypium\".*\.[0-9]*\"/\"@ohos\/hypium\": \"1.0.3\"/g' ./package.json
298                sed -i 's/\"@ohos\/hvigor-ohos-plugin\".*\.[0-9]*\"/\"@ohos\/hvigor-ohos-plugin\": \"1.3.1\"/g' ./package.json
299                sed -i 's/\"@ohos\/hvigor\".*\.[0-9]*\"/\"@ohos\/hvigor\": \"1.3.1\"/g' ./package.json
300        fi
301	module_list=()
302        module_name=()
303        out_module=()
304	bundle_name=""
305        while read line
306        do
307                if [[ ${line} =~ "srcPath" ]]; then
308                        pa=${line%\"*}
309                        pa=${pa##*\".}
310                        module_list[${#module_list[*]}]=${project_path}${pa}
311			del_dir ${project_path}${pa}/node_modules
312                        del_file ${project_path}${pa}/package-lock.json
313                        del_dir ${project_path}${pa}/oh_modules
314                        del_file ${project_path}${pa}/oh-package-lock.json5
315                        module_name[${#module_name[*]}]=${pa}
316                        if [ -d "${project_path}/AppScope" ]; then
317				cur_bundle_line=`cat ${project_path}/AppScope/app.json5 | grep "\"bundleName\""`
318                                bundle_name=${cur_bundle_line%\"*}
319                                bundle_name=${bundle_name##*\"}
320                                # echo "bundleName : "${bundle_name}
321                                is_entry=`cat ${project_path}${pa}/src/main/module.json5 | sed 's/ //g' | grep "\"type\":\"entry\""`
322                                is_feature=`cat ${project_path}${pa}/src/main/module.json5 | sed 's/ //g' | grep "\"type\":\"feature\""`
323                                if [[ "${is_entry}" != "" || "${is_feature}" != "" ]]; then
324                                        echo "hap输出module: "${project_path}${pa} >> ${compile_result_error}/${hap}".log" 2>&1
325                                        out_module[${#out_module[*]}]=${project_path}${pa}
326                                fi
327                        else
328				cur_bundle_line=`cat ${project_path}${pa}/src/main/config.json | grep "\"bundleName\""`
329                                bundle_name=${cur_bundle_line%\"*}
330                                bundle_name=${bundle_name##*\"}
331                                # echo "bundleName : "${bundle_name}
332                                is_entry=`cat ${project_path}${pa}/src/main/config.json | sed 's/ //g' | grep "\"moduleType\":\"entry\""`
333                                is_feature=`cat ${project_path}${pa}/src/main/config.json | sed 's/ //g' | grep "\"moduleType\":\"feature\""`
334                                if [[ "${is_entry}" != "" || "${is_feature}" != "" ]]; then
335                                        echo "hap输出module: "${project_path}${pa} >> ${compile_result_error}/${hap}".log" 2>&1
336                                        out_module[${#out_module[*]}]=${project_path}${pa}
337                                fi
338                        fi
339                fi
340        done < ${project_path}"/build-profile.json5"
341
342        if [[ -e "${project_path}/oh-package.json5" ]]; then #如果是ohpm包管理方式
343                for module in ${module_list[@]}
344                do
345                        del_module_name ${module##${project_path}}
346                        if [ $? -eq 0 ]; then
347                                for m_n in ${module_name[@]}
348                                do
349                                        echo "查找 ${m_n} 是否是${module} 的依赖" >> ${compile_result_error}/${hap}".log" 2>&1
350                                        rr=$(cat ${module}"/oh-package.json5" | grep "${m_n}")
351                                        if [[ "${rr}" != "" ]]; then
352                                                echo "处理循环依赖 : "${m_n} >> ${compile_result_error}/${hap}".log" 2>&1
353                                                load_oh_dep ${m_n}
354                                        fi
355                                        
356                                done
357                                cd ${module}
358                                echo ${module}" 执行ohpm install" >> ${compile_result_error}/${hap}".log" 2>&1
359
360                                if [[ -e "oh-package.json5" ]]; then
361                                        ohpm i >> ${compile_result_error}/${hap}".log" 2>&1
362                                else   
363                                        ohpm init >> ${compile_result_error}/${hap}".log" 2>&1
364                                        ohpm install >> ${compile_result_error}/${hap}".log" 2>&1
365                                fi    
366
367                        fi
368                done
369        else 
370                for module in ${module_list[@]}
371                do
372                        del_module_name ${module##${project_path}}
373                        if [ $? -eq 0 ]; then
374                                for m_n in ${module_name[@]}
375                                do
376                                        echo "查找 ${m_n} 是否是${module} 的依赖" >> ${compile_result_error}/${hap}".log" 2>&1
377                                        rr=$(cat ${module}"/package.json" | grep "${m_n}")
378                                        if [[ "${rr}" != "" ]]; then
379                                                echo "处理循环依赖 : "${m_n} >> ${compile_result_error}/${hap}".log" 2>&1
380                                                load_dep ${m_n}
381                                        fi
382                                        
383                                done
384                                cd ${module}
385                                echo ${module}" 执行npm install" >> ${compile_result_error}/${hap}".log" 2>&1
386                                npm i >> ${compile_result_error}/${hap}".log" 2>&1
387                        fi
388                done
389                
390        fi
391
392
393	cd ${project_path}
394	del_dir ${project_path}/node_modules
395        del_dir ${project_path}/oh_modules
396        del_file ${project_path}/package-lock.json
397        del_file ${project_path}/oh-package-lock.json5
398        echo ${project_path}" 执行npm install" >> ${compile_result_error}/${hap}".log" 2>&1
399
400        if [[ -e "${project_path}/oh-package.json5" ]]; then
401                ohpm i >> ${compile_result_error}/${hap}".log" 2>&1
402                chmod +x hvigorw 
403                ./hvigorw clean --no-daemon >> ${compile_result_error}/${hap}".log" 2>&1
404        else 
405                npm install >> ${compile_result_error}/${hap}".log" 2>&1
406                node ./node_modules/@ohos/hvigor/bin/hvigor.js clean --no-daemon >> ${compile_result_error}/${hap}".log" 2>&1
407        fi
408
409
410
411        rm -rf ${project_path}/sign_tool
412        cp -r ${BASE_PATH}/tool/sign_tool ${project_path}
413
414	cd ${project_path}/sign_tool
415	if [[ $(echo ${basic_list[@]} | grep "${hap//_//}") != "" ]]; then
416                echo "${hap} 使用basic签名" >> ${compile_result_error}/${hap}".log" 2>&1
417		sed -i "s/\"normal\"/\"system_basic\"/g" ./UnsgnedReleasedProfileTemplate.json >> ${compile_result_error}/${hap}".log" 2>&1
418	elif [[ $(echo ${core_list[@]} | grep "${hap//_//}") != "" ]]; then
419                echo "${hap} 使用core签名" >> ${compile_result_error}/${hap}".log" 2>&1
420		sed -i "s/\"normal\"/\"system_core\"/g" ./UnsgnedReleasedProfileTemplate.json >> ${compile_result_error}/${hap}".log" 2>&1
421	fi
422	if [[ $(echo ${system_app_list[@]} | grep "${hap//_//}") != "" ]]; then
423                echo "${hap} 系统应用" >> ${compile_result_error}/${hap}".log" 2>&1
424		sed -i "s/\"hos_normal_app\"/\"hos_system_app\"/g" ./UnsgnedReleasedProfileTemplate.json >> ${compile_result_error}/${hap}".log" 2>&1
425	fi
426	if [ "${bundle_name}" != "" ]; then
427                echo "bundleName = ${bundle_name}" >> ${compile_result_error}/${hap}".log" 2>&1
428                sed -i "s/\"com.OpenHarmony.app.test\"/\"${bundle_name}\"/g" ./UnsgnedReleasedProfileTemplate.json >> ${compile_result_error}/${hap}".log" 2>&1
429        fi
430
431
432	sign_hap_num=0
433        for module in ${out_module[@]}
434        do
435		cd ${project_path}
436                cur_out_module_name=${module##*/}
437                if [[ -e "${project_path}/oh-package.json5" ]]; then
438                        chmod +x hvigorw
439		        ./hvigorw --mode module -p module=${cur_out_module_name} assembleHap --no-daemon >> ${compile_result_error}/${hap}".log" 2>&1
440                        if [[ -d ${module}"/src/ohosTest" ]]; then
441		                ./hvigorw --mode module -p module=${cur_out_module_name}@ohosTest assembleHap --no-daemon >> ${compile_result_error}/${hap}".log" 2>&1
442                        fi
443                else 
444		        node ./node_modules/@ohos/hvigor/bin/hvigor.js --mode module -p module=${cur_out_module_name} assembleHap  --no-daemon>> ${compile_result_error}/${hap}".log" 2>&1
445                        if [[ -d ${module}"/src/ohosTest" ]]; then
446		                node ./node_modules/@ohos/hvigor/bin/hvigor.js --mode module -p module=${cur_out_module_name}@ohosTest assembleHap  --no-daemon>> ${compile_result_error}/${hap}".log" 2>&1
447                        fi
448                fi
449
450                is_sign=false
451                echo "module = ${module} , cur_out_module_name=${cur_out_module_name}" >> ${compile_result_error}/${hap}".log" 2>&1
452                if [ ! -d ${module}/build/default/outputs/default/ -o ! -d ${module}/build/default/outputs/ohosTest/ -a -d ${module}"/src/ohosTest" ]; then
453                        echo "module = ${module}, assembleHap error !!!" >> ${compile_result_error}/${hap}".log" 2>&1
454                        continue
455                fi
456		sign_hap_path=""
457		test_sign_hap_path=""
458		nosign_hap_path=""
459		test_nosign_hap_path=""
460		for out_file in `ls ${module}/build/default/outputs/default/`
461		do
462			if [[ "${out_file}" =~ "-unsigned.hap" ]]; then
463				echo "发现unsigned包 : "${out_file}",开始使用签名工具签名" >> ${compile_result_error}/${hap}".log" 2>&1
464				nosign_hap_path=${module}/build/default/outputs/default/${out_file}
465				sign_hap_path=${module}/build/default/outputs/default/${out_file/unsigned/signed}
466				cd ${project_path}/sign_tool
467				java -jar ${BASE_PATH}/tool/hap-sign-tool.jar sign-profile -keyAlias "openharmony application profile release" -signAlg "SHA256withECDSA" -mode "localSign" -profileCertFile "OpenHarmonyProfileRelease.pem" -inFile "UnsgnedReleasedProfileTemplate.json" -keystoreFile "OpenHarmony.p12" -outFile "openharmony_sx.p7b" -keyPwd "123456" -keystorePwd "123456" >> ${compile_result_error}/${hap}".log" 2>&1
468				java -jar ${BASE_PATH}/tool/hap-sign-tool.jar sign-app -keyAlias "openharmony application release" -signAlg "SHA256withECDSA" -mode "localSign" -appCertFile "OpenHarmonyApplication.pem" -profileFile "openharmony_sx.p7b" -inFile "${nosign_hap_path}" -keystoreFile "OpenHarmony.p12" -outFile "${sign_hap_path}" -keyPwd "123456" -keystorePwd "123456" >> ${compile_result_error}/${hap}".log" 2>&1
469			fi
470		done
471
472                if [[ -d ${module}"/src/ohosTest" ]]; then
473                        for out_file in `ls ${module}/build/default/outputs/ohosTest/`
474                        do
475                                if [[ "${out_file}" =~ "-unsigned.hap" ]]; then
476                                        echo "发现unsigned包 : "${out_file}",开始使用签名工具签名" >> ${compile_result_error}/${hap}".log" 2>&1
477                                        test_nosign_hap_path=${module}/build/default/outputs/ohosTest/${out_file}
478                                        test_sign_hap_path=${module}/build/default/outputs/ohosTest/${out_file/unsigned/signed}
479                                        cd ${project_path}/sign_tool
480                                        java -jar ${BASE_PATH}/tool/hap-sign-tool.jar sign-profile -keyAlias "openharmony application profile release" -signAlg "SHA256withECDSA" -mode "localSign" -profileCertFile "OpenHarmonyProfileRelease.pem" -inFile "UnsgnedReleasedProfileTemplate.json" -keystoreFile "OpenHarmony.p12" -outFile "openharmony_sx.p7b" -keyPwd "123456" -keystorePwd "123456" >> ${compile_result_error}/${hap}".log" 2>&1
481                                        java -jar ${BASE_PATH}/tool/hap-sign-tool.jar sign-app -keyAlias "openharmony application release" -signAlg "SHA256withECDSA" -mode "localSign" -appCertFile "OpenHarmonyApplication.pem" -profileFile "openharmony_sx.p7b" -inFile "${test_nosign_hap_path}" -keystoreFile "OpenHarmony.p12" -outFile "${test_sign_hap_path}" -keyPwd "123456" -keystorePwd "123456" >> ${compile_result_error}/${hap}".log" 2>&1
482                                fi
483                        done
484                fi
485
486		if [[ ${sign_hap_path} != "" && -f ${sign_hap_path} && ( -f ${test_sign_hap_path} || ! -d ${module}"/src/ohosTest") ]]; then
487			cp ${sign_hap_path} ${compile_result}/${hap}_${cur_out_module_name}_signed.hap
488			cp ${nosign_hap_path} ${nosign_hap_result}/${hap}_${cur_out_module_name}_signed.hap
489                        
490                        if [[ -d ${module}"/src/ohosTest" ]]; then
491                                cp ${test_sign_hap_path} ${compile_result}/${hap}_${cur_out_module_name}_ohosTest_signed.hap
492                                cp ${test_nosign_hap_path} ${nosign_hap_result}/${hap}_${cur_out_module_name}_ohosTest_signed.hap
493                        fi
494			sign_hap_num=$(expr ${sign_hap_num} + 1)
495			echo "${module} assembleHap success !!!" >> ${compile_result_error}/${hap}".log" 2>&1
496		else
497			echo "${module} assembleHap error !!!" >> ${compile_result_error}/${hap}".log" 2>&1
498		fi
499        done
500        if [[ ${#out_module[@]} == ${sign_hap_num} ]]; then
501                #rm ${compile_result_error}/${hap}".log"
502                mv ${compile_result_error}/${hap}.log ${compile_result_success}/${hap}.log
503                echo "success compile ${hap} !!! "
504	else
505		echo "error   compile ${hap} QwQ ,log at ${compile_result_error}/${hap}.log"
506	fi
507}
508
509
510function compile_project(){
511        echo "use public sdk compile..."
512        project_path=${1}
513        project_name=${2}
514        COMPILE_RESULT=${BASE_PATH}/out/${project_name}/public-sdk/hap-out-with-nosigned
515        COMPILE_RESULT_ERROR=${BASE_PATH}/out/${project_name}/public-sdk/compile-error-log
516        COMPILE_RESULT_SUCCESS=${BASE_PATH}/out/${project_name}/public-sdk/compile-success-log
517        SIGN_RESULT=${BASE_PATH}/out/${project_name}/public-sdk/hap-out-with-signed
518
519        clear_dir $COMPILE_RESULT
520        clear_dir $COMPILE_RESULT_ERROR
521        clear_dir $COMPILE_RESULT_SUCCESS
522        clear_dir $SIGN_RESULT
523
524
525        export OHOS_SDK_HOME=${arg_sdk_path}
526        export OHOS_BASE_SDK_HOME=${arg_sdk_path}
527        echo "OHOS_SDK_HOME="${OHOS_SDK_HOME}
528        echo "OHOS_BASE_SDK_HOME="${OHOS_BASE_SDK_HOME}
529        
530	EOF=0
531        curr=0
532        while [ $EOF -ne 1 ]; do
533                for ((i=1; i<=$TIME; i++)); do
534                        if  [ ${curr} -eq ${#public_list[@]} ]; then
535                                EOF=1
536                                break
537                        fi
538                        compile ${public_list[$curr]} ${SIGN_RESULT} ${COMPILE_RESULT_ERROR} ${COMPILE_RESULT} ${COMPILE_RESULT_SUCCESS} &
539                        curr=$((curr+1))
540                done
541                wait
542        done
543}
544
545function compile_project_full(){
546        echo "use full sdk compile..."
547        project_path=${1}
548        project_name=${2}
549        COMPILE_RESULT=${BASE_PATH}/out/${project_name}/full-sdk/hap-out-with-nosigned
550        COMPILE_RESULT_ERROR=${BASE_PATH}/out/${project_name}/full-sdk/compile-error-log
551        COMPILE_RESULT_SUCCESS=${BASE_PATH}/out/${project_name}/full-sdk/compile-success-log
552        SIGN_RESULT=${BASE_PATH}/out/${project_name}/full-sdk/hap-out-with-signed
553
554        clear_dir $COMPILE_RESULT
555        clear_dir $COMPILE_RESULT_ERROR
556        clear_dir $COMPILE_RESULT_SUCCESS
557        clear_dir $SIGN_RESULT
558
559        export OHOS_SDK_HOME=${arg_full_sdk_path}
560        export OHOS_BASE_SDK_HOME=${arg_full_sdk_path}
561        echo "OHOS_SDK_HOME="${OHOS_SDK_HOME}
562        echo "OHOS_BASE_SDK_HOME="${OHOS_BASE_SDK_HOME}
563
564	EOF=0
565        curr=0
566        while [ $EOF -ne 1 ]; do
567                for ((i=1; i<=$TIME; i++)); do
568                        if  [ ${curr} -eq ${#full_list[@]} ]; then
569                                EOF=1
570                                break
571                        fi
572                        compile ${full_list[$curr]} ${SIGN_RESULT} ${COMPILE_RESULT_ERROR} ${COMPILE_RESULT} ${COMPILE_RESULT_SUCCESS} &
573                        curr=$((curr+1))
574                done
575                wait
576        done
577}
578
579function load(){
580	project_url=${1}
581	project_branch=${2}
582	project_name=${3}
583	# if test -d ${BASE_PATH}/projects/${project_name}
584 	# then
585        #         echo "${project_name} exists,ready for update..."
586        #         cd ${BASE_PATH}/projects/${project_name}
587        #         git reset --hard origin/${project_branch}
588        #         git checkout -b ${project_branch} origin/${project_branch}
589        #         git checkout ${project_branch}
590        #         git lfs fetch origin ${project_branch}
591	# 	git pull
592        # else
593        #         echo "${project_name} dose not exist,ready to download..."
594        #         if [ ! -d ${BASE_PATH}/projects ]; then
595	# 		mkdir -p ${BASE_PATH}/projects
596	# 	fi
597        #         cd ${BASE_PATH}/projects
598        #         git lfs clone -b ${project_branch} ${project_url} ${project_name}
599        #         git checkout -b ${project_branch} origin/${project_branch}
600        # fi
601        if [ -d "${BASE_PATH}/projects/${project_name}/${arg_compile_dir}" ]; then
602                read_project ${BASE_PATH}/projects/${project_name}/${arg_compile_dir}
603                exclude_full_project
604		compile_project ${BASE_PATH}/projects/${project_name} ${project_name}
605		compile_project_full ${BASE_PATH}/projects/${project_name} ${project_name}
606        fi
607}
608
609
610while read line
611do
612        if [[ ${line} == ${tag_url}* ]]; then
613                url=${line##*${tag_url}}
614        elif [[ ${line} == ${tag_branch}* ]]; then
615                branch=${line##*${tag_branch}}
616        elif [[ ${line} == ${tag_name}* ]]; then
617                name=${line##*${tag_name}}
618        elif [[ ${line} == ${tag_full_list}* ]]; then
619                temp_string=${line##*${tag_full_list}}
620                full_list=(${temp_string//;/ })
621        elif [[ ${line} == ${tag_basic_list}* ]]; then
622                temp_string=${line##*${tag_basic_list}}
623                basic_list=(${temp_string//;/ })
624        elif [[ ${line} == ${tag_core_list}* ]]; then
625                temp_string=${line##*${tag_core_list}}
626                core_list=(${temp_string//;/ })
627	elif [[ ${line} == ${tag_system_app_list}* ]]; then
628                temp_string=${line##*${tag_system_app_list}}
629                system_app_list=(${temp_string//;/ })
630        fi
631done < ${arg_p}
632
633load ${url} ${branch} ${name}
634
635endTime=`date +%Y%m%d-%H:%M:%S`
636endTime_s=`date +%s`
637sumTime=$[ $endTime_s - $startTime_s ]
638
639# echo "$startTime ---> $endTime" "耗时:$sumTime seconds"
640# echo "| public-sdk--|-------------|-------------|-------------|-------------|-------------"
641# echo "| 仓库        | 项目数量    | 成功数量    | 失败数量    | Hap数量    | 签名成功    "
642# echo "|-------------|-------------|-------------|-------------|-------------"
643# echo "| ${name} | ${#public_list[@]}         | $(ls -l ${BASE_PATH}/out/${name}/public-sdk/compile-success-log|grep "^-"|wc -l)           | $(ls -l ${BASE_PATH}/out/${name}/public-sdk/compile-error-log|grep "^-"|wc -l)           | "`expr $(ls -l ${BASE_PATH}/out/${name}/public-sdk/hap-out-with-nosigned|grep "^-"|wc -l) / 2`"         | "`expr $(ls -l ${BASE_PATH}/out/${name}/public-sdk/hap-out-with-signed|grep "^-"|wc -l) / 2`
644# if (( $(ls -l ${BASE_PATH}/out/${name}/public-sdk/compile-error-log|grep "^-"|wc -l) > 0 )); then
645#         echo "| 失败项目列表|-------------|-------------|-------------|-------------|-------------"
646# 	for z in `ls ${BASE_PATH}/out/${name}/public-sdk/compile-error-log`
647#         do
648#                 z=${z//_//}
649#                 z=${z%.log}
650#                 echo "| "${z}" |"
651#         done
652# fi
653# echo "| 失败项目日志汇总地址|-------------|-------------|-------------|-------------------"
654# echo "| ${BASE_PATH}/out/${name}/public-sdk/compile-error-log"
655# echo "| full-sdk----|-------------|-------------|-------------|-------------|-------------"
656# echo "| 仓库        | 项目数量    | 成功数量    | 失败数量    | Hap数量    | 签名成功    "
657# echo "|-------------|-------------|-------------|-------------|-------------|-------------"
658# echo "| ${name} | ${#full_list[@]}          | $(ls -l ${BASE_PATH}/out/${name}/full-sdk/compile-success-log|grep "^-"|wc -l)           | $(ls -l ${BASE_PATH}/out/${name}/full-sdk/compile-error-log|grep "^-"|wc -l)           | "`expr $(ls -l ${BASE_PATH}/out/${name}/full-sdk/hap-out-with-nosigned|grep "^-"|wc -l) / 2`"          | "`expr $(ls -l ${BASE_PATH}/out/${name}/full-sdk/hap-out-with-signed|grep "^-"|wc -l) / 2`
659# if (( $(ls -l ${BASE_PATH}/out/${name}/full-sdk/compile-error-log|grep "^-"|wc -l) > 0 )); then
660#         echo "| 失败项目列表|-------------|-------------|-------------|-------------|-------------"
661# 	for z in `ls ${BASE_PATH}/out/${name}/full-sdk/compile-error-log`
662#         do
663#                 z=${z//_//}
664#                 z=${z%.log}
665#                 echo "| "${z}" |"
666#         done
667# fi
668# echo "| 失败项目日志汇总地址|-------------|-------------|-------------------"
669# echo "| ${BASE_PATH}/out/${name}/full-sdk/compile-error-log"
670# echo "|-------------|-------------|-------------|-------------|-------------"
671# echo "| 成功项目日志汇总地址|-------------|-------------|-------------------"
672# echo "| ${BASE_PATH}/out/${name}/full-sdk/compile-success-log"
673# echo "| 不含测试用例项目|-------------|-------------|-------------------"
674#         for simple in ${simple_list[@]};do
675#         echo "| "${simple}" |"
676#         done
677# echo "|-------------|-------------|-------------|-------------|-------------"
678# echo "compile completed..."
679if [[ $(ls -l ${BASE_PATH}/out/${name}/public-sdk/compile-error-log|grep "^-"|wc -l) -gt 0 ]] || [[ $(ls -l ${BASE_PATH}/out/${name}/full-sdk/compile-error-log|grep "^-"|wc -l) -gt 0 ]];then
680        echo  "hap_build fail"
681else
682        echo "hap_build success"
683fi