Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / build / android / gyp / push_libraries.py
blobe586d0be6d577e19a0ba585d10df73702b0e9aeb
1 #!/usr/bin/env python
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.
7 """Pushes native libraries to a device.
9 """
11 import json
12 import optparse
13 import os
14 import sys
16 from util import build_utils
17 from util import md5_check
19 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..')
20 sys.path.append(BUILD_ANDROID_DIR)
22 from pylib import android_commands
25 def DoPush(options):
26 libraries = build_utils.ReadJson(options.libraries_json)
28 adb = android_commands.AndroidCommands()
29 serial_number = adb.Adb().GetSerialNumber()
30 needs_directory = True
31 for lib in libraries:
32 device_path = os.path.join(options.device_dir, lib)
33 host_path = os.path.join(options.libraries_dir, lib)
35 md5_stamp = '%s.%s.push.md5' % (host_path, serial_number)
36 md5_checker = md5_check.Md5Checker(stamp=md5_stamp, inputs=[host_path])
37 if md5_checker.IsStale():
38 if needs_directory:
39 adb.RunShellCommand('mkdir ' + options.device_dir)
40 needs_directory = False
41 adb.PushIfNeeded(host_path, device_path)
42 md5_checker.Write()
45 def main(argv):
46 parser = optparse.OptionParser()
47 parser.add_option('--libraries-dir',
48 help='Directory that contains stripped libraries.')
49 parser.add_option('--device-dir',
50 help='Device directory to push the libraries to.')
51 parser.add_option('--libraries-json',
52 help='Path to the json list of native libraries.')
53 parser.add_option('--stamp', help='Path to touch on success.')
54 options, _ = parser.parse_args()
56 required_options = ['libraries_dir', 'device_dir', 'libraries_json']
57 build_utils.CheckOptions(options, parser, required=required_options)
59 DoPush(options)
61 if options.stamp:
62 build_utils.Touch(options.stamp)
65 if __name__ == '__main__':
66 sys.exit(main(sys.argv))