diff options
Diffstat (limited to 'build')
-rwxr-xr-x | build/android/gyp/apk_install.py | 8 | ||||
-rwxr-xr-x | build/android/gyp/create_device_library_links.py | 77 | ||||
-rw-r--r-- | build/java_apk.gypi | 22 |
3 files changed, 68 insertions, 39 deletions
diff --git a/build/android/gyp/apk_install.py b/build/android/gyp/apk_install.py index 8f1e69b..8cd1a60 100755 --- a/build/android/gyp/apk_install.py +++ b/build/android/gyp/apk_install.py @@ -27,6 +27,8 @@ def main(argv): help='Path to Android SDK tools.') parser.add_option('--apk-path', help='Path to .apk to install.') + parser.add_option('--install-record', + help='Path to install record (touched only when APK is installed).') parser.add_option('--stamp', help='Path to touch on success.') options, _ = parser.parse_args() @@ -37,10 +39,14 @@ def main(argv): 'install', '-r', options.apk_path] + def Install(): + build_utils.CheckCallDie(install_cmd) + build_utils.Touch(options.install_record) + serial_number = android_commands.AndroidCommands().Adb().GetSerialNumber() record_path = '%s.%s.md5.stamp' % (options.apk_path, serial_number) md5_check.CallAndRecordIfStale( - lambda: build_utils.CheckCallDie(install_cmd), + Install, record_path=record_path, input_paths=[options.apk_path], input_strings=install_cmd) diff --git a/build/android/gyp/create_device_library_links.py b/build/android/gyp/create_device_library_links.py index 48aa61e..5b8ee2b 100755 --- a/build/android/gyp/create_device_library_links.py +++ b/build/android/gyp/create_device_library_links.py @@ -25,57 +25,76 @@ sys.path.append(BUILD_ANDROID_DIR) from pylib import android_commands from pylib.utils import apk_helper +def RunShellCommand(adb, cmd): + 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 output: raise Exception( - 'Unexpected output creating links on device.\n' + - '\n'.join(result)) + 'Unexpected output running command: ' + cmd + '\n' + + '\n'.join(output)) -def CreateLinks(options): +def CreateSymlinkScript(options): libraries = build_utils.ReadJson(options.libraries_json) - apk_package = apk_helper.GetPackageName(options.apk) - adb = android_commands.AndroidCommands() - serial_number = adb.Adb().GetSerialNumber() + 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' + 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) + script += link_cmd % { 'lib_basename': lib } + + with open(options.script_host_path, 'w') as scriptfile: + scriptfile.write(script) + - record_path = '%s.%s.link.md5.stamp' % (host_path, serial_number) - md5_check.CallAndRecordIfStale( - CreateLink, - record_path=record_path, - input_paths=[host_path]) +def TriggerSymlinkScript(options): + apk_package = apk_helper.GetPackageName(options.apk) + apk_libraries_dir = '/data/data/%s/lib' % apk_package + + adb = android_commands.AndroidCommands() + device_dir = os.path.dirname(options.script_device_path) + mkdir_cmd = ('if [ ! -e %(dir)s ]; then mkdir %(dir)s; fi ' % + { 'dir': device_dir }) + RunShellCommand(adb, mkdir_cmd) + 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) 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'] + required_options = ['apk', 'libraries_json', 'script_host_path', + 'script_device_path', 'target_dir'] build_utils.CheckOptions(options, parser, required=required_options) - CreateLinks(options) + CreateSymlinkScript(options) + TriggerSymlinkScript(options) if options.stamp: build_utils.Touch(options.stamp) diff --git a/build/java_apk.gypi b/build/java_apk.gypi index ecf5474..5fbdd48 100644 --- a/build/java_apk.gypi +++ b/build/java_apk.gypi @@ -106,8 +106,10 @@ 'unsigned_apk_path': '<(intermediate_dir)/<(apk_name)-unsigned.apk', 'final_apk_path%': '<(PRODUCT_DIR)/apks/<(apk_name).apk', 'source_dir': '<(java_in_dir)/src', - 'apk_install_stamp': '<(intermediate_dir)/apk_install.stamp', + 'apk_install_record': '<(intermediate_dir)/apk_install.record.stamp', 'apk_package_native_libs_dir': '<(intermediate_dir)/libs', + 'symlink_script_host_path': '<(intermediate_dir)/create_symlinks.sh', + 'symlink_script_device_path': '/data/local/tmp/chromium/<(_target_name)/create_symlinks.sh', }, # Pass the jar path to the apk's "fake" jar target. This would be better as # direct_dependent_settings, but a variable set by a direct_dependent_settings @@ -210,22 +212,24 @@ 'includes': ['../build/android/push_libraries.gypi'], }, { - 'action_name': 'create_library_links', + 'action_name': 'create device library symlinks', 'message': 'Creating links on device for <(_target_name).', 'inputs': [ + '<(DEPTH)/build/android/gyp/util/build_utils.py', '<(DEPTH)/build/android/gyp/create_device_library_links.py', - '<(apk_install_stamp)', - '<(push_stamp)' + '<(apk_install_record)', + '<(ordered_libraries_file)', ], 'outputs': [ '<(link_stamp)' ], 'action': [ 'python', '<(DEPTH)/build/android/gyp/create_device_library_links.py', - '--apk=<(final_apk_path)', '--libraries-json=<(ordered_libraries_file)', - '--libraries-dir=<(libraries_source_dir)', + '--script-host-path=<(symlink_script_host_path)', + '--script-device-path=<(symlink_script_device_path)', '--target-dir=<(device_library_dir)', + '--apk=<(final_apk_path)', '--stamp=<(link_stamp)', ], }, @@ -273,18 +277,18 @@ '<(final_apk_path)', ], 'outputs': [ - '<(apk_install_stamp)', + '<(apk_install_record)', # If a user switches the connected device, the APK may need to be # installed even if there have been no changes. To ensure that the # APK on the device is always up-to-date, this step should always # be triggered. - '<(apk_install_stamp).fake', + '<(apk_install_record).fake', ], 'action': [ 'python', '<(DEPTH)/build/android/gyp/apk_install.py', '--android-sdk-tools=<(android_sdk_tools)', '--apk-path=<(final_apk_path)', - '--stamp=<(apk_install_stamp)' + '--install-record=<(apk_install_record)' ], }, ], |