forked from projectceladon/vendor-intel-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautopatch.sh
executable file
·172 lines (150 loc) · 6.24 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
#!/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"
current_project=""
previous_project=""
conflict=""
conflict_list=""
applied_already=""
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`
b=`echo ${a#"Date: "}`
c=`git log --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 . -iname "*.patch" |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 * -iname "*.patch" | 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 [[ -e ${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 ]];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 ]];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 ]];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