Chromium Code Reviews| Index: build/android/gyp/create_device_library_links.py |
| diff --git a/build/android/gyp/create_device_library_links.py b/build/android/gyp/create_device_library_links.py |
| index 48aa61eea997302ee2efa8ee0a5f41dfe14219f7..b0d41dc7e71ff17467fc71f2244896ed1d6a5686 100755 |
| --- a/build/android/gyp/create_device_library_links.py |
| +++ b/build/android/gyp/create_device_library_links.py |
| @@ -25,57 +25,75 @@ sys.path.append(BUILD_ANDROID_DIR) |
| from pylib import android_commands |
| from pylib.utils import apk_helper |
| +def RunShellCommand(adb, cmd, expect_output=False): |
| + output = adb.RunShellCommand(cmd) |
| -def RunLinkCommand(adb, target, link): |
| - cmd = ( |
| - 'rm ' + link + ' > /dev/null 2>&1 \n' |
| - 'ln -s ' + target + ' ' + link + '\n' |
| - ) |
| - result = adb.RunShellCommand(cmd) |
| - |
| - if result: |
| + if not expect_output and output: |
| raise Exception( |
| - 'Unexpected output creating links on device.\n' + |
| - '\n'.join(result)) |
| + 'Unexpected output running command.\n' + |
| + '\n'.join(output)) |
| -def CreateLinks(options): |
| +def CreateSymlinkScript(options): |
| libraries = build_utils.ReadJson(options.libraries_json) |
| + |
| + link_cmd = ( |
| + 'rm $APK_LIBRARIES_DIR/%(lib_basename)s > /dev/null 2>&1 \n' |
| + 'ln -s $STRIPPED_LIBRARIES_DIR/%(lib_basename)s ' |
| + '$APK_LIBRARIES_DIR/%(lib_basename)s \n' |
| + ) |
| + |
| + script = ('#!/bin/sh \n' |
| + '# usage: script.sh target_libraries_dir apk_libraries_dir \n') |
| + |
| + for lib in libraries: |
| + script += link_cmd % { 'lib_basename': lib } |
| + |
| + with open(options.script_host_path, 'w') as scriptfile: |
| + scriptfile.write(script) |
| + |
| + |
| +def TriggerSymlinkScript(options): |
| apk_package = apk_helper.GetPackageName(options.apk) |
| + apk_libraries_dir = '/data/data/' + apk_package + '/lib' |
|
Yaron
2013/04/18 18:06:25
'/data/data/%s/lib/' % apk_package
cjhopman
2013/04/18 21:05:23
Done.
|
| adb = android_commands.AndroidCommands() |
| - serial_number = adb.Adb().GetSerialNumber() |
| - for lib in libraries: |
| - host_path = os.path.join(options.libraries_dir, lib) |
| - def CreateLink(): |
| - link = '/data/data/' + apk_package + '/lib/' + lib |
| - target = options.target_dir + '/' + lib |
| - RunLinkCommand(adb, target, link) |
| + mkdir_cmd = 'mkdir ' + os.path.dirname(options.script_device_path) |
| + RunShellCommand(adb, mkdir_cmd, expect_output=True) |
|
Yaron
2013/04/18 18:06:25
You're just trying to avoid the directory already
cjhopman
2013/04/18 21:05:23
Done. I like that much better.
|
| + adb.PushIfNeeded(options.script_host_path, options.script_device_path) |
| + |
| + trigger_cmd = ( |
| + 'APK_LIBRARIES_DIR=%(apk_libraries_dir)s; ' |
| + 'STRIPPED_LIBRARIES_DIR=%(target_dir)s; ' |
| + '. %(script_device_path)s' |
| + ) % { |
| + 'apk_libraries_dir': apk_libraries_dir, |
| + 'target_dir': options.target_dir, |
| + 'script_device_path': options.script_device_path |
| + } |
| + RunShellCommand(adb, trigger_cmd) |
| - record_path = '%s.%s.link.md5.stamp' % (host_path, serial_number) |
| - md5_check.CallAndRecordIfStale( |
| - CreateLink, |
| - record_path=record_path, |
| - input_paths=[host_path]) |
| def main(argv): |
| parser = optparse.OptionParser() |
| parser.add_option('--apk', help='Path to the apk.') |
| + parser.add_option('--script-host-path', |
| + help='Path on the host for the symlink script.') |
| + parser.add_option('--script-device-path', |
| + help='Path on the device to push the created symlink script.') |
| parser.add_option('--libraries-json', |
| help='Path to the json list of native libraries.') |
| parser.add_option('--target-dir', |
| help='Device directory that contains the target libraries for symlinks.') |
| - parser.add_option('--libraries-dir', |
| - help='Directory that contains stripped libraries ' |
| - '(used to determine if a library has changed since last push).') |
| parser.add_option('--stamp', help='Path to touch on success.') |
| options, _ = parser.parse_args() |
| - required_options = ['apk', 'libraries_json', 'target_dir', 'libraries_dir'] |
|
Yaron
2013/04/18 18:06:25
Why is libraries_json not required?
cjhopman
2013/04/18 21:05:23
Done.
|
| + required_options = ['apk', 'target_dir'] |
| build_utils.CheckOptions(options, parser, required=required_options) |
| - CreateLinks(options) |
| + CreateSymlinkScript(options) |
| + TriggerSymlinkScript(options) |
| if options.stamp: |
|
Yaron
2013/04/18 18:06:25
You're never passing in the stamp anymore
cjhopman
2013/04/18 21:05:23
In all these scripts we have had --stamp as option
|
| build_utils.Touch(options.stamp) |