OSDN Git Service

88f7d6825bb2b11bdf71a228c1898a41d811c28e
[android-x86/device-common.git] / generate-blob-scripts.sh
1 #!/usr/bin/env bash
2
3 # Copyright (C) 2010 The Android Open Source Project
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # This script auto-generates the scripts that manage the handling of the
18 # proprietary blobs necessary to build the Android Open-Source Project code
19 # for a variety of hardware targets
20
21 # It needs to be run from the root of a source tree that can repo sync,
22 # runs builds with and without the vendor tree, and uses the difference
23 # to generate the scripts.
24
25 # It can optionally upload the results to a Gerrit server for review.
26
27 # WARNING: It destroys the source tree. Don't leave anything precious there.
28
29 # Caveat: this script does many full builds (2 per device). It takes a while
30 # to run. It's best # suited for overnight runs on multi-CPU machines
31 # with a lot of RAM.
32
33 # Syntax: device/common/generate-blob-scripts.sh -f|--force [<server> <branch>]
34 #
35 # If the server and branch paramters are both present, the script will upload
36 # new files (if there's been any change) to the mentioned Gerrit server,
37 # in the specified branch.
38
39 if test "$1" != "-f" -a "$1" != "--force"
40 then
41   echo This script must be run with the --force option
42   exit 1
43 fi
44 shift
45
46 DEVICES="crespo crespo4g stingray wingray panda"
47
48 repo sync
49 repo sync
50 repo sync
51
52 ARCHIVEDIR=archive-$(date +%s)
53 if test -d archive-ref
54 then
55   cp -R archive-ref $ARCHIVEDIR
56 else
57   mkdir $ARCHIVEDIR
58
59   . build/envsetup.sh
60   for DEVICENAME in $DEVICES
61   do
62     rm -rf out
63     lunch full_$DEVICENAME-user
64     make -j32
65     cat out/target/product/$DEVICENAME/installed-files.txt |
66       cut -b 15- |
67       sort -f > $ARCHIVEDIR/$DEVICENAME-with.txt
68   done
69   rm -rf vendor
70   rm -rf device/*/tuna
71   rm -rf device/*/toro
72   rm -rf device/*/maguro
73   for DEVICENAME in $DEVICES
74   do
75     rm -rf out
76     lunch full_$DEVICENAME-user
77     make -j32
78     cat out/target/product/$DEVICENAME/installed-files.txt |
79       cut -b 15- |
80       sort -f > $ARCHIVEDIR/$DEVICENAME-without.txt
81   done
82 fi
83
84 for DEVICENAME in $DEVICES
85 do
86   MANUFACTURERNAME=$( find device -type d | grep [^/]\*/[^/]\*/$DEVICENAME\$ | cut -f 2 -d / )
87   for FILESTYLE in extract unzip
88   do
89     (
90     echo '#!/bin/sh'
91     echo
92     echo '# Copyright (C) 2010 The Android Open Source Project'
93     echo '#'
94     echo '# Licensed under the Apache License, Version 2.0 (the "License");'
95     echo '# you may not use this file except in compliance with the License.'
96     echo '# You may obtain a copy of the License at'
97     echo '#'
98     echo '#      http://www.apache.org/licenses/LICENSE-2.0'
99     echo '#'
100     echo '# Unless required by applicable law or agreed to in writing, software'
101     echo '# distributed under the License is distributed on an "AS IS" BASIS,'
102     echo '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.'
103     echo '# See the License for the specific language governing permissions and'
104     echo '# limitations under the License.'
105     echo
106     echo '# This file is generated by device/common/generate-blob-scripts.sh - DO NOT EDIT'
107     echo
108     echo DEVICE=$DEVICENAME
109     echo MANUFACTURER=$MANUFACTURERNAME
110     echo
111     echo 'mkdir -p ../../../vendor/$MANUFACTURER/$DEVICE/proprietary'
112
113     diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
114       grep -v '\.odex$' |
115       grep '>' |
116       cut -b 3- |
117       while read FULLPATH
118       do
119         if test $FILESTYLE = extract
120         then
121           echo adb pull $FULLPATH ../../../vendor/\$MANUFACTURER/\$DEVICE/proprietary/$(basename $FULLPATH)
122         else
123           echo unzip -j -o ../../../\${DEVICE}_update.zip $(echo $FULLPATH | cut -b 2-) -d ../../../vendor/\$MANUFACTURER/\$DEVICE/proprietary
124         fi
125         if test $(basename $FULLPATH) = akmd -o $(basename $FULLPATH) = mm-venc-omx-test -o $(basename $FULLPATH) = parse_radio_log -o $(basename $FULLPATH) = akmd8973 -o $(basename $FULLPATH) = gpsd -o $(basename $FULLPATH) = pvrsrvinit
126         then
127           echo chmod 755 ../../../vendor/\$MANUFACTURER/\$DEVICE/proprietary/$(basename $FULLPATH)
128         fi
129       done
130     echo
131
132     echo -n '(cat << EOF) | sed s/__DEVICE__/$DEVICE/g | sed s/__MANUFACTURER__/$MANUFACTURER/g > ../../../vendor/$MANUFACTURER/$DEVICE/'
133     echo 'device-vendor-blobs.mk'
134
135     echo '# Copyright (C) 2010 The Android Open Source Project'
136     echo '#'
137     echo '# Licensed under the Apache License, Version 2.0 (the "License");'
138     echo '# you may not use this file except in compliance with the License.'
139     echo '# You may obtain a copy of the License at'
140     echo '#'
141     echo '#      http://www.apache.org/licenses/LICENSE-2.0'
142     echo '#'
143     echo '# Unless required by applicable law or agreed to in writing, software'
144     echo '# distributed under the License is distributed on an "AS IS" BASIS,'
145     echo '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.'
146     echo '# See the License for the specific language governing permissions and'
147     echo '# limitations under the License.'
148     echo
149     echo -n '# This file is generated by device/__MANUFACTURER__/__DEVICE__/'
150     echo -n $FILESTYLE
151     echo '-files.sh - DO NOT EDIT'
152
153     FOUND=false
154     diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
155       grep -v '\.odex$' |
156       grep '>' |
157       cut -b 3- |
158       while read FULLPATH
159       do
160         if test $(basename $FULLPATH) = libgps.so -o $(basename $FULLPATH) = libcamera.so -o $(basename $FULLPATH) = libsecril-client.so
161         then
162           if test $FOUND = false
163           then
164             echo
165             echo '# Prebuilt libraries that are needed to build open-source libraries'
166             echo 'PRODUCT_COPY_FILES := \\'
167           else
168             echo \ \\\\
169           fi
170           FOUND=true
171           echo -n \ \ \ \ vendor/__MANUFACTURER__/__DEVICE__/proprietary/$(basename $FULLPATH):obj/lib/$(basename $FULLPATH)
172         fi
173       done
174     echo
175
176     FOUND=false
177     diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
178       grep -v '\.odex$' |
179       grep -v '\.apk$' |
180       grep '>' |
181       cut -b 3- |
182       while read FULLPATH
183       do
184         if test $FOUND = false
185         then
186           echo
187           echo -n '# All the blobs necessary for '
188           echo $DEVICENAME
189           echo 'PRODUCT_COPY_FILES += \\'
190         else
191           echo \ \\\\
192         fi
193         FOUND=true
194         echo -n \ \ \ \ vendor/__MANUFACTURER__/__DEVICE__/proprietary/$(basename $FULLPATH):$(echo $FULLPATH | cut -b 2-)
195       done
196     echo
197
198     FOUND=false
199     diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
200       grep '\.apk$' |
201       grep '>' |
202       cut -b 3- |
203       while read FULLPATH
204       do
205         if test $FOUND = false
206         then
207           echo
208           echo -n '# All the apks necessary for '
209           echo $DEVICENAME
210           echo 'PRODUCT_PACKAGES += \\'
211         else
212           echo \ \\\\
213         fi
214         FOUND=true
215         echo -n \ \ \ \ 
216         echo -n $(basename $FULLPATH) | sed 's/\.apk//g'
217       done
218     echo
219
220     echo
221     echo 'EOF'
222
223     echo
224
225     echo -n '(cat << EOF) | sed s/__DEVICE__/$DEVICE/g | sed s/__MANUFACTURER__/$MANUFACTURER/g > ../../../vendor/$MANUFACTURER/$DEVICE/'
226     echo 'proprietary/Android.mk'
227
228     echo '# Copyright (C) 2011 The Android Open Source Project'
229     echo '#'
230     echo '# Licensed under the Apache License, Version 2.0 (the "License");'
231     echo '# you may not use this file except in compliance with the License.'
232     echo '# You may obtain a copy of the License at'
233     echo '#'
234     echo '#      http://www.apache.org/licenses/LICENSE-2.0'
235     echo '#'
236     echo '# Unless required by applicable law or agreed to in writing, software'
237     echo '# distributed under the License is distributed on an "AS IS" BASIS,'
238     echo '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.'
239     echo '# See the License for the specific language governing permissions and'
240     echo '# limitations under the License.'
241     echo
242     echo -n '# This file is generated by device/__MANUFACTURER__/__DEVICE__/'
243     echo -n $FILESTYLE
244     echo '-files.sh - DO NOT EDIT'
245     echo
246     echo ifeq \(\\\$\(TARGET_DEVICE\),$DEVICENAME\)
247     echo LOCAL_PATH:=\\\$\(call my-dir\)
248
249     FOUND=false
250     diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
251       grep '\.apk$' |
252       grep '>' |
253       cut -b 3- |
254       while read FULLPATH
255       do
256         if test $FOUND = false
257         then
258           echo
259           echo -n '# Module makefile rules for apks on '
260           echo $DEVICENAME
261         fi
262         FOUND=true
263         echo
264         echo -n '# '
265         echo $(basename $FULLPATH) | sed 's/\.apk//g'
266         echo
267         echo include \\\$\(CLEAR_VARS\)
268         echo
269         echo LOCAL_MODULE := $(basename $FULLPATH) | sed 's/\.apk//g'
270         echo LOCAL_SRC_FILES := \\\$\(LOCAL_MODULE\).apk
271         echo LOCAL_MODULE_CLASS := APPS
272         echo LOCAL_MODULE_TAGS := optional
273         echo LOCAL_CERTIFICATE := PRESIGNED
274         echo LOCAL_MODULE_SUFFIX := \\\$\(COMMON_ANDROID_PACKAGE_SUFFIX\)
275         echo include \\\$\(BUILD_PREBUILT\)
276       done
277     echo
278     echo endif
279     echo
280
281     echo 'EOF'
282     echo
283     echo './setup-makefiles.sh'
284
285     ) > $ARCHIVEDIR/$DEVICENAME-$FILESTYLE-files.sh
286     cp $ARCHIVEDIR/$DEVICENAME-$FILESTYLE-files.sh device/$MANUFACTURERNAME/$DEVICENAME/$FILESTYLE-files.sh
287     chmod a+x device/$MANUFACTURERNAME/$DEVICENAME/$FILESTYLE-files.sh
288   done
289
290   (
291     cd device/$MANUFACTURERNAME/$DEVICENAME
292     git add .
293     git commit -m "auto-generated blob-handling scripts"
294     if test "$1" != "" -a "$2" != ""
295     then
296       echo uploading to server $1 branch $2
297       git push ssh://$1:29418/device/$MANUFACTURERNAME/$DEVICENAME.git HEAD:refs/for/$2
298     fi
299   )
300
301 done
302
303 echo * device/* |
304   tr \  \\n |
305   grep -v ^archive- |
306   grep -v ^device$ |
307   grep -v ^device/common$ |
308   xargs rm -rf