OSDN Git Service

027c821f5275bf3cc27c64177a989dcd2c2b688d
[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 passion and crespo 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 tuna toro panda"
47
48 ARCHIVEDIR=archive-$(date +%s)
49 mkdir $ARCHIVEDIR
50
51 repo sync
52 repo sync
53 repo sync
54
55 . build/envsetup.sh
56 for DEVICENAME in $DEVICES
57 do
58   rm -rf out
59   lunch full_$DEVICENAME-user
60   make -j32
61   cat out/target/product/$DEVICENAME/installed-files.txt |
62     cut -b 15- |
63     sort -f > $ARCHIVEDIR/$DEVICENAME-with.txt
64 done
65 rm -rf vendor
66 for DEVICENAME in $DEVICES
67 do
68   rm -rf out
69   lunch full_$DEVICENAME-user
70   make -j32
71   cat out/target/product/$DEVICENAME/installed-files.txt |
72     cut -b 15- |
73     sort -f > $ARCHIVEDIR/$DEVICENAME-without.txt
74 done
75
76 for DEVICENAME in $DEVICES
77 do
78   MANUFACTURERNAME=$( find device -type d | grep [^/]\*/[^/]\*/$DEVICENAME\$ | cut -f 2 -d / )
79   for FILESTYLE in extract unzip
80   do
81     (
82     echo '#!/bin/sh'
83     echo
84     echo '# Copyright (C) 2010 The Android Open Source Project'
85     echo '#'
86     echo '# Licensed under the Apache License, Version 2.0 (the "License");'
87     echo '# you may not use this file except in compliance with the License.'
88     echo '# You may obtain a copy of the License at'
89     echo '#'
90     echo '#      http://www.apache.org/licenses/LICENSE-2.0'
91     echo '#'
92     echo '# Unless required by applicable law or agreed to in writing, software'
93     echo '# distributed under the License is distributed on an "AS IS" BASIS,'
94     echo '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.'
95     echo '# See the License for the specific language governing permissions and'
96     echo '# limitations under the License.'
97     echo
98     echo '# This file is generated by device/common/generate-blob-scripts.sh - DO NOT EDIT'
99     echo
100     echo DEVICE=$DEVICENAME
101     echo MANUFACTURER=$MANUFACTURERNAME
102     echo
103     echo 'mkdir -p ../../../vendor/$MANUFACTURER/$DEVICE/proprietary'
104
105     diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
106       grep -v '\.odex$' |
107       grep '>' |
108       cut -b 3- |
109       while read FULLPATH
110       do
111         if test $FILESTYLE = extract
112         then
113           echo adb pull $FULLPATH ../../../vendor/\$MANUFACTURER/\$DEVICE/proprietary/$(basename $FULLPATH)
114         else
115           echo unzip -j -o ../../../\${DEVICE}_update.zip $(echo $FULLPATH | cut -b 2-) -d ../../../vendor/\$MANUFACTURER/\$DEVICE/proprietary
116         fi
117         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
118         then
119           echo chmod 755 ../../../vendor/\$MANUFACTURER/\$DEVICE/proprietary/$(basename $FULLPATH)
120         fi
121       done
122     echo
123
124     echo -n '(cat << EOF) | sed s/__DEVICE__/$DEVICE/g | sed s/__MANUFACTURER__/$MANUFACTURER/g > ../../../vendor/$MANUFACTURER/$DEVICE/'
125     echo 'device-vendor-blobs.mk'
126
127     echo '# Copyright (C) 2010 The Android Open Source Project'
128     echo '#'
129     echo '# Licensed under the Apache License, Version 2.0 (the "License");'
130     echo '# you may not use this file except in compliance with the License.'
131     echo '# You may obtain a copy of the License at'
132     echo '#'
133     echo '#      http://www.apache.org/licenses/LICENSE-2.0'
134     echo '#'
135     echo '# Unless required by applicable law or agreed to in writing, software'
136     echo '# distributed under the License is distributed on an "AS IS" BASIS,'
137     echo '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.'
138     echo '# See the License for the specific language governing permissions and'
139     echo '# limitations under the License.'
140     echo
141     echo -n '# This file is generated by device/__MANUFACTURER__/__DEVICE__/'
142     echo -n $FILESTYLE
143     echo '-files.sh - DO NOT EDIT'
144
145     FOUND=false
146     diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
147       grep -v '\.odex$' |
148       grep '>' |
149       cut -b 3- |
150       while read FULLPATH
151       do
152         if test $(basename $FULLPATH) = libgps.so -o $(basename $FULLPATH) = libcamera.so -o $(basename $FULLPATH) = libsecril-client.so
153         then
154           if test $FOUND = false
155           then
156             echo
157             echo '# Prebuilt libraries that are needed to build open-source libraries'
158             echo 'PRODUCT_COPY_FILES := \\'
159           else
160             echo \ \\\\
161           fi
162           FOUND=true
163           echo -n \ \ \ \ vendor/__MANUFACTURER__/__DEVICE__/proprietary/$(basename $FULLPATH):obj/lib/$(basename $FULLPATH)
164         fi
165       done
166     echo
167
168     FOUND=false
169     diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
170       grep -v '\.odex$' |
171       grep -v '\.apk$' |
172       grep '>' |
173       cut -b 3- |
174       while read FULLPATH
175       do
176         if test $FOUND = false
177         then
178           echo
179           echo -n '# All the blobs necessary for '
180           echo $DEVICENAME
181           echo 'PRODUCT_COPY_FILES += \\'
182         else
183           echo \ \\\\
184         fi
185         FOUND=true
186         echo -n \ \ \ \ vendor/__MANUFACTURER__/__DEVICE__/proprietary/$(basename $FULLPATH):$(echo $FULLPATH | cut -b 2-)
187       done
188     echo
189
190     FOUND=false
191     diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
192       grep '\.apk$' |
193       grep '>' |
194       cut -b 3- |
195       while read FULLPATH
196       do
197         if test $FOUND = false
198         then
199           echo
200           echo -n '# All the apks necessary for '
201           echo $DEVICENAME
202           echo 'PRODUCT_PACKAGES += \\'
203         else
204           echo \ \\\\
205         fi
206         FOUND=true
207         echo -n \ \ \ \ 
208         echo -n $(basename $FULLPATH) | sed 's/\.apk//g'
209       done
210     echo
211
212     echo 'EOF'
213
214     echo -n '(cat << EOF) | sed s/__DEVICE__/$DEVICE/g | sed s/__MANUFACTURER__/$MANUFACTURER/g > ../../../vendor/$MANUFACTURER/$DEVICE/'
215     echo 'proprietary/Android.mk'
216
217     echo '# Copyright (C) 2011 The Android Open Source Project'
218     echo '#'
219     echo '# Licensed under the Apache License, Version 2.0 (the "License");'
220     echo '# you may not use this file except in compliance with the License.'
221     echo '# You may obtain a copy of the License at'
222     echo '#'
223     echo '#      http://www.apache.org/licenses/LICENSE-2.0'
224     echo '#'
225     echo '# Unless required by applicable law or agreed to in writing, software'
226     echo '# distributed under the License is distributed on an "AS IS" BASIS,'
227     echo '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.'
228     echo '# See the License for the specific language governing permissions and'
229     echo '# limitations under the License.'
230     echo
231     echo -n '# This file is generated by device/__MANUFACTURER__/__DEVICE__/'
232     echo -n $FILESTYLE
233     echo '-files.sh - DO NOT EDIT'
234
235     FOUND=false
236     diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
237       grep '\.apk$' |
238       grep '>' |
239       cut -b 3- |
240       while read FULLPATH
241       do
242         if test $FOUND = false
243         then
244           echo
245           echo ifeq \(\$\(TARGET_DEVICE\),$DEVICENAME\)
246           echo LOCAL_PATH:=\$\(call my-dir\)
247           echo
248           echo -n '# Makefile rules for apks on '
249           echo $DEVICENAME
250         fi
251         FOUND=true
252         echo
253         echo -n '# '
254         echo $(basename $FULLPATH) | sed 's/\.apk//g'
255         echo
256         echo include \$\(CLEAR_VARS\)
257         echo
258         echo LOCAL_MODULE := $(basename $FULLPATH) | sed 's/\.apk//g'
259         echo LOCAL_SRC_FILES := \$\(LOCAL_MODULE\).apk
260         echo LOCAL_MODULE_CLASS := APPS
261         echo LOCAL_MODULE_TAGS := optional
262         echo LOCAL_CERTIFICATE := PRESIGNED
263         echo LOCAL_MODULE_SUFFIX := \$\(COMMON_ANDROID_PACKAGE_SUFFIX\)
264         echo include \$\(BUILD_PREBUILT\)
265       done
266       if test $FOUND = true
267       then
268         echo
269         echo endif
270       fi
271     echo
272
273     echo 'EOF'
274     echo
275     echo './setup-makefiles.sh'
276
277     ) > $ARCHIVEDIR/$DEVICENAME-$FILESTYLE-files.sh
278     cp $ARCHIVEDIR/$DEVICENAME-$FILESTYLE-files.sh device/$MANUFACTURERNAME/$DEVICENAME/$FILESTYLE-files.sh
279     chmod a+x device/$MANUFACTURERNAME/$DEVICENAME/$FILESTYLE-files.sh
280   done
281
282   (
283     cd device/$MANUFACTURERNAME/$DEVICENAME
284     git add .
285     git commit -m "auto-generated blob-handling scripts"
286     if test "$1" != "" -a "$2" != ""
287     then
288       echo uploading to server $1 branch $2
289       git push ssh://$1:29418/device/$MANUFACTURERNAME/$DEVICENAME.git HEAD:refs/for/$2
290     fi
291   )
292
293 done
294
295 echo * device/* |
296   tr \  \\n |
297   grep -v ^archive- |
298   grep -v ^device$ |
299   grep -v ^device/common$ |
300   xargs rm -rf