forked from projectceladon/vendor-intel-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autopatch.sh
executable file
·289 lines (252 loc) · 11.7 KB
/
autopatch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/bin/bash
# autopatch.sh: script to manage patches on top of repo
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# Author: sgnanase <[email protected]>
# Author: Sun, Yi J <[email protected]>
#
# SPDX-License-Identifier: BSD-3-Clause
top_dir=`pwd`
if [ ! "${top_dir}" ]; then
echo "[autopatch.sh] Couldn't locate the top of the tree. Try setting TOP." >&2
return
fi
utils_dir="$top_dir/vendor/intel/utils"
patch_dir_aosp="$utils_dir/aosp_diff"
patch_dir_bsp="$utils_dir/bsp_diff"
private_utils_dir="$top_dir/vendor/intel/utils_priv"
private_patch_dir_aosp="$private_utils_dir/aosp_diff"
private_patch_dir_bsp="$private_utils_dir/bsp_diff"
vertical_utils_dir="$top_dir/vendor/intel/utils_vertical"
vertical_patch_dir_aosp="$vertical_utils_dir/aosp_diff"
vertical_patch_dir_bsp="$vertical_utils_dir/bsp_diff"
private_vertical_utils_dir="$top_dir/vendor/intel/utils_vertical_priv"
private_vertical_patch_dir_aosp="$private_vertical_utils_dir/aosp_diff"
private_vertical_patch_dir_bsp="$private_vertical_utils_dir/bsp_diff"
current_project=""
previous_project=""
conflict=""
conflict_list=""
applied_already=""
git_select=""
usage() {
echo "USAGE"
echo "Run below cmd to apply patches only to a specific repo:"
echo "$ TARGET_PRODUCT=<name> vendor/intel/utils/autopatch.sh <repo name>"
echo "OR just run to apply patches to all repos"
echo "$ TARGET_PRODUCT=<name> vendor/intel/utils/autopatch.sh"
}
apply_patch() {
pl=$1
pd=$2
for i in $pl
do
current_project=`dirname $i`
if [[ $current_project != $previous_project ]]; then
echo ""
echo "Project $current_project"
fi
previous_project=$current_project
cd $top_dir/$current_project
remote=`git remote -v | grep "https://android.googlesource.com/"`
if [[ -z "$remote" ]]; then
default_revision="remotes/m/master"
else
if [[ -f "$top_dir/.repo/manifest.xml" ]]; then
default_revision=`grep default $top_dir/.repo/manifest.xml | grep -o 'revision="[^"]\+"' | cut -d'=' -f2 | sed 's/\"//g'`
else
echo "Please make sure .repo/manifest.xml"
exit 1
fi
fi
cd $top_dir/$current_project
a=`grep "Date: " ${pd}/$i | head -1`
b=`echo ${a#"Date: "}`
c=`git log -500 --pretty=format:%aD | grep "$b"`
if [[ "$c" == "" ]] ; then
git am -3 --keep-cr --whitespace=nowarn $pd/$i >& /dev/null
if [[ $? == 0 ]]; then
echo -e "\tApplying\t\t`basename $i`"
else
echo -e "\tConflicts\t\t`basename $i`"
git am --abort >& /dev/null
conflict="y"
conflict_list="$current_project $conflict_list"
fi
else
echo -e "\tAlready applied\t\t`basename $i`"
applied_already="y"
fi
done
}
function fpnat() # find patch files and apply them
{
local patch_top_dir=$1
# arg #1 should be the .patch files' top directory,
# either aosp_diff/preliminary or aosp_diff/${TARGET_PRODUCT}
# and bsp_diff/preliminary bsp_diff/${TARGET_PRODUCT} directories.
cd ${patch_top_dir}
patch_file_number=`find ./$git_select -iname "*.patch" 2>/dev/null |wc -l`
echo "Path: `basename ${patch_top_dir}` has ${patch_file_number} patch file(s) to apply!"
if [[ ${patch_file_number} != 0 ]];then
patch_list=`find ./$git_select -iname "*.patch" 2>/dev/null | sort -u`
apply_patch "${patch_list}" "${patch_top_dir}"
if [[ $? != 0 ]]; then
echo "Apply ${patch_top_dir} patches failure!"
fi
fi
unset patch_list patch_top_dir
}
if [[ $# -eq 1 ]]; then
if [[ -d $top_dir/$1 ]]; then
git_select="$1"
else
echo "$1 - this git doesn't exist"
usage
exit -1
fi
fi
if [[ $# -gt 1 || $# -lt 0 ]]; then
usage
exit -1
fi
if [[ -e ${patch_dir_aosp}/${TARGET_PRODUCT}/include_preliminary ]] || [[ -e ${private_patch_dir_aosp}/${TARGET_PRODUCT}/include_preliminary ]];then
echo -e "\nApply utils/aosp_diff/preliminary patches:"
fpnat "$patch_dir_aosp/preliminary"
fi
if [[ -e ${patch_dir_aosp}/${TARGET_PRODUCT} ]] && [[ -d ${patch_dir_aosp}/${TARGET_PRODUCT} ]];then
echo -e "\nApply utils/aosp_diff Target ${TARGET_PRODUCT} Patches:"
fpnat "${patch_dir_aosp}/${TARGET_PRODUCT}"
fi
if [[ -e ${patch_dir_bsp}/${TARGET_PRODUCT}/include_common ]] || [[ -e ${private_patch_dir_bsp}/${TARGET_PRODUCT}/include_common ]];then
echo -e "\nApply utils/bsp_diff/common Patches:"
fpnat "${patch_dir_bsp}/common"
fi
if [[ -e ${patch_dir_bsp}/${TARGET_PRODUCT} ]] && [[ -d ${patch_dir_bsp}/${TARGET_PRODUCT} ]];then
echo -e "\nApply utils/bsp_diff Target ${TARGET_PRODUCT} Patches:"
fpnat "${patch_dir_bsp}/${TARGET_PRODUCT}"
fi
if [[ "$conflict" == "y" ]]; then
echo -e "\n\n\t\tALERT : Conflicts Observed while patch application !! "
for i in $conflict_list ; do echo $i; done | sort -u
echo -e "\n\n\t\tError: Please resolve Conflict(s) and re-run lunch..."
echo '$(error "Conflicts seen while applying lunch patches !! Resolve and re-trigger")' > $top_dir/vendor/intel/utils/Android.mk
else
echo -e "\n\t\tSUCCESS : All patches applied successfully in: `basename $patch_dir_aosp` and `basename ${patch_dir_bsp}` !!"
if [[ "$applied_already" == "y" ]]; then
echo -e "\n\t\tINFO : SOME PATCHES ARE APPLIED ALREADY !!"
fi
if [ -f "$top_dir/vendor/intel/utils/Android.mk" ]; then
sed -i '/^/d' $top_dir/vendor/intel/utils/Android.mk
fi
fi
# Apply Embargoed patches if exist
if [[ -e ${private_utils_dir} ]] && [[ -d ${private_utils_dir} ]];then
echo -e "\n============================="
echo "Embargoed Patches Found"
echo "============================="
if [[ -e ${private_patch_dir_aosp}/${TARGET_PRODUCT}/include_preliminary_priv ]];then
echo -e "\nApply utils_priv/aosp_diff/preliminary Patches:"
fpnat "${private_patch_dir_aosp}/preliminary"
fi
if [[ -e ${private_patch_dir_aosp}/${TARGET_PRODUCT} ]] && [[ -d ${private_patch_dir_aosp}/${TARGET_PRODUCT} ]];then
echo -e "\nApply utils_priv/aosp_diff Target ${TARGET_PRODUCT} Patches:"
fpnat "${private_patch_dir_aosp}/${TARGET_PRODUCT}"
fi
if [[ -e ${private_patch_dir_bsp}/${TARGET_PRODUCT}/include_common_priv ]];then
echo -e "\nApply utils_priv/bsp_diff/common Patches:"
fpnat "${private_patch_dir_bsp}/common"
fi
if [[ -e ${private_patch_dir_bsp}/${TARGET_PRODUCT} ]] && [[ -d ${private_patch_dir_bsp}/${TARGET_PRODUCT} ]];then
echo -e "\nApply utils_priv/bsp_diff Target ${TARGET_PRODUCT} Patches:"
fpnat "${private_patch_dir_bsp}/${TARGET_PRODUCT}"
fi
if [[ "$conflict" == "y" ]]; then
echo -e "\n\t\tALERT : Conflicts Observed while patch application !! "
for i in $conflict_list ; do echo $i; done | sort -u
echo -e "\n\t\tError: Please resolve Conflict(s) and re-run lunch..."
echo '$(error "Conflicts seen while applying lunch patches !! Resolve and re-trigger")' > $top_dir/vendor/intel/utils_priv/Android.mk
else
echo -e "\n\t\tSUCCESS : All patches applied SUCCESSFULLY in `basename ${private_patch_dir_aosp}` and `basename ${private_patch_dir_bsp}`"
if [[ "$applied_already" == "y" ]]; then
echo -e "\n\t\tINFO : SOME PATCHES ARE APPLIED ALREADY !!"
fi
if [ -f "$top_dir/vendor/intel/utils_priv/Android.mk" ]; then
sed -i '/^/d' $top_dir/vendor/intel/utils_priv/Android.mk
fi
fi
fi
# NOTE: include_preliminary and inlcude_preliminary_priv feature if needed by
# Vertical then will be implemented. As of now it is supported by utils and
# utils_priv repos only.
# Apply Vertical patches if exist
if [[ -e ${vertical_utils_dir} ]] && [[ -d ${vertical_utils_dir} ]];then
echo -e "\n============================="
echo "Vertical Patches Found"
echo "============================="
if [[ -e ${vertical_patch_dir_aosp}/${TARGET_PRODUCT}/include_preliminary ]];then
echo -e "\nApply utils_vertical/aosp_diff/preliminary Patches:"
fpnat "${vertical_patch_dir_aosp}/preliminary"
fi
if [[ -e ${vertical_patch_dir_aosp}/${TARGET_PRODUCT} ]] && [[ -d ${vertical_patch_dir_aosp}/${TARGET_PRODUCT} ]];then
echo -e "\nApply utils_vertical/aosp_diff Target ${TARGET_PRODUCT} Patches:"
fpnat "${vertical_patch_dir_aosp}/${TARGET_PRODUCT}"
fi
if [[ -e ${vertical_patch_dir_bsp}/${TARGET_PRODUCT}/include_common ]];then
echo -e "\nApply utils_vertical/bsp_diff/common Patches:"
fpnat "${vertical_patch_dir_bsp}/common"
fi
if [[ -e ${vertical_patch_dir_bsp}/${TARGET_PRODUCT} ]] && [[ -d ${vertical_patch_dir_bsp}/${TARGET_PRODUCT} ]];then
echo -e "\nApply utils_vertical/bsp_diff Target ${TARGET_PRODUCT} Patches:"
fpnat "${vertical_patch_dir_bsp}/${TARGET_PRODUCT}"
fi
if [[ "$conflict" == "y" ]]; then
echo -e "\n\t\tALERT : Conflicts Observed while patch application !! "
for i in $conflict_list ; do echo $i; done | sort -u
echo -e "\n\t\tError: Please resolve Conflict(s) and re-run lunch..."
echo '$(error "Conflicts seen while applying lunch patches !! Resolve and re-trigger")' > $top_dir/vendor/intel/utils_vertical/Android.mk
else
echo -e "\n\t\tSUCCESS : All patches applied SUCCESSFULLY in `basename ${vertical_patch_dir_aosp}` and `basename ${vertical_patch_dir_bsp}`"
if [[ "$applied_already" == "y" ]]; then
echo -e "\n\t\tINFO : SOME PATCHES ARE APPLIED ALREADY !!"
fi
if [ -f "$top_dir/vendor/intel/utils_vertical/Android.mk" ]; then
sed -i '/^/d' $top_dir/vendor/intel/utils_vertical/Android.mk
fi
fi
fi
# Apply Vertical private patches if exist
if [[ -e ${private_vertical_utils_dir} ]] && [[ -d ${private_vertical_utils_dir} ]];then
echo -e "\n============================="
echo "Vertical Embargoed Patches Found"
echo "============================="
if [[ -e ${private_vertical_patch_dir_aosp}/${TARGET_PRODUCT}/include_preliminary ]];then
echo -e "\nApply private_utils_vertical/aosp_diff/preliminary Patches:"
fpnat "${private_vertical_patch_dir_aosp}/preliminary"
fi
if [[ -e ${private_vertical_patch_dir_aosp}/${TARGET_PRODUCT} ]] && [[ -d ${private_vertical_patch_dir_aosp}/${TARGET_PRODUCT} ]];then
echo -e "\nApply private_utils_vertical/aosp_diff Target ${TARGET_PRODUCT} Patches:"
fpnat "${private_vertical_patch_dir_aosp}/${TARGET_PRODUCT}"
fi
if [[ -e ${private_vertical_patch_dir_bsp}/${TARGET_PRODUCT}/include_common ]];then
echo -e "\nApply private_utils_vertical/bsp_diff/common Patches:"
fpnat "${private_vertical_patch_dir_bsp}/common"
fi
if [[ -e ${private_vertical_patch_dir_bsp}/${TARGET_PRODUCT} ]] && [[ -d ${private_vertical_patch_dir_bsp}/${TARGET_PRODUCT} ]];then
echo -e "\nApply private_utils_vertical/bsp_diff Target ${TARGET_PRODUCT} Patches:"
fpnat "${private_vertical_patch_dir_bsp}/${TARGET_PRODUCT}"
fi
if [[ "$conflict" == "y" ]]; then
echo -e "\n\t\tALERT : Conflicts Observed while patch application !! "
for i in $conflict_list ; do echo $i; done | sort -u
echo -e "\n\t\tError: Please resolve Conflict(s) and re-run lunch..."
echo '$(error "Conflicts seen while applying lunch patches !! Resolve and re-trigger")' > $top_dir/vendor/intel/utils_vertical_priv/Android.mk
else
echo -e "\n\t\tSUCCESS : All patches applied SUCCESSFULLY in `basename ${private_vertical_patch_dir_aosp}` and `basename ${private_vertical_patch_dir_bsp}`"
if [[ "$applied_already" == "y" ]]; then
echo -e "\n\t\tINFO : SOME PATCHES ARE APPLIED ALREADY !!"
fi
if [ -f "$top_dir/vendor/intel/utils_vertical_priv/Android.mk" ]; then
sed -i '/^/d' $top_dir/vendor/intel/utils_vertical_priv/Android.mk
fi
fi
fi