OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 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 |
| 5 # found in the LICENSE file. |
| 6 |
| 7 """Creates symlinks to native libraries for an APK. |
| 8 |
| 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 |
| 11 those native libraries. |
| 12 """ |
| 13 |
| 14 import json |
| 15 import optparse |
| 16 import os |
| 17 import sys |
| 18 |
| 19 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') |
| 20 sys.path.append(BUILD_ANDROID_DIR) |
| 21 |
| 22 from pylib import android_commands |
| 23 from pylib import build_utils |
| 24 from pylib.utils import apk_helper |
| 25 |
| 26 |
| 27 def CreateLinks(options): |
| 28 libraries = build_utils.ReadJson(options.libraries_json) |
| 29 apk_package = apk_helper.GetPackageName(options.apk) |
| 30 |
| 31 # There is a large (~100ms) overhead for each call to adb.RunShellCommand. To |
| 32 # avoid this overhead, craft a single command that creates all the links. |
| 33 link = '/data/data/' + apk_package + '/lib/$f' |
| 34 target = options.target_dir + '/$f' |
| 35 names = ' '.join(libraries) |
| 36 cmd = ( |
| 37 'for f in ' + names + '; do \n' + |
| 38 'rm ' + link + ' > /dev/null 2>&1 \n' + |
| 39 'ln -s ' + target + ' ' + link + '\n' + |
| 40 'done' |
| 41 ) |
| 42 |
| 43 adb = android_commands.AndroidCommands() |
| 44 result = adb.RunShellCommand(cmd) |
| 45 |
| 46 if result: |
| 47 raise Exception( |
| 48 'Unexpected output creating links on device.\n' + |
| 49 '\n'.join(result)) |
| 50 |
| 51 |
| 52 def main(argv): |
| 53 parser = optparse.OptionParser() |
| 54 parser.add_option('--apk', help='Path to the apk.') |
| 55 parser.add_option('--libraries-json', |
| 56 help='Path to the json list of native libraries.') |
| 57 parser.add_option('--target-dir', |
| 58 help='Device directory that contains the target libraries for symlinks.') |
| 59 parser.add_option('--stamp', help='Path to touch on success.') |
| 60 options, _ = parser.parse_args() |
| 61 |
| 62 required_options = ['apk', 'libraries_json', 'target_dir'] |
| 63 build_utils.CheckOptions(options, parser, required=required_options) |
| 64 |
| 65 CreateLinks(options) |
| 66 |
| 67 if options.stamp: |
| 68 build_utils.Touch(options.stamp) |
| 69 |
| 70 |
| 71 if __name__ == '__main__': |
| 72 sys.exit(main(sys.argv)) |
OLD | NEW |