OSDN Git Service

am 562d2080: am 523e077f: chmod the output scripts
[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="passion crespo crespo4g stingray wingray tuna toro"
47
48 ARCHIVEDIR=archive-$(date +%s)
49 mkdir $ARCHIVEDIR
50
51 repo sync
52 repo sync
53 repo sync
54
55 # Remove directory that breaks the build
56 rm -rf device/samsung/crespo4g/crespo4g_overlay
57
58 . build/envsetup.sh
59 for DEVICENAME in $DEVICES
60 do
61   rm -rf out
62   lunch full_$DEVICENAME-user
63   make -j32
64   cat out/target/product/$DEVICENAME/installed-files.txt |
65     cut -b 15- |
66     sort -f > $ARCHIVEDIR/$DEVICENAME-with.txt
67 done
68 rm -rf vendor
69 for DEVICENAME in $DEVICES
70 do
71   rm -rf out
72   lunch full_$DEVICENAME-user
73   make -j32
74   cat out/target/product/$DEVICENAME/installed-files.txt |
75     cut -b 15- |
76     sort -f > $ARCHIVEDIR/$DEVICENAME-without.txt
77 done
78
79 for DEVICENAME in $DEVICES
80 do
81   MANUFACTURERNAME=$( find device -type d | grep [^/]\*/[^/]\*/$DEVICENAME\$ | cut -f 2 -d / )
82   for FILESTYLE in extract unzip
83   do
84     (
85     echo '#!/bin/sh'
86     echo
87     echo '# Copyright (C) 2010 The Android Open Source Project'
88     echo '#'
89     echo '# Licensed under the Apache License, Version 2.0 (the "License");'
90     echo '# you may not use this file except in compliance with the License.'
91     echo '# You may obtain a copy of the License at'
92     echo '#'
93     echo '#      http://www.apache.org/licenses/LICENSE-2.0'
94     echo '#'
95     echo '# Unless required by applicable law or agreed to in writing, software'
96     echo '# distributed under the License is distributed on an "AS IS" BASIS,'
97     echo '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.'
98     echo '# See the License for the specific language governing permissions and'
99     echo '# limitations under the License.'
100     echo
101     echo '# This file is generated by device/common/generate-blob-scripts.sh - DO NOT EDIT'
102     echo
103     echo DEVICE=$DEVICENAME
104     echo MANUFACTURER=$MANUFACTURERNAME
105     echo
106     echo 'mkdir -p ../../../vendor/$MANUFACTURER/$DEVICE/proprietary'
107
108     diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
109       grep -v Nfc\.apk\$ |
110       grep -v Tag\.apk\$ |
111       grep -v libnfc\.so\$ |
112       grep -v libnfc_jni\.so\$ |
113       grep '>' |
114       cut -b 3- |
115       while read FULLPATH
116       do
117         if test $FILESTYLE = extract
118         then
119           echo adb pull $FULLPATH ../../../vendor/\$MANUFACTURER/\$DEVICE/proprietary/$(basename $FULLPATH)
120         else
121           echo unzip -j -o ../../../\${DEVICE}_update.zip $(echo $FULLPATH | cut -b 2-) -d ../../../vendor/\$MANUFACTURER/\$DEVICE/proprietary
122         fi
123         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
124         then
125           echo chmod 755 ../../../vendor/\$MANUFACTURER/\$DEVICE/proprietary/$(basename $FULLPATH)
126         fi
127       done
128     echo
129
130     echo -n '(cat << EOF) | sed s/__DEVICE__/$DEVICE/g | sed s/__MANUFACTURER__/$MANUFACTURER/g > ../../../vendor/$MANUFACTURER/$DEVICE/'
131     echo 'device-vendor-blobs.mk'
132
133     echo '# Copyright (C) 2010 The Android Open Source Project'
134     echo '#'
135     echo '# Licensed under the Apache License, Version 2.0 (the "License");'
136     echo '# you may not use this file except in compliance with the License.'
137     echo '# You may obtain a copy of the License at'
138     echo '#'
139     echo '#      http://www.apache.org/licenses/LICENSE-2.0'
140     echo '#'
141     echo '# Unless required by applicable law or agreed to in writing, software'
142     echo '# distributed under the License is distributed on an "AS IS" BASIS,'
143     echo '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.'
144     echo '# See the License for the specific language governing permissions and'
145     echo '# limitations under the License.'
146     echo
147     echo -n '# This file is generated by device/__MANUFACTURER__/__DEVICE__/'
148     echo -n $FILESTYLE
149     echo '-files.sh - DO NOT EDIT'
150
151     FOUND=false
152     diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
153       grep -v Nfc\.apk\$ |
154       grep -v Tag\.apk\$ |
155       grep -v libnfc\.so\$ |
156       grep -v libnfc_jni\.so\$ |
157       grep '>' |
158       cut -b 3- |
159       while read FULLPATH
160       do
161         if test $(basename $FULLPATH) = libgps.so -o $(basename $FULLPATH) = libcamera.so -o $(basename $FULLPATH) = libsecril-client.so
162         then
163           if test $FOUND = false
164           then
165             echo
166             echo '# Prebuilt libraries that are needed to build open-source libraries'
167             echo 'PRODUCT_COPY_FILES := \\'
168           else
169             echo \ \\\\
170           fi
171           FOUND=true
172           echo -n \ \ \ \ vendor/__MANUFACTURER__/__DEVICE__/proprietary/$(basename $FULLPATH):obj/lib/$(basename $FULLPATH)
173         fi
174       done
175     echo
176
177     FOUND=false
178     diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
179       grep -v Nfc\.apk\$ |
180       grep -v Tag\.apk\$ |
181       grep -v libnfc\.so\$ |
182       grep -v libnfc_jni\.so\$ |
183       grep '>' |
184       cut -b 3- |
185       while read FULLPATH
186       do
187         if test $FOUND = false
188         then
189           echo
190           echo -n '# All the blobs necessary for '
191           echo $DEVICENAME
192           echo 'PRODUCT_COPY_FILES += \\'
193         else
194           echo \ \\\\
195         fi
196         FOUND=true
197         echo -n \ \ \ \ vendor/__MANUFACTURER__/__DEVICE__/proprietary/$(basename $FULLPATH):$(echo $FULLPATH | cut -b 2-)
198       done
199     echo
200     echo 'EOF'
201     echo
202     echo './setup-makefiles.sh'
203
204     ) > $ARCHIVEDIR/$DEVICENAME-$FILESTYLE-files.sh
205     cp $ARCHIVEDIR/$DEVICENAME-$FILESTYLE-files.sh device/$MANUFACTURERNAME/$DEVICENAME/$FILESTYLE-files.sh
206     chmod a+x device/$MANUFACTURERNAME/$DEVICENAME/$FILESTYLE-files.sh
207   done
208
209   (
210     cd device/$MANUFACTURERNAME/$DEVICENAME
211     git add .
212     git commit -m "auto-generated blob-handling scripts"
213     if test "$1" != "" -a "$2" != ""
214     then
215       echo uploading to server $1 branch $2
216       git push ssh://$1:29418/device/$MANUFACTURERNAME/$DEVICENAME.git HEAD:refs/for/$2
217     fi
218   )
219
220 done
221
222 echo * device/* |
223   tr \  \\n |
224   grep -v ^archive- |
225   grep -v ^device$ |
226   grep -v ^device/common$ |
227   xargs rm -rf