• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"""Pushes native libraries to a device.
8
9"""
10
11import optparse
12import os
13import sys
14
15from util import build_device
16from util import build_utils
17from util import md5_check
18
19BUILD_ANDROID_DIR = os.path.abspath(
20    os.path.join(os.path.dirname(__file__), os.pardir))
21sys.path.append(BUILD_ANDROID_DIR)
22
23import devil_chromium
24from pylib import constants
25
26def DoPush(options):
27  libraries = build_utils.ParseGypList(options.libraries)
28
29  device = build_device.GetBuildDeviceFromPath(
30      options.build_device_configuration)
31  if not device:
32    return
33
34  serial_number = device.GetSerialNumber()
35  # A list so that it is modifiable in Push below.
36  needs_directory = [True]
37  for lib in libraries:
38    device_path = os.path.join(options.device_dir, lib)
39    host_path = os.path.join(options.libraries_dir, lib)
40
41    def Push():
42      if needs_directory:
43        device.RunShellCommand('mkdir -p ' + options.device_dir)
44        needs_directory[:] = [] # = False
45      device.PushChangedFiles([(os.path.abspath(host_path), device_path)])
46
47    record_path = '%s.%s.push.md5.stamp' % (host_path, serial_number)
48    md5_check.CallAndRecordIfStale(
49        Push,
50        record_path=record_path,
51        input_paths=[host_path],
52        input_strings=[device_path])
53
54
55def main(args):
56  args = build_utils.ExpandFileArgs(args)
57  parser = optparse.OptionParser()
58  parser.add_option('--libraries-dir',
59      help='Directory that contains stripped libraries.')
60  parser.add_option('--device-dir',
61      help='Device directory to push the libraries to.')
62  parser.add_option('--libraries',
63      help='List of native libraries.')
64  parser.add_option('--stamp', help='Path to touch on success.')
65  parser.add_option('--build-device-configuration',
66      help='Path to build device configuration.')
67  parser.add_option('--output-directory',
68      help='The output directory.')
69  options, _ = parser.parse_args(args)
70
71  required_options = ['libraries', 'device_dir', 'libraries']
72  build_utils.CheckOptions(options, parser, required=required_options)
73
74  devil_chromium.Initialize(
75      output_directory=os.path.abspath(options.output_directory))
76
77  DoPush(options)
78
79  if options.stamp:
80    build_utils.Touch(options.stamp)
81
82
83if __name__ == '__main__':
84  sys.exit(main(sys.argv[1:]))
85