1*635a8641SAndroid Build Coastguard Worker#!/usr/bin/env python 2*635a8641SAndroid Build Coastguard Worker# Copyright 2017 The Chromium Authors. All rights reserved. 3*635a8641SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be 4*635a8641SAndroid Build Coastguard Worker# found in the LICENSE file. 5*635a8641SAndroid Build Coastguard Worker 6*635a8641SAndroid Build Coastguard Worker""" 7*635a8641SAndroid Build Coastguard WorkerThis script runs swarming_xcode_install on the bots. It should be run when we 8*635a8641SAndroid Build Coastguard Workerneed to upgrade all the swarming testers. It: 9*635a8641SAndroid Build Coastguard Worker 1) Packages two python files into an isolate. 10*635a8641SAndroid Build Coastguard Worker 2) Runs the isolate on swarming machines that satisfy certain dimensions. 11*635a8641SAndroid Build Coastguard Worker 12*635a8641SAndroid Build Coastguard WorkerExample usage: 13*635a8641SAndroid Build Coastguard Worker $ ./build/run_swarming_xcode_install.py --luci_path ~/work/luci-py \ 14*635a8641SAndroid Build Coastguard Worker --swarming-server touch-swarming.appspot.com \ 15*635a8641SAndroid Build Coastguard Worker --isolate-server touch-isolate.appspot.com 16*635a8641SAndroid Build Coastguard Worker""" 17*635a8641SAndroid Build Coastguard Worker 18*635a8641SAndroid Build Coastguard Workerimport argparse 19*635a8641SAndroid Build Coastguard Workerimport os 20*635a8641SAndroid Build Coastguard Workerimport shutil 21*635a8641SAndroid Build Coastguard Workerimport subprocess 22*635a8641SAndroid Build Coastguard Workerimport sys 23*635a8641SAndroid Build Coastguard Workerimport tempfile 24*635a8641SAndroid Build Coastguard Worker 25*635a8641SAndroid Build Coastguard Worker 26*635a8641SAndroid Build Coastguard Workerdef main(): 27*635a8641SAndroid Build Coastguard Worker parser = argparse.ArgumentParser( 28*635a8641SAndroid Build Coastguard Worker description='Run swarming_xcode_install on the bots.') 29*635a8641SAndroid Build Coastguard Worker parser.add_argument('--luci_path', required=True, type=os.path.abspath) 30*635a8641SAndroid Build Coastguard Worker parser.add_argument('--swarming-server', required=True, type=str) 31*635a8641SAndroid Build Coastguard Worker parser.add_argument('--isolate-server', required=True, type=str) 32*635a8641SAndroid Build Coastguard Worker parser.add_argument('--batches', type=int, default=25, 33*635a8641SAndroid Build Coastguard Worker help="Run xcode install in batches of size |batches|.") 34*635a8641SAndroid Build Coastguard Worker parser.add_argument('--dimension', nargs=2, action='append') 35*635a8641SAndroid Build Coastguard Worker args = parser.parse_args() 36*635a8641SAndroid Build Coastguard Worker 37*635a8641SAndroid Build Coastguard Worker args.dimension = args.dimension or [] 38*635a8641SAndroid Build Coastguard Worker 39*635a8641SAndroid Build Coastguard Worker script_dir = os.path.dirname(os.path.abspath(__file__)) 40*635a8641SAndroid Build Coastguard Worker tmp_dir = tempfile.mkdtemp(prefix='swarming_xcode') 41*635a8641SAndroid Build Coastguard Worker try: 42*635a8641SAndroid Build Coastguard Worker print('Making isolate.') 43*635a8641SAndroid Build Coastguard Worker shutil.copyfile(os.path.join(script_dir, 'swarming_xcode_install.py'), 44*635a8641SAndroid Build Coastguard Worker os.path.join(tmp_dir, 'swarming_xcode_install.py')) 45*635a8641SAndroid Build Coastguard Worker shutil.copyfile(os.path.join(script_dir, 'mac_toolchain.py'), 46*635a8641SAndroid Build Coastguard Worker os.path.join(tmp_dir, 'mac_toolchain.py')) 47*635a8641SAndroid Build Coastguard Worker 48*635a8641SAndroid Build Coastguard Worker luci_client = os.path.join(args.luci_path, 'client') 49*635a8641SAndroid Build Coastguard Worker cmd = [ 50*635a8641SAndroid Build Coastguard Worker sys.executable, os.path.join(luci_client, 'isolateserver.py'), 'archive', 51*635a8641SAndroid Build Coastguard Worker '-I', args.isolate_server, tmp_dir, 52*635a8641SAndroid Build Coastguard Worker ] 53*635a8641SAndroid Build Coastguard Worker isolate_hash = subprocess.check_output(cmd).split()[0] 54*635a8641SAndroid Build Coastguard Worker 55*635a8641SAndroid Build Coastguard Worker print('Running swarming_xcode_install.') 56*635a8641SAndroid Build Coastguard Worker # TODO(crbug.com/765361): The dimensions below should be updated once 57*635a8641SAndroid Build Coastguard Worker # swarming for iOS is fleshed out, likely removing xcode_version 9 and 58*635a8641SAndroid Build Coastguard Worker # adding different dimensions. 59*635a8641SAndroid Build Coastguard Worker luci_tools = os.path.join(luci_client, 'tools') 60*635a8641SAndroid Build Coastguard Worker dimensions = [['pool', 'Chrome'], ['xcode_version', '9.0']] + args.dimension 61*635a8641SAndroid Build Coastguard Worker dim_args = [] 62*635a8641SAndroid Build Coastguard Worker for d in dimensions: 63*635a8641SAndroid Build Coastguard Worker dim_args += ['--dimension'] + d 64*635a8641SAndroid Build Coastguard Worker cmd = [ 65*635a8641SAndroid Build Coastguard Worker sys.executable, os.path.join(luci_tools, 'run_on_bots.py'), 66*635a8641SAndroid Build Coastguard Worker '--swarming', args.swarming_server, '--isolate-server', 67*635a8641SAndroid Build Coastguard Worker args.isolate_server, '--priority', '20', '--batches', str(args.batches), 68*635a8641SAndroid Build Coastguard Worker '--tags', 'name:run_swarming_xcode_install', 69*635a8641SAndroid Build Coastguard Worker ] + dim_args + ['--name', 'run_swarming_xcode_install', '--', isolate_hash, 70*635a8641SAndroid Build Coastguard Worker 'python', 'swarming_xcode_install.py', 71*635a8641SAndroid Build Coastguard Worker ] 72*635a8641SAndroid Build Coastguard Worker subprocess.check_call(cmd) 73*635a8641SAndroid Build Coastguard Worker print('All tasks completed.') 74*635a8641SAndroid Build Coastguard Worker 75*635a8641SAndroid Build Coastguard Worker finally: 76*635a8641SAndroid Build Coastguard Worker shutil.rmtree(tmp_dir) 77*635a8641SAndroid Build Coastguard Worker return 0 78*635a8641SAndroid Build Coastguard Worker 79*635a8641SAndroid Build Coastguard Worker 80*635a8641SAndroid Build Coastguard Workerif __name__ == '__main__': 81*635a8641SAndroid Build Coastguard Worker sys.exit(main()) 82