Hal Canary | 6fe9d0a | 2018-10-29 16:39:10 -0400 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | # Copyright 2018 Google LLC. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | ''' |
| 7 | This script can be run with no arguments, in which case it will produce an |
| 8 | APK with native libraries for all four architectures: arm, arm64, x86, and |
| 9 | x64. You can instead list the architectures you want as arguments to this |
| 10 | script. For example: |
| 11 | |
| 12 | python make_universal_apk.py arm x86 |
| 13 | |
| 14 | The environment variables ANDROID_NDK and ANDROID_HOME must be set to the |
| 15 | locations of the Android NDK and SDK. |
| 16 | |
| 17 | Additionally, `ninja` should be in your path. |
| 18 | |
| 19 | It assumes that the source tree is in the desired state, e.g. by having |
| 20 | run 'python tools/git-sync-deps' in the root of the skia checkout. |
| 21 | |
| 22 | Also: |
| 23 | * If the environment variable SKQP_BUILD_DIR is set, many of the |
Hal Canary | 82e3afa | 2019-08-19 15:04:24 -0400 | [diff] [blame] | 24 | intermediate build objects will be placed here. |
Hal Canary | 6fe9d0a | 2018-10-29 16:39:10 -0400 | [diff] [blame] | 25 | * If the environment variable SKQP_OUTPUT_DIR is set, the final APK |
| 26 | will be placed in this directory. |
| 27 | * If the environment variable SKQP_DEBUG is set, Skia will be compiled |
| 28 | in debug mode. |
| 29 | ''' |
| 30 | |
| 31 | import os |
Hal Canary | 6fe9d0a | 2018-10-29 16:39:10 -0400 | [diff] [blame] | 32 | import sys |
Hal Canary | 6fe9d0a | 2018-10-29 16:39:10 -0400 | [diff] [blame] | 33 | |
Hal Canary | 82e3afa | 2019-08-19 15:04:24 -0400 | [diff] [blame] | 34 | import create_apk |
| 35 | import download_model |
Hal Canary | 6fe9d0a | 2018-10-29 16:39:10 -0400 | [diff] [blame] | 36 | |
Hal Canary | 82e3afa | 2019-08-19 15:04:24 -0400 | [diff] [blame] | 37 | def make_apk(opts): |
Hal Canary | 6fe9d0a | 2018-10-29 16:39:10 -0400 | [diff] [blame] | 38 | assert '/' in [os.sep, os.altsep] # 'a/b' over os.path.join('a', 'b') |
Hal Canary | 6fe9d0a | 2018-10-29 16:39:10 -0400 | [diff] [blame] | 39 | |
Hal Canary | 82e3afa | 2019-08-19 15:04:24 -0400 | [diff] [blame] | 40 | skia_dir = os.path.dirname(__file__) + '/../..' |
| 41 | create_apk.makedirs(opts.build_dir) |
| 42 | assets_dir = skia_dir + '/platform_tools/android/apps/skqp/src/main/assets' |
| 43 | gmkb = assets_dir + '/gmkb' |
| 44 | resources_path = assets_dir + '/resources' |
Hal Canary | 974200c | 2018-11-09 09:30:47 -0500 | [diff] [blame] | 45 | |
Hal Canary | 82e3afa | 2019-08-19 15:04:24 -0400 | [diff] [blame] | 46 | with create_apk.RemoveFiles(resources_path, gmkb): # always clean up |
| 47 | create_apk.remove(gmkb) |
| 48 | create_apk.make_symlinked_subdir(gmkb, opts.build_dir) |
Hal Canary | 6fe9d0a | 2018-10-29 16:39:10 -0400 | [diff] [blame] | 49 | |
Hal Canary | 82e3afa | 2019-08-19 15:04:24 -0400 | [diff] [blame] | 50 | create_apk.remove(resources_path) |
Hal Canary | d561155 | 2019-08-05 14:31:02 -0400 | [diff] [blame] | 51 | os.symlink('../../../../../../../resources', resources_path) |
Hal Canary | 69802c4 | 2019-01-11 16:27:35 -0500 | [diff] [blame] | 52 | |
Hal Canary | 82e3afa | 2019-08-19 15:04:24 -0400 | [diff] [blame] | 53 | if os.path.exists(assets_dir + '/files.checksum'): |
| 54 | download_model.main() |
Hal Canary | d561155 | 2019-08-05 14:31:02 -0400 | [diff] [blame] | 55 | else: |
| 56 | sys.stderr.write( |
Hal Canary | 82e3afa | 2019-08-19 15:04:24 -0400 | [diff] [blame] | 57 | '\n* * * Note: SkQP models are missing! * * *\n\n') |
| 58 | create_apk.create_apk(opts) |
Hal Canary | 6fe9d0a | 2018-10-29 16:39:10 -0400 | [diff] [blame] | 59 | |
| 60 | def main(): |
Hal Canary | 82e3afa | 2019-08-19 15:04:24 -0400 | [diff] [blame] | 61 | options = create_apk.SkQP_Build_Options() |
| 62 | if options.error: |
| 63 | sys.stderr.write(options.error + __doc__) |
Hal Canary | 6fe9d0a | 2018-10-29 16:39:10 -0400 | [diff] [blame] | 64 | sys.exit(1) |
Hal Canary | 82e3afa | 2019-08-19 15:04:24 -0400 | [diff] [blame] | 65 | options.write(sys.stdout) |
| 66 | make_apk(options) |
Hal Canary | 6fe9d0a | 2018-10-29 16:39:10 -0400 | [diff] [blame] | 67 | |
| 68 | if __name__ == '__main__': |
| 69 | main() |