blob: 37bd3ce7edf798a3566a48fe5fbd49a8f13f0b15 [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
17if [ -z "$MANIFEST_URL" ] || [ -z "$MANIFEST_BRANCH" ] || [ -z "$PROJECT_NAME" ] || [ -z "$BRANCH_NAME" ]; then
18 echo "NULL params!"
19 exit 1
20fi
21
Kelvin Zhangd64c8832022-04-02 19:56:24 +080022if [ "$SUBMIT_TYPE" = "daily" -o "$SUBMIT_TYPE" = "release" ];then
kelvin.zhanga1170fa2022-03-03 20:06:57 +080023 BUILDCHECK_BASE_PATH=/mnt/fileroot/autobuild/workdir/workspace/RTOS/RTOS_SDK/patchbuild
kelvin.zhang01393902022-03-03 20:42:46 +080024elif [ "$SUBMIT_TYPE" = "every" ];then
kelvin.zhanga1170fa2022-03-03 20:06:57 +080025 BUILDCHECK_BASE_PATH=/mnt/fileroot/jenkins/build-check
kelvin.zhanga1170fa2022-03-03 20:06:57 +080026fi
27
28MATCH_PATTERN="projects/"
Kelvin Zhange1cb8732022-03-22 11:39:49 +080029BRANCH=${MANIFEST_BRANCH#*${MATCH_PATTERN}}
kelvin.zhanga1170fa2022-03-03 20:06:57 +080030WORK_DIR=$BUILDCHECK_BASE_PATH/$PROJECT_NAME/$BRANCH
Kelvin Zhangb2630702022-04-20 11:22:32 +080031OUTPUT_DIR=$WORK_DIR/output
kelvin.zhanga1170fa2022-03-03 20:06:57 +080032
Kelvin Zhangb2630702022-04-20 11:22:32 +080033LAST_MANIFEST_FILE="$OUTPUT_DIR/manifest_last.xml"
34CURRENT_MANIFEST_FILE="$OUTPUT_DIR/manifest.xml"
35DIFF_MANIFEST_FILE="$OUTPUT_DIR/updates.xml"
36BUILD_LOG="$OUTPUT_DIR/build.log"
kelvin.zhang5fd25982022-03-04 09:43:01 +080037
Kelvin Zhangb2630702022-04-20 11:22:32 +080038if [ -n "$EXCLUDE_REPOS" ]; then
39 echo "Exclude repos:"
40 echo "$EXCLUDE_REPOS"
41 while IFS= read -r line
42 do
43 [ -n "$REPO_SYNC_IPATTERN" ] && REPO_SYNC_IPATTERN+="|"
44 REPO_SYNC_IPATTERN+="$line"
45 done <<< "$EXCLUDE_REPOS"
46fi
47
48[ "$FRESH_DOWNLOAD" = "yes" ] && rm -rf $WORK_DIR
49
kelvin.zhang01393902022-03-03 20:42:46 +080050if [ ! -d "$WORK_DIR" ]; then
51 echo -e "\n======== Downloading source code ========"
52 mkdir -p $WORK_DIR
Kelvin Zhangb2630702022-04-20 11:22:32 +080053 mkdir -p $OUTPUT_DIR
kelvin.zhang01393902022-03-03 20:42:46 +080054 cd $WORK_DIR
55 repo init -u ${MANIFEST_URL} -b ${MANIFEST_BRANCH} --repo-url=git://scgit.amlogic.com/tools/repo.git --no-repo-verify
kelvin.zhang5fd25982022-03-04 09:43:01 +080056else
57 echo -e "\n======== Syncing source code ========"
58 cd $WORK_DIR
Kelvin Zhang442c9152022-05-30 17:29:53 +080059 if [ -n "$REPO_SYNC_IPATTERN" ]; then
60 repo forall -i "$REPO_SYNC_IPATTERN" -c git reset -q --hard origin/$BRANCH_NAME
61 else
62 repo forall -c git reset -q --hard origin/$BRANCH_NAME
63 fi
kelvin.zhang5fd25982022-03-04 09:43:01 +080064 repo manifest -r -o $LAST_MANIFEST_FILE
kelvin.zhang01393902022-03-03 20:42:46 +080065fi
kelvin.zhanga1170fa2022-03-03 20:06:57 +080066
kelvin.zhang5fd25982022-03-04 09:43:01 +080067repo sync -cq -j8
Kelvin Zhang442c9152022-05-30 17:29:53 +080068[ "$?" -ne 0 ] && cd - && echo "Sync error! will do fresh download next time" && exit 1
69if [ -n "$REPO_SYNC_IPATTERN" ]; then
70 repo forall -i "$REPO_SYNC_IPATTERN" -c git reset -q --hard origin/$BRANCH_NAME
71else
72 repo forall -c git reset -q --hard origin/$BRANCH_NAME
73fi
kelvin.zhang5fd25982022-03-04 09:43:01 +080074repo manifest -r -o $CURRENT_MANIFEST_FILE
75echo -e "======== Done ========\n"
kelvin.zhang01393902022-03-03 20:42:46 +080076
kelvin.zhang5fd25982022-03-04 09:43:01 +080077if [ -f $LAST_MANIFEST_FILE ] && [ -f $CURRENT_MANIFEST_FILE ]; then
78 comm -23 <(sort $LAST_MANIFEST_FILE) <(sort $CURRENT_MANIFEST_FILE) > $DIFF_MANIFEST_FILE
79
80 if [ -s $DIFF_MANIFEST_FILE ]; then
81 echo "======== Recent Changes ========"
82
83 while IFS= read -r line
84 do
85 keyline=`echo "$line" | grep 'name=.* path='`
86
87 for keyword in $keyline; do
88 [[ $keyword == path=* ]] && repo_path=`echo ${keyword#*path=} | sed 's/\"//g'`
89 [[ $keyword == name=* ]] && repo_name=`echo ${keyword#*name=} | sed 's/\"//g'`
90 [[ $keyword == revision=* ]] && repo_version=`echo ${keyword#*revision=} | sed 's/\"//g'`
91 done
92
93 if [ -d "$repo_path" ]; then
94 pushd $repo_path > /dev/null
95 echo -e "\nProject $repo_name"
96 git log $repo_version..HEAD
97 popd > /dev/null
98 fi
99 done < $DIFF_MANIFEST_FILE
100 else
101 echo -e "======== Nothing changed since last build ========"
102 fi
103 rm -f $DIFF_MANIFEST_FILE
104fi
105
106if [ -n "$GERRIT_PROJECT" ] && [ -n "$GERRIT_PATCHSET_NUMBER" ] && [ -n "$GERRIT_CHANGE_NUMBER" ]; then
Kelvin Zhang90176112022-04-26 16:22:25 +0800107 echo -e "\n======== Applying Gerrit change $GERRIT_CHANGE_NUMBER on Project $GERRIT_PROJECT ========"
kelvin.zhang5fd25982022-03-04 09:43:01 +0800108 keyline=`grep "name=\"$GERRIT_PROJECT\"" $CURRENT_MANIFEST_FILE`
109
110 for keyword in $keyline; do
111 if [[ $keyword == path=* ]]; then
112 repo_path=`echo ${keyword#*path=} | sed 's/\"//g'`
113 break;
114 fi
115 done
116
117 if [ -d "$repo_path" ]; then
118 pushd $repo_path > /dev/null
119 l2=${GERRIT_CHANGE_NUMBER: -2}
120 git fetch ssh://scgit.amlogic.com:29418/${GERRIT_PROJECT} refs/changes/${l2}/${GERRIT_CHANGE_NUMBER}/${GERRIT_PATCHSET_NUMBER}
121 git cherry-pick FETCH_HEAD
122 if [ "$?" -ne 0 ]; then
123 echo -e "========= Applying patch failed! =========\n"
124 exit 1
125 fi
126 popd > /dev/null
127 else
128 echo "No such directory! $repo_path"
129 exit 1
130 fi
131 echo -e "======== Done ========\n"
132fi
133
kelvin.zhang2219b412022-03-04 16:44:41 +0800134# Manually cherry pick patches
135./scripts/cherry_pick.sh
136
Kelvin Zhangaa84d882022-04-22 13:38:46 +0800137# Include publish functions
138source scripts/publish.sh
139
Kelvin Zhangd64c8832022-04-02 19:56:24 +0800140if [[ "$SUBMIT_TYPE" == "release" ]]; then
141 echo "========= Building all packages ========"
Kelvin Zhangb2630702022-04-20 11:22:32 +0800142 ./scripts/build_all_pkg.sh > $BUILD_LOG 2>&1
Kelvin Zhangd64c8832022-04-02 19:56:24 +0800143 if [ "$?" -eq 0 ]; then
Kelvin Zhangaa84d882022-04-22 13:38:46 +0800144 post_publish_packages >> $BUILD_LOG 2>&1
Kelvin Zhangd64c8832022-04-02 19:56:24 +0800145 echo "======== Done ========"
146 else
Kelvin Zhangb2630702022-04-20 11:22:32 +0800147 cat $BUILD_LOG
Kelvin Zhangd64c8832022-04-02 19:56:24 +0800148 echo -e "\nAborted!"
149 exit 1
150 fi
kelvin.zhang5fd25982022-03-04 09:43:01 +0800151else
Kelvin Zhangd64c8832022-04-02 19:56:24 +0800152 echo "========= Building all projects ========"
Kelvin Zhangb2630702022-04-20 11:22:32 +0800153 ./scripts/build_all.sh > $BUILD_LOG 2>&1
Kelvin Zhangd64c8832022-04-02 19:56:24 +0800154 if [ "$?" -eq 0 ]; then
Kelvin Zhang8ce1b6e2022-05-30 17:36:49 +0800155 grep -qr "warning: " $BUILD_LOG
156 [ "$?" -eq 0 ] && cat $BUILD_LOG && echo -e "\nAborted with warnings!" && exit 1
Kelvin Zhang0322c7e2022-04-25 18:19:41 +0800157 [[ "$SUBMIT_TYPE" == "daily" ]] && post_publish_images >> $BUILD_LOG 2>&1
Kelvin Zhangd64c8832022-04-02 19:56:24 +0800158 echo "======== Done ========"
159 else
Kelvin Zhangb2630702022-04-20 11:22:32 +0800160 cat $BUILD_LOG
Kelvin Zhang8ce1b6e2022-05-30 17:36:49 +0800161 echo -e "\nAborted with errors!"
Kelvin Zhangd64c8832022-04-02 19:56:24 +0800162 exit 1
163 fi
kelvin.zhang5fd25982022-03-04 09:43:01 +0800164fi