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"""Gets and writes the configurations of the attached devices. 8 9This configuration is used by later build steps to determine which devices to 10install to and what needs to be installed to those devices. 11""" 12 13import optparse 14import os 15import sys 16 17from util import build_device 18from util import build_utils 19 20BUILD_ANDROID_DIR = os.path.abspath( 21 os.path.join(os.path.dirname(__file__), '..')) 22sys.path.append(BUILD_ANDROID_DIR) 23 24import devil_chromium 25 26 27def main(argv): 28 parser = optparse.OptionParser() 29 parser.add_option('--stamp', action='store') 30 parser.add_option('--output', action='store') 31 parser.add_option('--output-directory', action='store') 32 options, _ = parser.parse_args(argv) 33 34 devil_chromium.Initialize( 35 output_directory=os.path.abspath(options.output_directory)) 36 37 devices = build_device.GetAttachedDevices() 38 39 device_configurations = [] 40 for d in devices: 41 configuration, is_online, has_root = ( 42 build_device.GetConfigurationForDevice(d)) 43 44 if not is_online: 45 build_utils.PrintBigWarning( 46 '%s is not online. Skipping managed install for this device. ' 47 'Try rebooting the device to fix this warning.' % d) 48 continue 49 50 if not has_root: 51 build_utils.PrintBigWarning( 52 '"adb root" failed on device: %s\n' 53 'Skipping managed install for this device.' 54 % configuration['description']) 55 continue 56 57 device_configurations.append(configuration) 58 59 if len(device_configurations) == 0: 60 build_utils.PrintBigWarning( 61 'No valid devices attached. Skipping managed install steps.') 62 elif len(devices) > 1: 63 # Note that this checks len(devices) and not len(device_configurations). 64 # This way, any time there are multiple devices attached it is 65 # explicitly stated which device we will install things to even if all but 66 # one device were rejected for other reasons (e.g. two devices attached, 67 # one w/o root). 68 build_utils.PrintBigWarning( 69 'Multiple devices attached. ' 70 'Installing to the preferred device: ' 71 '%(id)s (%(description)s)' % (device_configurations[0])) 72 73 74 build_device.WriteConfigurations(device_configurations, options.output) 75 76 77if __name__ == '__main__': 78 sys.exit(main(sys.argv)) 79