Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: build/android/gyp/create_device_library_links.py

Issue 14017010: [Android] Use a script on the device for creating library symlinks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/gyp/apk_install.py ('k') | build/java_apk.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 from util import md5_check
21 21
22 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') 22 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..')
23 sys.path.append(BUILD_ANDROID_DIR) 23 sys.path.append(BUILD_ANDROID_DIR)
24 24
25 from pylib import android_commands 25 from pylib import android_commands
26 from pylib.utils import apk_helper 26 from pylib.utils import apk_helper
27 27
28 def RunShellCommand(adb, cmd):
29 output = adb.RunShellCommand(cmd)
28 30
29 def RunLinkCommand(adb, target, link): 31 if output:
30 cmd = (
31 'rm ' + link + ' > /dev/null 2>&1 \n'
32 'ln -s ' + target + ' ' + link + '\n'
33 )
34 result = adb.RunShellCommand(cmd)
35
36 if result:
37 raise Exception( 32 raise Exception(
38 'Unexpected output creating links on device.\n' + 33 'Unexpected output running command: ' + cmd + '\n' +
39 '\n'.join(result)) 34 '\n'.join(output))
40 35
41 36
42 def CreateLinks(options): 37 def CreateSymlinkScript(options):
43 libraries = build_utils.ReadJson(options.libraries_json) 38 libraries = build_utils.ReadJson(options.libraries_json)
39
40 link_cmd = (
41 'rm $APK_LIBRARIES_DIR/%(lib_basename)s > /dev/null 2>&1 \n'
42 'ln -s $STRIPPED_LIBRARIES_DIR/%(lib_basename)s '
43 '$APK_LIBRARIES_DIR/%(lib_basename)s \n'
44 )
45
46 script = '#!/bin/sh \n'
47
48 for lib in libraries:
49 script += link_cmd % { 'lib_basename': lib }
50
51 with open(options.script_host_path, 'w') as scriptfile:
52 scriptfile.write(script)
53
54
55 def TriggerSymlinkScript(options):
44 apk_package = apk_helper.GetPackageName(options.apk) 56 apk_package = apk_helper.GetPackageName(options.apk)
57 apk_libraries_dir = '/data/data/%s/lib' % apk_package
45 58
46 adb = android_commands.AndroidCommands() 59 adb = android_commands.AndroidCommands()
47 serial_number = adb.Adb().GetSerialNumber() 60 device_dir = os.path.dirname(options.script_device_path)
48 for lib in libraries: 61 mkdir_cmd = ('if [ ! -e %(dir)s ]; then mkdir %(dir)s; fi ' %
49 host_path = os.path.join(options.libraries_dir, lib) 62 { 'dir': device_dir })
50 def CreateLink(): 63 RunShellCommand(adb, mkdir_cmd)
51 link = '/data/data/' + apk_package + '/lib/' + lib 64 adb.PushIfNeeded(options.script_host_path, options.script_device_path)
52 target = options.target_dir + '/' + lib
53 RunLinkCommand(adb, target, link)
54 65
55 record_path = '%s.%s.link.md5.stamp' % (host_path, serial_number) 66 trigger_cmd = (
56 md5_check.CallAndRecordIfStale( 67 'APK_LIBRARIES_DIR=%(apk_libraries_dir)s; '
57 CreateLink, 68 'STRIPPED_LIBRARIES_DIR=%(target_dir)s; '
58 record_path=record_path, 69 '. %(script_device_path)s'
59 input_paths=[host_path]) 70 ) % {
71 'apk_libraries_dir': apk_libraries_dir,
72 'target_dir': options.target_dir,
73 'script_device_path': options.script_device_path
74 }
75 RunShellCommand(adb, trigger_cmd)
60 76
61 77
62 def main(argv): 78 def main(argv):
63 parser = optparse.OptionParser() 79 parser = optparse.OptionParser()
64 parser.add_option('--apk', help='Path to the apk.') 80 parser.add_option('--apk', help='Path to the apk.')
81 parser.add_option('--script-host-path',
82 help='Path on the host for the symlink script.')
83 parser.add_option('--script-device-path',
84 help='Path on the device to push the created symlink script.')
65 parser.add_option('--libraries-json', 85 parser.add_option('--libraries-json',
66 help='Path to the json list of native libraries.') 86 help='Path to the json list of native libraries.')
67 parser.add_option('--target-dir', 87 parser.add_option('--target-dir',
68 help='Device directory that contains the target libraries for symlinks.') 88 help='Device directory that contains the target libraries for symlinks.')
69 parser.add_option('--libraries-dir',
70 help='Directory that contains stripped libraries '
71 '(used to determine if a library has changed since last push).')
72 parser.add_option('--stamp', help='Path to touch on success.') 89 parser.add_option('--stamp', help='Path to touch on success.')
73 options, _ = parser.parse_args() 90 options, _ = parser.parse_args()
74 91
75 required_options = ['apk', 'libraries_json', 'target_dir', 'libraries_dir'] 92 required_options = ['apk', 'libraries_json', 'script_host_path',
93 'script_device_path', 'target_dir']
76 build_utils.CheckOptions(options, parser, required=required_options) 94 build_utils.CheckOptions(options, parser, required=required_options)
77 95
78 CreateLinks(options) 96 CreateSymlinkScript(options)
97 TriggerSymlinkScript(options)
79 98
80 if options.stamp: 99 if options.stamp:
81 build_utils.Touch(options.stamp) 100 build_utils.Touch(options.stamp)
82 101
83 102
84 if __name__ == '__main__': 103 if __name__ == '__main__':
85 sys.exit(main(sys.argv)) 104 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « build/android/gyp/apk_install.py ('k') | build/java_apk.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698