Index: build/android/gyp/gen-android-test-isolate.py |
diff --git a/build/android/gyp/gen-android-test-isolate.py b/build/android/gyp/gen-android-test-isolate.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..d195b4b98c580e82782703a1ddab9a2ea8389776 |
--- /dev/null |
+++ b/build/android/gyp/gen-android-test-isolate.py |
@@ -0,0 +1,89 @@ |
+#!/usr/bin/env python |
+# Copyright 2016 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Creates an Android .apk.isolate for a given test target. |
+ |
+This currently works by running "gn desc runtime_deps". In the future, it would |
+be better if GN had a way to forcefully write gn runtime deps during generation |
+(as if --runtime-deps-list-file were used for a target with |
+record_runtime_deps = "path"). Then, this script can be changed to just convert |
+the file into an .apk.isolate. |
+""" |
+ |
+import argparse |
+import os |
+import sys |
+import pprint |
+ |
+from util import build_utils |
+ |
+ |
+_FILE_BLACKLIST = set(( |
+ # test_env.py are listed by test_support targets. Not needed on-device. |
+ 'test_env.py', |
+ # The following are packaged into the .apk. |
+ 'icudtl.dat', |
+ 'natives_blob_32.bin', |
+ 'natives_blob_64.bin', |
+ 'snapshot_blob_32.bin', |
+ 'snapshot_blob_64.bin', |
+)) |
+ |
+ |
+def _GnPath(): |
+ src_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, |
+ os.pardir) |
+ if sys.platform == 'linux2': |
+ subdir, exe = 'linux64', 'gn' |
+ elif sys.platform == 'darwin': |
+ subdir, exe = 'mac', 'gn' |
+ else: |
+ subdir, exe = 'win', 'gn.exe' |
+ return os.path.join(src_dir, 'buildtools', subdir, exe) |
+ |
+ |
+def main(): |
+ # GN uses a lot of CPU and ninja may run multiple at the same time. Be nice. |
+ os.nice(10) |
+ |
+ parser = argparse.ArgumentParser(description=__doc__) |
+ parser.add_argument('path', help='path build was generated into') |
+ parser.add_argument('target', help='ninja target to generate the isolate for') |
+ parser.add_argument('--out-file', help='write to file rather than stdout') |
+ options = parser.parse_args() |
+ |
+ # Use the data deps defined by the library dependencies to avoid pulling in |
+ # deps required only by the test runner. |
+ deps = build_utils.CheckOutput([_GnPath(), 'desc', options.path, |
+ options.target, 'runtime_deps']).splitlines() |
+ # .so files are hardcoded by .gn to be included in runtime_deps, but since |
+ # they are embedded in the .apk, we don't need to push them to device. |
+ deps = (d for d in deps if not d.endswith('.so')) |
+ # lint rules are declared as data_deps to achieve better concurrency. |
+ deps = (d for d in deps if '__lint' not in d) |
+ # Blacklisted files. |
+ deps = (d for d in deps if os.path.basename(d) not in _FILE_BLACKLIST) |
+ |
+ # Make them relative to out-file. |
+ if options.out_file: |
+ subdir = os.path.relpath(options.path, os.path.dirname(options.out_file)) |
+ deps = (os.path.join(subdir, d) for d in deps) |
+ |
+ isolate_data = pprint.pformat({ |
+ 'variables': { |
+ 'files': sorted(deps), |
+ } |
+ }) |
+ |
+ if options.out_file: |
+ with open(options.out_file, 'w') as f: |
+ f.write(isolate_data + '\n') |
+ else: |
+ print isolate_data |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main()) |
+ |