summaryrefslogtreecommitdiffstats
path: root/generate-blob-scripts.sh
blob: 4b3de720afc1b0c513c6159a9809c1818cb0cd7d (plain)
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
297
298
299
300
301
302
303
304
305
#!/usr/bin/env bash

# Copyright (C) 2010 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script auto-generates the scripts that manage the handling of the
# proprietary blobs necessary to build the Android Open-Source Project code
# for a variety of hardware targets

# It needs to be run from the root of a source tree that can repo sync,
# runs builds with and without the vendor tree, and uses the difference
# to generate the scripts.

# It can optionally upload the results to a Gerrit server for review.

# WARNING: It destroys the source tree. Don't leave anything precious there.

# Caveat: this script does many full builds (2 per device). It takes a while
# to run. It's best # suited for overnight runs on multi-CPU machines
# with a lot of RAM.

# Syntax: device/common/generate-blob-scripts.sh -f|--force [<server> <branch>]
#
# If the server and branch paramters are both present, the script will upload
# new files (if there's been any change) to the mentioned Gerrit server,
# in the specified branch.

if test "$1" != "-f" -a "$1" != "--force"
then
  echo This script must be run with the --force option
  exit 1
fi
shift

DEVICES="crespo crespo4g stingray panda toro maguro"

repo sync
repo sync
repo sync

ARCHIVEDIR=archive-$(date +%s)
if test -d archive-ref
then
  cp -R archive-ref $ARCHIVEDIR
else
  mkdir $ARCHIVEDIR

  . build/envsetup.sh
  for DEVICENAME in $DEVICES
  do
    rm -rf out
    lunch full_$DEVICENAME-user
    make -j32
    cat out/target/product/$DEVICENAME/installed-files.txt |
      cut -b 15- |
      sort -f > $ARCHIVEDIR/$DEVICENAME-with.txt
  done
  rm -rf vendor
  for DEVICENAME in $DEVICES
  do
    rm -rf out
    lunch full_$DEVICENAME-user
    make -j32
    cat out/target/product/$DEVICENAME/installed-files.txt |
      cut -b 15- |
      sort -f > $ARCHIVEDIR/$DEVICENAME-without.txt
  done
fi

for DEVICENAME in $DEVICES
do
  MANUFACTURERNAME=$( find device -type d | grep [^/]\*/[^/]\*/$DEVICENAME\$ | cut -f 2 -d / )
  for FILESTYLE in extract unzip
  do
    (
    echo '#!/bin/sh'
    echo
    echo '# Copyright (C) 2010 The Android Open Source Project'
    echo '#'
    echo '# Licensed under the Apache License, Version 2.0 (the "License");'
    echo '# you may not use this file except in compliance with the License.'
    echo '# You may obtain a copy of the License at'
    echo '#'
    echo '#      http://www.apache.org/licenses/LICENSE-2.0'
    echo '#'
    echo '# Unless required by applicable law or agreed to in writing, software'
    echo '# distributed under the License is distributed on an "AS IS" BASIS,'
    echo '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.'
    echo '# See the License for the specific language governing permissions and'
    echo '# limitations under the License.'
    echo
    echo '# This file is generated by device/common/generate-blob-scripts.sh - DO NOT EDIT'
    echo
    echo DEVICE=$DEVICENAME
    echo MANUFACTURER=$MANUFACTURERNAME
    echo
    echo 'mkdir -p ../../../vendor/$MANUFACTURER/$DEVICE/proprietary'

    diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
      grep -v '\.odex$' |
      grep '>' |
      cut -b 3- |
      while read FULLPATH
      do
        if test $FILESTYLE = extract
        then
          echo adb pull $FULLPATH ../../../vendor/\$MANUFACTURER/\$DEVICE/proprietary/$(basename $FULLPATH)
        else
          echo unzip -j -o ../../../\${DEVICE}_update.zip $(echo $FULLPATH | cut -b 2-) -d ../../../vendor/\$MANUFACTURER/\$DEVICE/proprietary
        fi
        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 -o $(basename $FULLPATH) = fRom
        then
          echo chmod 755 ../../../vendor/\$MANUFACTURER/\$DEVICE/proprietary/$(basename $FULLPATH)
        fi
      done
    echo

    echo -n '(cat << EOF) | sed s/__DEVICE__/$DEVICE/g | sed s/__MANUFACTURER__/$MANUFACTURER/g > ../../../vendor/$MANUFACTURER/$DEVICE/'
    echo 'device-vendor-blobs.mk'

    echo '# Copyright (C) 2010 The Android Open Source Project'
    echo '#'
    echo '# Licensed under the Apache License, Version 2.0 (the "License");'
    echo '# you may not use this file except in compliance with the License.'
    echo '# You may obtain a copy of the License at'
    echo '#'
    echo '#      http://www.apache.org/licenses/LICENSE-2.0'
    echo '#'
    echo '# Unless required by applicable law or agreed to in writing, software'
    echo '# distributed under the License is distributed on an "AS IS" BASIS,'
    echo '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.'
    echo '# See the License for the specific language governing permissions and'
    echo '# limitations under the License.'
    echo
    echo -n '# This file is generated by device/__MANUFACTURER__/__DEVICE__/'
    echo -n $FILESTYLE
    echo '-files.sh - DO NOT EDIT'

    FOUND=false
    diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
      grep -v '\.odex$' |
      grep '>' |
      cut -b 3- |
      while read FULLPATH
      do
        if test $(basename $FULLPATH) = libgps.so -o $(basename $FULLPATH) = libcamera.so -o $(basename $FULLPATH) = libsecril-client.so
        then
          if test $FOUND = false
          then
            echo
            echo '# Prebuilt libraries that are needed to build open-source libraries'
            echo 'PRODUCT_COPY_FILES := \\'
          else
            echo \ \\\\
          fi
          FOUND=true
          echo -n \ \ \ \ vendor/__MANUFACTURER__/__DEVICE__/proprietary/$(basename $FULLPATH):obj/lib/$(basename $FULLPATH)
        fi
      done
    echo

    FOUND=false
    diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
      grep -v '\.odex$' |
      grep -v '\.apk$' |
      grep '>' |
      cut -b 3- |
      while read FULLPATH
      do
        if test $FOUND = false
        then
          echo
          echo -n '# All the blobs necessary for '
          echo $DEVICENAME
          echo 'PRODUCT_COPY_FILES += \\'
        else
          echo \ \\\\
        fi
        FOUND=true
        echo -n \ \ \ \ vendor/__MANUFACTURER__/__DEVICE__/proprietary/$(basename $FULLPATH):$(echo $FULLPATH | cut -b 2-)
      done
    echo

    FOUND=false
    diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
      grep '\.apk$' |
      grep '>' |
      cut -b 3- |
      while read FULLPATH
      do
        if test $FOUND = false
        then
          echo
          echo -n '# All the apks necessary for '
          echo $DEVICENAME
          echo 'PRODUCT_PACKAGES += \\'
        else
          echo \ \\\\
        fi
        FOUND=true
        echo -n \ \ \ \ 
        echo -n $(basename $FULLPATH) | sed 's/\.apk//g'
      done
    echo

    echo
    echo 'EOF'

    echo

    echo -n '(cat << EOF) | sed s/__DEVICE__/$DEVICE/g | sed s/__MANUFACTURER__/$MANUFACTURER/g > ../../../vendor/$MANUFACTURER/$DEVICE/'
    echo 'proprietary/Android.mk'

    echo '# Copyright (C) 2011 The Android Open Source Project'
    echo '#'
    echo '# Licensed under the Apache License, Version 2.0 (the "License");'
    echo '# you may not use this file except in compliance with the License.'
    echo '# You may obtain a copy of the License at'
    echo '#'
    echo '#      http://www.apache.org/licenses/LICENSE-2.0'
    echo '#'
    echo '# Unless required by applicable law or agreed to in writing, software'
    echo '# distributed under the License is distributed on an "AS IS" BASIS,'
    echo '# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.'
    echo '# See the License for the specific language governing permissions and'
    echo '# limitations under the License.'
    echo
    echo -n '# This file is generated by device/__MANUFACTURER__/__DEVICE__/'
    echo -n $FILESTYLE
    echo '-files.sh - DO NOT EDIT'
    echo
    echo ifeq \(\\\$\(TARGET_DEVICE\),$DEVICENAME\)
    echo LOCAL_PATH:=\\\$\(call my-dir\)

    FOUND=false
    diff $ARCHIVEDIR/$DEVICENAME-without.txt $ARCHIVEDIR/$DEVICENAME-with.txt |
      grep '\.apk$' |
      grep '>' |
      cut -b 3- |
      while read FULLPATH
      do
        if test $FOUND = false
        then
          echo
          echo -n '# Module makefile rules for apks on '
          echo $DEVICENAME
        fi
        FOUND=true
        echo
        echo -n '# '
        echo $(basename $FULLPATH) | sed 's/\.apk//g'
        echo
        echo include \\\$\(CLEAR_VARS\)
        echo
        echo LOCAL_MODULE := $(basename $FULLPATH) | sed 's/\.apk//g'
        echo LOCAL_SRC_FILES := \\\$\(LOCAL_MODULE\).apk
        echo LOCAL_MODULE_CLASS := APPS
        echo LOCAL_MODULE_TAGS := optional
        echo LOCAL_CERTIFICATE := PRESIGNED
        echo LOCAL_MODULE_SUFFIX := \\\$\(COMMON_ANDROID_PACKAGE_SUFFIX\)
        echo include \\\$\(BUILD_PREBUILT\)
      done
    echo
    echo endif
    echo

    echo 'EOF'
    echo
    echo './setup-makefiles.sh'

    ) > $ARCHIVEDIR/$DEVICENAME-$FILESTYLE-files.sh
    cp $ARCHIVEDIR/$DEVICENAME-$FILESTYLE-files.sh device/$MANUFACTURERNAME/$DEVICENAME/$FILESTYLE-files.sh
    chmod a+x device/$MANUFACTURERNAME/$DEVICENAME/$FILESTYLE-files.sh
  done

  (
    cd device/$MANUFACTURERNAME/$DEVICENAME
    git add .
    git commit -m "$(echo -e 'auto-generated blob-handling scripts\n\nBug: 4295425')"
    if test "$1" != "" -a "$2" != ""
    then
      echo uploading to server $1 branch $2
      git push ssh://$1:29418/device/$MANUFACTURERNAME/$DEVICENAME.git HEAD:refs/for/$2/autoblobs
    fi
  )

done

echo * device/* |
  tr \  \\n |
  grep -v ^archive- |
  grep -v ^device$ |
  grep -v ^device/common$ |
  xargs rm -rf