blob: 2d57574821b00867d65dc432f58c6de791cee493 [file] [log] [blame]
xiaobo gue6c46862018-01-10 18:58:09 +08001#!/bin/bash
2
3DEBUG_PRINT=0
4
5
6declare GIT_OPERATE_INFO=""
7
8function dbg() {
9 if [ 0 != ${DEBUG_PRINT} ]; then
10 echo "$1"
11 fi
12}
13
14declare str_use=""
15# filter means get useful information
16function string_filter() {
17 # #1 origin str, #2 filter str, #3 split char, #4 which section
18 local str_origin=$1
19 local str_filter=$2
20 local str_split=$3
21 str_origin=${str_origin#*${str_filter}} # filter
22 IFS=${str_split} read -ra DATA <<< "$str_origin"
23 str_use=${DATA[$4]}
24}
25
26function get_versions() {
27 echo "Get version info"
28 # read manifest, get each blx information
29 while read -r line || [[ -n $line ]]; do
30 string_filter "${line}" "dest-branch=" '"' 1
31 GIT_INFO[0]=${str_use}
32 string_filter "${line}" "path=" '"' 1
33 GIT_INFO[1]=${str_use}
34 string_filter "${line}" "revision=" '"' 1
35 GIT_INFO[2]=${str_use}
36 string_filter "${line}" "name=" '"' 1
37 GIT_INFO[3]=${str_use}
38 string_filter "${line}" "remote=" '"' 1
39 GIT_INFO[4]=${str_use}
40 # if this line doesn't contain any info, skip it
41 if [ "${GIT_INFO[2]}" == "" ]; then
42 continue
43 fi
44 #echo "${GIT_INFO[0]} ${GIT_INFO[1]} ${GIT_INFO[2]} ${GIT_INFO[3]} ${GIT_INFO[4]}"
45 #echo ${BLX_NAME[@]}
46 #echo ${BLX_SRC_FOLDER[@]}
47 for loop in ${!BLX_NAME[@]}; do
48 if [ "${GIT_INFO[1]}" == "${BLX_SRC_FOLDER[$loop]}" ]; then
49 CUR_REV[$loop]=${GIT_INFO[2]}
50 #CUR_BIN_BRANCH[$loop]=${GIT_INFO[0]}
51 echo -n "name:${BLX_NAME[$loop]}, path:${BLX_SRC_FOLDER[$loop]}, "
52 if [ "${CUR_REV[$loop]}" == "${GIT_INFO[0]}" ]; then
53 # if only specify branch name, not version, use latest binaries under bin/ folders
54 git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1
55 git_msg=${GIT_OPERATE_INFO}
56 IFS=' ' read -ra DATA <<< "$git_msg"
57 CUR_REV[$loop]=${DATA[2]}
58 echo -n "revL:${CUR_REV[$loop]} "
59 else
60 echo -n "rev:${CUR_REV[$loop]} "
61 fi
62 echo "@ ${GIT_INFO[0]}"
63 fi
64 done
65 done < "$MANIFEST"
66}
67
68function git_operate() {
69 # $1: path, $2: other parameters
70 GIT_OPERATE_INFO=`git --git-dir $1/.git --work-tree=$1 ${@:2}`
71 dbg "${GIT_OPERATE_INFO}"
72}
73
74function git_operate2() {
75 # use -C. for pull use. don't know why [git_operate pull] doesn't work, server git update?
76 # $1: path, $2: other parameters
77 GIT_OPERATE_INFO="`git -C \"$1\" ${@:2}`"
78 #echo "${GIT_OPERATE_INFO}"
79}
80
81function get_blx_bin() {
82 # $1: current blx index
83 index=$1
84 git_operate ${BLX_BIN_FOLDER[index]} log --pretty=oneline
85
86 git_msg=${GIT_OPERATE_INFO}
87 BLX_READY[${index}]="false"
88 mkdir -p ${FIP_BUILD_FOLDER}
89
90 # get version log line by line, compare with target version
91 line_num=0
92 while read line;
93 do
94 IFS=' ' read -ra DATA <<< "$line"
95 # v1-fix support short-id
96 #echo "${CUR_REV[$index]:0:7} - ${DATA[2]:0:7}"
97 if [ "${CUR_REV[$index]:0:7}" == "${DATA[2]:0:7}" ]; then
98 BLX_READY[${index}]="true"
99 dbg "blxbin:${DATA[0]} blxsrc: ${DATA[2]}"
100 dbg "blxbin:${DATA[0]} blxsrc-s:${DATA[2]:0:7}"
101 # reset to history version
102 #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard
103 git_operate2 ${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard
104 # copy binary file
105 if [ "bl32" == "${BLX_NAME[$index]}" ]; then
106 # bl32 is optional
107 if [ "y" == "${CONFIG_NEED_BL32}" ]; then
108 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
109 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
110 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null
111 fi
112 fi
113 else
114 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
115 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
116 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null
117 fi
118 fi
119 # undo reset
120 if [ 0 -ne ${line_num} ]; then
121 # this is not latest version, can do reset. latest version doesn't have 'git reflog'
122 #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard
123 git_operate2 ${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard
124 fi
125 break
126 fi
127 line_num=$((line_num+1))
128 done <<< "${git_msg}"
129 if [ "true" == ${BLX_READY[${index}]} ]; then
130 echo "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... done"
131 else
132 echo -n "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... failed"
133 if [ "true" == ${BLX_NEEDFUL[$index]} ]; then
134 echo "... abort"
135 exit -1
136 else
137 echo ""
138 fi
139 fi
140 return 0;
141}