blob: af7bb96066af1b7f91252b03a1415aa09f86ad02 [file] [log] [blame]
xiaobo gue6c46862018-01-10 18:58:09 +08001#!/bin/bash
2
3DEBUG_PRINT=0
4
xiaobo gue6c46862018-01-10 18:58:09 +08005declare GIT_OPERATE_INFO=""
6
7function dbg() {
8 if [ 0 != ${DEBUG_PRINT} ]; then
9 echo "$1"
10 fi
11}
12
13declare str_use=""
14# filter means get useful information
15function string_filter() {
16 # #1 origin str, #2 filter str, #3 split char, #4 which section
17 local str_origin=$1
18 local str_filter=$2
19 local str_split=$3
20 str_origin=${str_origin#*${str_filter}} # filter
21 IFS=${str_split} read -ra DATA <<< "$str_origin"
22 str_use=${DATA[$4]}
23}
24
25function get_versions() {
26 echo "Get version info"
xiaobo gude8a46a2018-03-05 21:41:54 +080027 declare -a SRC_REV
28 declare -a BIN_REV
xiaobo gue6c46862018-01-10 18:58:09 +080029 # read manifest, get each blx information
xiaobo gude8a46a2018-03-05 21:41:54 +080030 if [ -f $MANIFEST ]; then
31 while read -r line || [[ -n $line ]]; do
32 string_filter "${line}" "dest-branch=" '"' 1
33 GIT_INFO[0]=${str_use}
34 string_filter "${line}" "path=" '"' 1
35 GIT_INFO[1]=${str_use}
36 string_filter "${line}" "revision=" '"' 1
37 GIT_INFO[2]=${str_use}
38 string_filter "${line}" "name=" '"' 1
39 GIT_INFO[3]=${str_use}
40 string_filter "${line}" "remote=" '"' 1
41 GIT_INFO[4]=${str_use}
42 # if this line doesn't contain any info, skip it
43 if [ "${GIT_INFO[2]}" == "" ]; then
44 continue
45 fi
46 #echo "${GIT_INFO[0]} ${GIT_INFO[1]} ${GIT_INFO[2]} ${GIT_INFO[3]} ${GIT_INFO[4]}"
47 #echo ${BLX_NAME[@]}
48 #echo ${BLX_SRC_FOLDER[@]}
49 for loop in ${!BLX_NAME[@]}; do
50 if [ "${GIT_INFO[1]}" == "${BLX_SRC_FOLDER[$loop]}" ]; then
51 SRC_REV[$loop]=${GIT_INFO[2]}
52 #CUR_BIN_BRANCH[$loop]=${GIT_INFO[0]}
53 echo -n "name:${BLX_NAME[$loop]}, path:${BLX_SRC_FOLDER[$loop]}, "
54 if [ "${SRC_REV[$loop]}" == "${GIT_INFO[0]}" ]; then
55 # if only specify branch name, not version, use latest binaries under bin/ folders
56 # use bin.git revision, in case src code have local commits
57 if [ -d ${BLX_BIN_FOLDER[loop]} ]; then
58 git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1
59 git_msg=${GIT_OPERATE_INFO}
60 else
61 git_msg=""
62 fi
63 IFS=' ' read -ra DATA <<< "$git_msg"
64 SRC_REV[$loop]=${DATA[2]}
65 echo -n "revL:${SRC_REV[$loop]} "
66 else
67 SRC_REV[$loop]=${GIT_INFO[2]}
68 echo -n "rev:${SRC_REV[$loop]} "
69 fi
70 echo "@ ${GIT_INFO[0]}"
71 fi
72 if [ "${GIT_INFO[1]}" == "${BLX_BIN_FOLDER[$loop]}" ]; then
73 BIN_REV[$loop]=${GIT_INFO[2]}
74 #CUR_BIN_BRANCH[$loop]=${GIT_INFO[0]}
75 echo -n "name:${BLX_NAME[$loop]}, path:${BLX_BIN_FOLDER[$loop]}, "
76 if [ "${BIN_REV[$loop]}" == "${GIT_INFO[0]}" ]; then
77 # if only specify branch name, not version, use latest binaries under bin/ folders
78 git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1
79 else
80 # else get bin->src version
81 git_operate ${BLX_BIN_FOLDER[loop]} log ${BIN_REV[$loop]} --pretty=oneline -1
82 fi
xiaobo gue6c46862018-01-10 18:58:09 +080083 git_msg=${GIT_OPERATE_INFO}
84 IFS=' ' read -ra DATA <<< "$git_msg"
xiaobo gude8a46a2018-03-05 21:41:54 +080085 BIN_REV[$loop]=${DATA[2]}
86 echo -n "revL:${BIN_REV[$loop]} "
87 echo "@ ${GIT_INFO[0]}"
xiaobo gue6c46862018-01-10 18:58:09 +080088 fi
xiaobo gude8a46a2018-03-05 21:41:54 +080089 done
90 done < "$MANIFEST"
91 # SRC_REV="" means this is a no-src repo, use bin.git
92 if [ "" == "${SRC_REV[0]}" ]; then
93 dbg "src_rev NULL"
94 for loop in ${!BIN_REV[@]}; do
95 echo "Manifest: Use bin.git version. ${BLX_BIN_FOLDER[$loop]} - ${BIN_REV[$loop]}"
96 CUR_REV[$loop]=${BIN_REV[$loop]}
97 done
98 else
99 dbg "src_rev not NULL"
100 for loop in ${!SRC_REV[@]}; do
101 dbg "Manifest: src.git version. ${BLX_SRC_FOLDER[$loop]} - ${SRC_REV[$loop]}"
102 CUR_REV[$loop]=${SRC_REV[$loop]}
103 done
104 fi
105
106 # BIN_REV="" means this is a no-bin repo, use src.git
107 if [ "" == "${BIN_REV[0]}" ]; then
108 for loop in ${!SRC_REV[@]}; do
109 echo "Manifest: Src code only. build with --update-${BLX_NAME[$loop]}"
110 #CUR_REV[$loop]=${SRC_REV[$loop]}
111 update_bin_path $loop "source"
112 done
113 fi
114 else
115 for loop in ${!BLX_NAME[@]}; do
116 # merge into android/buildroot, can not get manifest.xml, get version by folder
117 # loop src folder
118 if [ -d ${BLX_SRC_FOLDER[$loop]} ]; then
119 echo "No-Manifest: Src code only. build with --update-${BLX_NAME[$loop]}"
120 update_bin_path $loop "source"
xiaobo gue6c46862018-01-10 18:58:09 +0800121 fi
122 done
xiaobo gude8a46a2018-03-05 21:41:54 +0800123 # loop bin folder. (this will overwrite src version if both exist)
124 for loop in ${!BLX_NAME[@]}; do
125 if [ -d ${BLX_BIN_FOLDER[$loop]} ]; then
126 git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1
127 git_msg=${GIT_OPERATE_INFO}
128 IFS=' ' read -ra DATA <<< "$git_msg"
129 CUR_REV[$loop]=${DATA[2]}
130 echo -n "revL:${CUR_REV[$loop]} "
131 echo "@ ${BLX_BIN_FOLDER[$loop]}"
132 fi
133 done
134 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800135}
136
137function git_operate() {
138 # $1: path, $2: other parameters
139 GIT_OPERATE_INFO=`git --git-dir $1/.git --work-tree=$1 ${@:2}`
140 dbg "${GIT_OPERATE_INFO}"
141}
142
143function git_operate2() {
144 # use -C. for pull use. don't know why [git_operate pull] doesn't work, server git update?
145 # $1: path, $2: other parameters
146 GIT_OPERATE_INFO="`git -C \"$1\" ${@:2}`"
147 #echo "${GIT_OPERATE_INFO}"
148}
149
150function get_blx_bin() {
151 # $1: current blx index
152 index=$1
153 git_operate ${BLX_BIN_FOLDER[index]} log --pretty=oneline
154
155 git_msg=${GIT_OPERATE_INFO}
156 BLX_READY[${index}]="false"
157 mkdir -p ${FIP_BUILD_FOLDER}
158
159 # get version log line by line, compare with target version
160 line_num=0
161 while read line;
162 do
163 IFS=' ' read -ra DATA <<< "$line"
164 # v1-fix support short-id
xiaobo gude8a46a2018-03-05 21:41:54 +0800165 dbg "${CUR_REV[$index]:0:7} - ${DATA[2]:0:7}"
xiaobo gue6c46862018-01-10 18:58:09 +0800166 if [ "${CUR_REV[$index]:0:7}" == "${DATA[2]:0:7}" ]; then
167 BLX_READY[${index}]="true"
168 dbg "blxbin:${DATA[0]} blxsrc: ${DATA[2]}"
169 dbg "blxbin:${DATA[0]} blxsrc-s:${DATA[2]:0:7}"
170 # reset to history version
171 #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard
172 git_operate2 ${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard
173 # copy binary file
174 if [ "bl32" == "${BLX_NAME[$index]}" ]; then
175 # bl32 is optional
176 if [ "y" == "${CONFIG_NEED_BL32}" ]; then
177 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
178 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
179 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null
180 fi
181 fi
182 else
183 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
184 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
185 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null
186 fi
Zhongfu Luofd0ea3e2018-11-30 14:15:16 +0800187 if [ -e ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/bl2.v3.bin ]; then
188 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/bl2.v3.bin ${FIP_BUILD_FOLDER} -f
189 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800190 fi
191 # undo reset
192 if [ 0 -ne ${line_num} ]; then
193 # this is not latest version, can do reset. latest version doesn't have 'git reflog'
194 #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard
195 git_operate2 ${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard
196 fi
197 break
198 fi
199 line_num=$((line_num+1))
200 done <<< "${git_msg}"
201 if [ "true" == ${BLX_READY[${index}]} ]; then
202 echo "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... done"
203 else
204 echo -n "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... failed"
205 if [ "true" == ${BLX_NEEDFUL[$index]} ]; then
206 echo "... abort"
207 exit -1
208 else
209 echo ""
210 fi
211 fi
212 return 0;
213}