diff --git a/engine/src/flutter/tools/android_library_cacher.py b/engine/src/flutter/tools/android_library_cacher.py new file mode 100755 index 0000000000..5cedc1985e --- /dev/null +++ b/engine/src/flutter/tools/android_library_cacher.py @@ -0,0 +1,61 @@ +#!/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']) + + # TODO(eseidel): Check the build.props, or find some way to avoid + # re-pulling every library every time. adb_gdb has code to do this + # but doesn't seem to notice when the set of needed libraries changed. + + library_regexp = re.compile(r'(?P/system/.*\.so)') + 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') + + dev_null = open(os.devnull, 'w') # Leaking. + to_pull = set(filter(None, map(library_from_line, maps_lines))) + to_pull.add('/system/bin/linker') # Unclear why but adb_gdb pulls this too. + for library_path in sorted(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, stderr=dev_null) + + +if __name__ == '__main__': + main() diff --git a/engine/src/flutter/tools/skydb b/engine/src/flutter/tools/skydb index 5320e273bd..ab84fae44b 100755 --- a/engine/src/flutter/tools/skydb +++ b/engine/src/flutter/tools/skydb @@ -137,7 +137,7 @@ class SkyDebugger(object): def sky_server_for_args(self, args): # FIXME: This is a hack. sky_server should just take a build_dir # not a magical "configuration" name. - configuration = os.path.basename(os.path.normpath(args.build_dir)) + configuration = os.path.basename(os.path.normpath(self.paths.build_dir)) server_root = self._server_root_for_url(args.url_or_path) sky_server = SkyServer(self.paths, SKY_SERVER_PORT, configuration, server_root) @@ -176,7 +176,7 @@ class SkyDebugger(object): # FIXME: This is probably not the right way to compute is_android # from the build directory? - gn_args = gn_args_from_build_dir(args.build_dir) + gn_args = gn_args_from_build_dir(self.paths.build_dir) is_android = 'android_sdk_version' in gn_args sky_server = self.sky_server_for_args(args) @@ -184,12 +184,12 @@ class SkyDebugger(object): self.pids['sky_server_port'] = sky_server.port self.pids['sky_server_root'] = sky_server.root - self.pids['build_dir'] = args.build_dir + self.pids['build_dir'] = self.paths.build_dir self.pids['sky_command_port'] = args.command_port if is_android: # Pray to the build/android gods in their misspelled tongue. - constants.SetOutputDirectort(args.build_dir) + constants.SetOutputDirectort(self.paths.build_dir) device = self._connect_to_device() self.pids['device_serial'] = device.GetDevice() @@ -409,8 +409,26 @@ class SkyDebugger(object): # Write out our pid file before we exec ourselves. self._write_pid_file(PID_FILE_PATH, self.pids) + # Pull down the system libraries this pid has already mapped in. + # TODO(eseidel): This does not handle dynamic loads well. + system_libs_root = '/tmp/device_libs' + library_cacher_path = os.path.join( + self.paths.sky_tools_directory, 'android_library_cacher.py') + subprocess.call([ + library_cacher_path, system_libs_root, self.pids['mojo_shell_pid'] + ]) + + # TODO(eseidel): adb_gdb does, this, unclear why solib-absolute-prefix + # doesn't make this explicit listing not necessary? + system_lib_dirs = subprocess.check_output([ + 'find', system_libs_root, + '-mindepth', '1', + '-maxdepth', '4', + '-type', 'd', + ]).strip().split('\n') + # TODO(eseidel): Need to sync down system libraries into a directory. - symbol_search_paths = [ + symbol_search_paths = system_lib_dirs + [ links_path, self.pids['build_dir'], ] @@ -425,6 +443,7 @@ class SkyDebugger(object): '--eval-command', 'target remote localhost:%s' % GDB_PORT, '--eval-command', 'set solib-search-path %s' % ':'.join(symbol_search_paths), + '--eval-command', 'set solib-absolute-prefix %s' % system_libs_root, ] print " ".join(gdb_command) # We don't want python listening for signals or anything, so exec diff --git a/engine/src/flutter/tools/skypy/paths.py b/engine/src/flutter/tools/skypy/paths.py index 8a7a6b5ddd..81b7e99397 100644 --- a/engine/src/flutter/tools/skypy/paths.py +++ b/engine/src/flutter/tools/skypy/paths.py @@ -10,6 +10,7 @@ class Paths(object): self.src_root = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, os.pardir, os.pardir)) self.sky_root = os.path.join(self.src_root, 'sky') - self.gen_root = os.path.join(self.src_root, build_directory, 'gen') + self.build_dir = os.path.join(self.src_root, build_directory) + self.gen_root = os.path.join(self.build_dir, 'gen') self.sky_tools_directory = os.path.join(self.src_root, 'sky', 'tools') self.mojo_shell_path = os.path.join(self.src_root, build_directory, 'mojo_shell')