Index: sky/tools/android_library_cacher.py |
diff --git a/sky/tools/android_library_cacher.py b/sky/tools/android_library_cacher.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..def60e85a28cb428aa6a5e315005b8b5e29205b9 |
--- /dev/null |
+++ b/sky/tools/android_library_cacher.py |
@@ -0,0 +1,55 @@ |
+#!/usr/bin/env python |
+# Copyright 2015 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. |
+ |
+import argparse |
+import re |
+import sys |
+import os |
+import logging |
+import subprocess |
+ |
+ |
+# TODO(eseidel): This should be shared with adb_gdb |
+def main(): |
+ logging.basicConfig(level=logging.INFO) |
+ parser = argparse.ArgumentParser( |
+ description='Pull all libraries used by a pid on android into a cache.') |
+ parser.add_argument('cache_root', type=str) |
+ parser.add_argument('pid', type=int) |
+ args = parser.parse_args() |
+ |
+ if not os.path.exists(args.cache_root): |
+ os.makedirs(args.cache_root) |
+ |
+ subprocess.check_call(['adb', 'root']) |
+ |
+ library_regexp = re.compile(r'(?P<library_path>/system/.*\.so)') |
abarth-chromium
2015/01/16 21:17:20
lib?
|
+ cat_maps_cmd = ['adb', 'shell', 'cat', '/proc/%s/maps' % args.pid] |
+ maps_lines = subprocess.check_output(cat_maps_cmd).strip().split('\n') |
+ # adb shell doesn't return the return code from the shell? |
+ if not maps_lines or 'No such file or directory' in maps_lines[0]: |
+ print 'Failed to get maps for pid %s on device.' % args.pid |
+ sys.exit(1) |
+ |
+ def library_from_line(line): |
+ result = library_regexp.search(line) |
+ if not result: |
+ return None |
+ return result.group('library_path') |
+ |
+ to_pull = sorted(set(filter(None, map(library_from_line, maps_lines)))) |
+ for library_path in to_pull: |
+ # Not using os.path.join since library_path is absolute. |
+ dest_file = os.path.normpath("%s/%s" % (args.cache_root, library_path)) |
+ dest_dir = os.path.dirname(dest_file) |
+ if not os.path.exists(dest_dir): |
+ os.makedirs(dest_dir) |
+ print '%s -> %s' % (library_path, dest_file) |
+ pull_cmd = ['adb', 'pull', library_path, dest_file] |
+ subprocess.check_call(pull_cmd) |
+ |
+ |
+if __name__ == '__main__': |
+ main() |