-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvendorsetup.sh
More file actions
297 lines (274 loc) · 9.98 KB
/
Copy pathvendorsetup.sh
File metadata and controls
297 lines (274 loc) · 9.98 KB
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
290
291
292
293
294
295
296
# Copyright (c) 2012, The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Code Aurora Forum, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Environment variables influencing operation:
# B2G_TREE_ID - Defines the tree ID, used to determine which patches to
# apply. If unset, |treeid.sh| is run to identify the tree
# B2G_PATCH_DIRS_OVERRIDE - List of patch directories to be used instead of
# the build defaults.
# B2G_USE_REPO - If set, use |repo manifest| to determine when the Android
# tree has changed. Disabled by default for performance
# reasons.
# REPO - Path to repo executable (default: repo)
# NOTE: This file is from changeset 3adb883a67f76736fae667ea48fb9159f616efd6
# retrieved from git://codeaurora.org/quic/b2g/build.git
#echo "=======vendorsetup.sh"
#B2G_TREEID_SH=${B2G_TREEID_SH:-device/qcom/b2g_common/treeid.sh}
B2G_HASHED_FILES="${B2G_HASHED_FILES:-"device/qcom/b2g_common/vendorsetup.sh ${B2G_TREEID_SH}"}"
echo "B2G_HASHED_FILES: ${B2G_HASHED_FILES}"
REPO="${REPO:-repo}"
#B2G_PATCH_DIRS=${B2G_PATCH_DIRS_OVERRIDE:-device/qcom/b2g_common/patch}
B2G_PATCH_DIRS=${B2G_PATCH_DIRS_OVERRIDE}
echo "B2G_PATCH_DIRS: ${B2G_PATCH_DIRS}"
FORCE=1
__tree_md5sum()
{
#echo "tree_md5sum"
(
FILELIST="$(find $@ -type f 2>/dev/null) ${B2G_HASHED_FILES}"
# echo "FILELIST : ${FILELIST}"
if [[ -n "${B2G_USE_REPO}" ]]; then
${REPO} manifest -r -o - 2>/dev/null
fi
cat ${FILELIST}
) | openssl dgst -md5
}
__abandon_tree()
{
echo "abandon_tree"
rm -f out/lastpatch.md5sum
if [[ -d .repo ]]; then
${REPO} abandon b2g_autogen_ephemeral_branch || true
fi
}
__patch_tree()
{
(
cd $(gettop)
local TREE_ID=${B2G_TREE_ID:-$(${B2G_TREEID_SH})}
echo ">> Android tree IDs: ${TREE_ID}"
set -e
echo -n ">> Analyzing workspace for change..."
local LASTMD5SUM=invalid
local MD5SUM=unknown
if [[ -f out/lastpatch.md5sum ]]; then
LASTMD5SUM=$(cat out/lastpatch.md5sum)
MD5SUM=$(__tree_md5sum ${B2G_PATCH_DIRS})
echo "MD5SUM=${MD5SUM}"
fi
if [[ "$LASTMD5SUM" != "$MD5SUM" ]]; then
echo "Change detected. Applying B2G patches".
__abandon_tree
branch() {
[[ -d $1 ]] || return 1
pushd $1 > /dev/null
echo
echo [entering $1]
if [[ -d .git ]]; then
# Try repo first, but if the project is not repo managed then
# use a raw git branch instead.
${REPO} start b2g_autogen_ephemeral_branch . ||
( git checkout master && \
( git branch -D b2g_autogen_ephemeral_branch || true ) && \
git branch b2g_autogen_ephemeral_branch && \
git checkout b2g_autogen_ephemeral_branch \
)
else
read -p "Project $1 is not managed by git. Modify anyway? [y/N] "
if [[ ${REPLY} != "y" ]]; then
echo "No."
popd > /dev/null
return 1
fi
fi
}
apply() {
if [[ -d .git ]]; then
echo "git apply: $1"
git apply --index $1
else
echo "patch -p1 $1"
patch -p1 < $1
fi
}
git_rm() {
echo "git_rm:"
if [[ -d .git ]]; then
git rm -q $@
else
rm $@
fi
}
git_add() {
echo "git_add: $@"
if [[ -d .git ]]; then
git add $@
fi
}
commit() {
echo "git commit"
if [[ -d .git ]]; then
git commit --all -m "B2G Adaptations" --allow-empty -q
fi
popd > /dev/null
}
# Find all of the patches for TREE_ID
# and collate them into an associative array
# indexed by project
# echo "patching 1111111"
declare -a PRJ_LIST
declare -a PATCH_LIST
echo "B2G_PATCH_DIRS : ${B2G_PATCH_DIRS}"
for DIR in ${B2G_PATCH_DIRS} ; do
# echo " DIR : ${DIR}"
# echo " ==${TREE_ID}"
for ID in ${TREE_ID} ; do
# echo " ID : ${ID}"
local D=${DIR}/${ID}
# echo " D : ${D}"
[[ -d $D ]] || continue
PATCHES=$(find $D -type f | sort -fs)
echo "===PATCHES : ${PATCHES}"
for P in ${PATCHES}; do
PRJ=$(dirname ${P#${DIR}/${ID}/})
PATCH_ADDED=0
# echo "*** P=${P}"
# echo "PRJ=${PRJ}"
for (( I=0 ; I<${#PRJ_LIST[@]} ; I++ )) ; do
if [[ ${PRJ_LIST[$I]} == ${PRJ} ]]; then
PATCH_ADDED=1
PATCH_LIST[$I]="${PATCH_LIST[$I]} $P"
break
fi
done
# echo "PATCH_ADDED : ${PATCH_ADDED}"
if [[ ${PATCH_ADDED} -eq 0 ]]; then
PRJ_LIST=("${PRJ_LIST[@]}" "${PRJ}")
PATCH_LIST=("${PATCH_LIST[@]}" "$P")
fi
done
done
done
echo "list : ${PATCH_LIST[$I]}"
# Run through each project and apply patches
ROOT_DIR=${PWD}
for (( I=0 ; I<${#PRJ_LIST[@]} ; I++ )) ; do
local PRJ=${PRJ_LIST[$I]}
local FAILED_PRJ=${PRJ}
echo "patching...."
set +e
(
set -e
if branch ${PRJ} ; then
if [[ $1 != "force" && $(whoami) != "lnxbuild" && $FORCE != 1 ]]; then
if [[ -n $(git status --porcelain) ]]; then
echo "ERROR: You have uncommited changes in ${PRJ}"
echo "You may force overwriting these changes"
echo "with |source build/envsetup.sh force|"
exit 1
fi
fi
# Ensure the project is clean before applying patches to it
git reset --hard HEAD > /dev/null
git clean -dfx
declare -a PATCHNAME
for P in ${PATCH_LIST[$I]} ; do
# Skip patches that have already been applied by an earlier ID
local PATCH_APPLIED=0
for APPLIED in ${PATCHNAME} ; do
if [[ ${APPLIED} == $(basename $P) ]]; then
PATCH_APPLIED=1
fi
done
if [[ ${PATCH_APPLIED} -eq 1 ]]; then
continue
else
PATCHNAME="${PATCHNAME} $(basename $P)"
fi
echo "+${P}"
case $P in
*.patch) apply ${ROOT_DIR}/$P ;;
*.sh) source ${ROOT_DIR}/$P ;;
esac
done
commit
fi
)
local ERR=$?
if [[ ${ERR} -ne 0 ]]; then
echo
echo ERROR: Patching of ${FAILED_PRJ}/ failed.
echo
exit ${ERR}
fi
set -e
done
echo
echo B2G patches applied.
mkdir -p out
echo "create out/lastpatch.md5sum"
echo $(__tree_md5sum ${B2G_PATCH_DIRS}) > out/lastpatch.md5sum
else
echo no changes detected.
fi
)
ERR=$?
if [[ ${ERR} -ne 0 ]]; then
lunch() { echo ERROR: B2G PATCHES FAILED TO APPLY; return 1; }
choosecombo() { lunch; }
fi
return ${ERR}
}
# Stub out all java compilation.
export JAVA_HOME=$(gettop)/device/qcom/b2g_common/faketools/jdk
export ANDROID_JAVA_HOME=${JAVA_HOME}
# Use a local Xulrunner SDK copy instead of downloading
if [[ -d gaia/xulrunner-sdk/.git ]]; then
export USE_LOCAL_XULRUNNER_SDK=1
fi
flash()
{
( cd $(gettop)/device/qcom/b2g_common && ./flash.sh $@ )
}
rungdb()
{
( cd $(gettop)/device/qcom/b2g_common && ./run-gdb.sh $@ )
}
echo "========vendorsetup======="
if [[ -f vendor/qcom/proprietary/b2g_common/vendorsetup.sh ]]; then
. vendor/qcom/proprietary/b2g_common/vendorsetup.sh
fi
if [[ -z $1 ]]; then
__patch_tree
else
case $1 in
clean) __abandon_tree ;;
force) __patch_tree force ;;
np) echo "Skipping patch tree step...";;
*) [[ -z "$PS1" ]] && __patch_tree || echo Error: Unknown command: $1
esac
fi