| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Creates symlinks to native libraries for an APK. | 7 """Creates symlinks to native libraries for an APK. |
| 8 | 8 |
| 9 The native libraries should have previously been pushed to the device (in | 9 The native libraries should have previously been pushed to the device (in |
| 10 options.target_dir). This script then creates links in an apk's lib/ folder to | 10 options.target_dir). This script then creates links in an apk's lib/ folder to |
| 11 those native libraries. | 11 those native libraries. |
| 12 """ | 12 """ |
| 13 | 13 |
| 14 import json | 14 import json |
| 15 import optparse | 15 import optparse |
| 16 import os | 16 import os |
| 17 import sys | 17 import sys |
| 18 | 18 |
| 19 from util import build_utils | 19 from util import build_utils |
| 20 from util import md5_check |
| 20 | 21 |
| 21 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') | 22 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') |
| 22 sys.path.append(BUILD_ANDROID_DIR) | 23 sys.path.append(BUILD_ANDROID_DIR) |
| 23 | 24 |
| 24 from pylib import android_commands | 25 from pylib import android_commands |
| 25 from pylib.utils import apk_helper | 26 from pylib.utils import apk_helper |
| 26 | 27 |
| 27 | 28 |
| 28 def CreateLinks(options): | 29 def RunLinkCommand(adb, target, link): |
| 29 libraries = build_utils.ReadJson(options.libraries_json) | |
| 30 apk_package = apk_helper.GetPackageName(options.apk) | |
| 31 | |
| 32 # There is a large (~100ms) overhead for each call to adb.RunShellCommand. To | |
| 33 # avoid this overhead, craft a single command that creates all the links. | |
| 34 link = '/data/data/' + apk_package + '/lib/$f' | |
| 35 target = options.target_dir + '/$f' | |
| 36 names = ' '.join(libraries) | |
| 37 cmd = ( | 30 cmd = ( |
| 38 'for f in ' + names + '; do \n' + | 31 'rm ' + link + ' > /dev/null 2>&1 \n' |
| 39 'rm ' + link + ' > /dev/null 2>&1 \n' + | 32 'ln -s ' + target + ' ' + link + '\n' |
| 40 'ln -s ' + target + ' ' + link + '\n' + | |
| 41 'done' | |
| 42 ) | 33 ) |
| 43 | |
| 44 adb = android_commands.AndroidCommands() | |
| 45 result = adb.RunShellCommand(cmd) | 34 result = adb.RunShellCommand(cmd) |
| 46 | 35 |
| 47 if result: | 36 if result: |
| 48 raise Exception( | 37 raise Exception( |
| 49 'Unexpected output creating links on device.\n' + | 38 'Unexpected output creating links on device.\n' + |
| 50 '\n'.join(result)) | 39 '\n'.join(result)) |
| 51 | 40 |
| 52 | 41 |
| 42 def CreateLinks(options): |
| 43 libraries = build_utils.ReadJson(options.libraries_json) |
| 44 apk_package = apk_helper.GetPackageName(options.apk) |
| 45 |
| 46 adb = android_commands.AndroidCommands() |
| 47 serial_number = adb.Adb().GetSerialNumber() |
| 48 for lib in libraries: |
| 49 host_path = os.path.join(options.libraries_dir, lib) |
| 50 |
| 51 md5_stamp = '%s.%s.link.md5' % (host_path, serial_number) |
| 52 md5_checker = md5_check.Md5Checker(stamp=md5_stamp, inputs=[host_path]) |
| 53 if md5_checker.IsStale(): |
| 54 link = '/data/data/' + apk_package + '/lib/' + lib |
| 55 target = options.target_dir + '/' + lib |
| 56 RunLinkCommand(adb, target, link) |
| 57 md5_checker.Write() |
| 58 |
| 59 |
| 53 def main(argv): | 60 def main(argv): |
| 54 parser = optparse.OptionParser() | 61 parser = optparse.OptionParser() |
| 55 parser.add_option('--apk', help='Path to the apk.') | 62 parser.add_option('--apk', help='Path to the apk.') |
| 56 parser.add_option('--libraries-json', | 63 parser.add_option('--libraries-json', |
| 57 help='Path to the json list of native libraries.') | 64 help='Path to the json list of native libraries.') |
| 58 parser.add_option('--target-dir', | 65 parser.add_option('--target-dir', |
| 59 help='Device directory that contains the target libraries for symlinks.') | 66 help='Device directory that contains the target libraries for symlinks.') |
| 67 parser.add_option('--libraries-dir', |
| 68 help='Directory that contains stripped libraries ' |
| 69 '(used to determine if a library has changed since last push).') |
| 60 parser.add_option('--stamp', help='Path to touch on success.') | 70 parser.add_option('--stamp', help='Path to touch on success.') |
| 61 options, _ = parser.parse_args() | 71 options, _ = parser.parse_args() |
| 62 | 72 |
| 63 required_options = ['apk', 'libraries_json', 'target_dir'] | 73 required_options = ['apk', 'libraries_json', 'target_dir', 'libraries_dir'] |
| 64 build_utils.CheckOptions(options, parser, required=required_options) | 74 build_utils.CheckOptions(options, parser, required=required_options) |
| 65 | 75 |
| 66 CreateLinks(options) | 76 CreateLinks(options) |
| 67 | 77 |
| 68 if options.stamp: | 78 if options.stamp: |
| 69 build_utils.Touch(options.stamp) | 79 build_utils.Touch(options.stamp) |
| 70 | 80 |
| 71 | 81 |
| 72 if __name__ == '__main__': | 82 if __name__ == '__main__': |
| 73 sys.exit(main(sys.argv)) | 83 sys.exit(main(sys.argv)) |
| OLD | NEW |