blob: c9a35106f7f4363ea3be8830d628cc6b7142a6fb [file] [log] [blame]
kelvin.zhanga1170fa2022-03-03 20:06:57 +08001#!/bin/bash
2#
3# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
4#
5# SPDX-License-Identifier: MIT
6#
7
Kelvin Zhange1cb8732022-03-22 11:39:49 +08008source /etc/profile.d/TOOLSENV.sh
9
kelvin.zhanga1170fa2022-03-03 20:06:57 +080010export PATH=/opt/cmake-3.18.4-Linux-x86_64/bin/:$PATH
11export PATH=/proj/coverity/cov-analysis/bin/:$PATH
12export LM_LICENSE_FILE=/mnt/fileroot/jenkins/Xplorer_key.txt:$LM_LICENSE_FILE
13export PATH=/opt/xtensa/XtDevTools/install/tools/RG-2018.9-linux/XtensaTools/bin:$PATH
14export XTENSA_SYSTEM=/opt/xtensa/XtDevTools/install/builds/RG-2018.9-linux/Amlogic_v0/config
15export XTENSA_CORE=Amlogic_v0
16
Kelvin Zhangcf643422022-11-22 15:28:31 +080017if [ -z "$MANIFEST_BRANCH" ] || [ -z "$PROJECT_NAME" ] || [ -z "$BRANCH_NAME" ]; then
kelvin.zhanga1170fa2022-03-03 20:06:57 +080018 echo "NULL params!"
19 exit 1
20fi
21
fugui.zhang89409e12024-07-03 14:10:05 +080022if [ "$SUBMIT_TYPE" = "daily" ];then
Keguang Zhang1cba8592024-08-20 20:30:28 +080023 BASE_PATH=/mnt/fileroot/autobuild/workdir/workspace/RTOS/RTOS_SDK/dailybuild
fugui.zhang89409e12024-07-03 14:10:05 +080024elif [ "$SUBMIT_TYPE" = "release" ];then
Keguang Zhang1cba8592024-08-20 20:30:28 +080025 BASE_PATH=/mnt/fileroot/autobuild/workdir/workspace/RTOS/RTOS_SDK/dailybuild_release
fugui.zhang89409e12024-07-03 14:10:05 +080026elif [ "$SUBMIT_TYPE" = "patch" ];then
Keguang Zhang1cba8592024-08-20 20:30:28 +080027 BASE_PATH=/mnt/fileroot/autobuild/workdir/workspace/RTOS/RTOS_SDK/patchbuild
kelvin.zhang01393902022-03-03 20:42:46 +080028elif [ "$SUBMIT_TYPE" = "every" ];then
Keguang Zhang1cba8592024-08-20 20:30:28 +080029 BASE_PATH=/mnt/fileroot/jenkins/build-check
kelvin.zhanga1170fa2022-03-03 20:06:57 +080030fi
31
32MATCH_PATTERN="projects/"
Kelvin Zhange1cb8732022-03-22 11:39:49 +080033BRANCH=${MANIFEST_BRANCH#*${MATCH_PATTERN}}
Keguang Zhang1cba8592024-08-20 20:30:28 +080034WORK_DIR=$BASE_PATH/$PROJECT_NAME/$BRANCH
Kelvin Zhangb2630702022-04-20 11:22:32 +080035OUTPUT_DIR=$WORK_DIR/output
kelvin.zhanga1170fa2022-03-03 20:06:57 +080036
Kelvin Zhangfdf8ff02023-04-21 21:23:30 +080037MANIFEST="$OUTPUT_DIR/manifest.xml"
Kelvin Zhang4982b0b2022-08-31 19:15:24 +080038LAST_MANIFEST="$OUTPUT_DIR/last_manifest.xml"
Kelvin Zhang7052f1c2022-09-20 11:11:41 +080039DIFF_MANIFEST="$OUTPUT_DIR/diff_manifest.xml"
Kelvin Zhangff0a2b32022-11-08 14:17:14 +080040LAST_BUILD_FAILURE="$OUTPUT_DIR/.last_build_failure"
kelvin.zhang5fd25982022-03-04 09:43:01 +080041
Kelvin Zhang461d2e12022-11-21 20:51:42 +080042GERRIT_SERVER="scgit.amlogic.com"
43GERRIT_PORT="29418"
44GERRIT_QUERY_RESULT="$OUTPUT_DIR/topic_changes.txt"
45
Kelvin Zhangb2630702022-04-20 11:22:32 +080046if [ -n "$EXCLUDE_REPOS" ]; then
47 echo "Exclude repos:"
48 echo "$EXCLUDE_REPOS"
49 while IFS= read -r line
50 do
51 [ -n "$REPO_SYNC_IPATTERN" ] && REPO_SYNC_IPATTERN+="|"
52 REPO_SYNC_IPATTERN+="$line"
53 done <<< "$EXCLUDE_REPOS"
54fi
55
56[ "$FRESH_DOWNLOAD" = "yes" ] && rm -rf $WORK_DIR
57
kelvin.zhang01393902022-03-03 20:42:46 +080058if [ ! -d "$WORK_DIR" ]; then
59 echo -e "\n======== Downloading source code ========"
60 mkdir -p $WORK_DIR
Kelvin Zhangb2630702022-04-20 11:22:32 +080061 mkdir -p $OUTPUT_DIR
kelvin.zhang01393902022-03-03 20:42:46 +080062 cd $WORK_DIR
Kelvin Zhang461d2e12022-11-21 20:51:42 +080063 repo init -u ssh://${GERRIT_SERVER}:${GERRIT_PORT}/${PROJECT_NAME} -b ${MANIFEST_BRANCH} --repo-url=git://${GERRIT_SERVER}/tools/repo.git --no-repo-verify
kelvin.zhang5fd25982022-03-04 09:43:01 +080064else
65 echo -e "\n======== Syncing source code ========"
66 cd $WORK_DIR
Kelvin Zhang442c9152022-05-30 17:29:53 +080067 if [ -n "$REPO_SYNC_IPATTERN" ]; then
68 repo forall -i "$REPO_SYNC_IPATTERN" -c git reset -q --hard origin/$BRANCH_NAME
69 else
70 repo forall -c git reset -q --hard origin/$BRANCH_NAME
71 fi
Kelvin Zhang7052f1c2022-09-20 11:11:41 +080072 repo manifest -r -o $LAST_MANIFEST
kelvin.zhang01393902022-03-03 20:42:46 +080073fi
kelvin.zhanga1170fa2022-03-03 20:06:57 +080074
Kelvin Zhang81eb1b12022-06-09 14:35:18 +080075repo sync -cq -j8 --prune
Kelvin Zhang442c9152022-05-30 17:29:53 +080076[ "$?" -ne 0 ] && cd - && echo "Sync error! will do fresh download next time" && exit 1
77if [ -n "$REPO_SYNC_IPATTERN" ]; then
78 repo forall -i "$REPO_SYNC_IPATTERN" -c git reset -q --hard origin/$BRANCH_NAME
79else
80 repo forall -c git reset -q --hard origin/$BRANCH_NAME
81fi
Kelvin Zhangfdf8ff02023-04-21 21:23:30 +080082repo manifest -r -o $MANIFEST
kelvin.zhang5fd25982022-03-04 09:43:01 +080083echo -e "======== Done ========\n"
kelvin.zhang01393902022-03-03 20:42:46 +080084
Kelvin Zhangfdf8ff02023-04-21 21:23:30 +080085if [ -f $LAST_MANIFEST ] && [ -f $MANIFEST ]; then
86 comm -23 <(sort $LAST_MANIFEST) <(sort $MANIFEST) > $DIFF_MANIFEST
kelvin.zhang5fd25982022-03-04 09:43:01 +080087
Kelvin Zhang7052f1c2022-09-20 11:11:41 +080088 if [ -s $DIFF_MANIFEST ]; then
kelvin.zhang5fd25982022-03-04 09:43:01 +080089 echo "======== Recent Changes ========"
90
91 while IFS= read -r line
92 do
93 keyline=`echo "$line" | grep 'name=.* path='`
94
95 for keyword in $keyline; do
96 [[ $keyword == path=* ]] && repo_path=`echo ${keyword#*path=} | sed 's/\"//g'`
97 [[ $keyword == name=* ]] && repo_name=`echo ${keyword#*name=} | sed 's/\"//g'`
98 [[ $keyword == revision=* ]] && repo_version=`echo ${keyword#*revision=} | sed 's/\"//g'`
99 done
100
101 if [ -d "$repo_path" ]; then
102 pushd $repo_path > /dev/null
103 echo -e "\nProject $repo_name"
104 git log $repo_version..HEAD
105 popd > /dev/null
106 fi
Kelvin Zhang7052f1c2022-09-20 11:11:41 +0800107 done < $DIFF_MANIFEST
Kelvin Zhange98bd542022-09-07 15:43:58 +0800108 echo -e "================\n"
kelvin.zhang5fd25982022-03-04 09:43:01 +0800109 else
Kelvin Zhange98bd542022-09-07 15:43:58 +0800110 echo -e "======== Nothing changed since last build ========\n"
Keguang Zhang1cba8592024-08-20 20:30:28 +0800111 [[ "$SUBMIT_TYPE" == "daily" || "$SUBMIT_TYPE" == "release" ]] && exit 0
kelvin.zhang5fd25982022-03-04 09:43:01 +0800112 fi
Kelvin Zhang81eb1b12022-06-09 14:35:18 +0800113fi
114
Kelvin Zhang461d2e12022-11-21 20:51:42 +0800115source scripts/gerrit_review.sh
Kelvin Zhangc07a8db2022-09-06 21:06:31 +0800116# Cherry pick patches
Kelvin Zhang0f582792022-08-31 18:52:20 +0800117source scripts/cherry_pick.sh
Kelvin Zhanga04b9cb2022-11-29 15:05:27 +0800118[ "$?" -ne 0 ] && gerrit_review_for_gerrit_topic FAIL && exit 1
Kelvin Zhangcf643422022-11-22 15:28:31 +0800119gerrit_review_for_gerrit_topic Start
kelvin.zhang2219b412022-03-04 16:44:41 +0800120
Kelvin Zhang7052f1c2022-09-20 11:11:41 +0800121# Generate Jenkins trigger
Kelvin Zhangfdf8ff02023-04-21 21:23:30 +0800122JENKINS_TRIGGER="$OUTPUT_DIR/jenkins_trigger.txt"
fugui.zhang89409e12024-07-03 14:10:05 +0800123[[ "$SUBMIT_TYPE" == "daily" || "$SUBMIT_TYPE" == "patch" ]] && source scripts/gen_jenkins_trigger.sh
Kelvin Zhang7052f1c2022-09-20 11:11:41 +0800124
shijie.xiongec398682022-09-07 15:57:54 +0800125if [[ "$MANIFEST_BRANCH" == "$BRANCH_NAME" ]]; then
126 source scripts/build_all_pkg.sh
kelvin.zhang5fd25982022-03-04 09:43:01 +0800127else
Kelvin Zhang727c3e32022-08-31 20:57:37 +0800128 source scripts/build_all.sh
kelvin.zhang5fd25982022-03-04 09:43:01 +0800129fi
Kelvin Zhang461d2e12022-11-21 20:51:42 +0800130
Kelvin Zhanga04b9cb2022-11-29 15:05:27 +0800131[ "$?" -ne 0 ] && gerrit_review_for_gerrit_topic FAIL && exit 1
Kelvin Zhang461d2e12022-11-21 20:51:42 +0800132gerrit_review_for_gerrit_topic SUCCESS