OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 """Creates an Android .apk.isolate for a given test target. |
| 7 |
| 8 This currently works by running "gn desc runtime_deps". In the future, it would |
| 9 be better if GN had a way to forcefully write gn runtime deps during generation |
| 10 (as if --runtime-deps-list-file were used for a target with |
| 11 record_runtime_deps = "path"). Then, this script can be changed to just convert |
| 12 the file into an .apk.isolate. |
| 13 """ |
| 14 |
| 15 import argparse |
| 16 import os |
| 17 import sys |
| 18 import pprint |
| 19 |
| 20 from util import build_utils |
| 21 |
| 22 |
| 23 _FILE_BLACKLIST = set(( |
| 24 # test_env.py are listed by test_support targets. Not needed on-device. |
| 25 'test_env.py', |
| 26 # The following are packaged into the .apk. |
| 27 'icudtl.dat', |
| 28 'natives_blob_32.bin', |
| 29 'natives_blob_64.bin', |
| 30 'snapshot_blob_32.bin', |
| 31 'snapshot_blob_64.bin', |
| 32 )) |
| 33 |
| 34 |
| 35 def _GnPath(): |
| 36 src_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, |
| 37 os.pardir) |
| 38 if sys.platform == 'linux2': |
| 39 subdir, exe = 'linux64', 'gn' |
| 40 elif sys.platform == 'darwin': |
| 41 subdir, exe = 'mac', 'gn' |
| 42 else: |
| 43 subdir, exe = 'win', 'gn.exe' |
| 44 return os.path.join(src_dir, 'buildtools', subdir, exe) |
| 45 |
| 46 |
| 47 def main(): |
| 48 # GN uses a lot of CPU and ninja may run multiple at the same time. Be nice. |
| 49 os.nice(10) |
| 50 |
| 51 parser = argparse.ArgumentParser(description=__doc__) |
| 52 parser.add_argument('path', help='path build was generated into') |
| 53 parser.add_argument('target', help='ninja target to generate the isolate for') |
| 54 parser.add_argument('--out-file', help='write to file rather than stdout') |
| 55 options = parser.parse_args() |
| 56 |
| 57 # Use the data deps defined by the library dependencies to avoid pulling in |
| 58 # deps required only by the test runner. |
| 59 deps = build_utils.CheckOutput([_GnPath(), 'desc', options.path, |
| 60 options.target, 'runtime_deps']).splitlines() |
| 61 # .so files are hardcoded by .gn to be included in runtime_deps, but since |
| 62 # they are embedded in the .apk, we don't need to push them to device. |
| 63 deps = (d for d in deps if not d.endswith('.so')) |
| 64 # lint rules are declared as data_deps to achieve better concurrency. |
| 65 deps = (d for d in deps if '__lint' not in d) |
| 66 # Blacklisted files. |
| 67 deps = (d for d in deps if os.path.basename(d) not in _FILE_BLACKLIST) |
| 68 |
| 69 # Make them relative to out-file. |
| 70 if options.out_file: |
| 71 subdir = os.path.relpath(options.path, os.path.dirname(options.out_file)) |
| 72 deps = (os.path.join(subdir, d) for d in deps) |
| 73 |
| 74 isolate_data = pprint.pformat({ |
| 75 'variables': { |
| 76 'files': sorted(deps), |
| 77 } |
| 78 }) |
| 79 |
| 80 if options.out_file: |
| 81 with open(options.out_file, 'w') as f: |
| 82 f.write(isolate_data + '\n') |
| 83 else: |
| 84 print isolate_data |
| 85 |
| 86 |
| 87 if __name__ == '__main__': |
| 88 sys.exit(main()) |
| 89 |
OLD | NEW |