blob: d214d0b06c37116bc9a84d76e8bdb659677b1e4c [file] [log] [blame]
Justin Cohenae7265c2017-09-15 13:17:501#!/usr/bin/env python
2# Copyright 2017 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""
7Script used to install Xcode on the swarming bots.
8"""
9
Raul Tambre9e24293b2019-05-12 06:11:0710from __future__ import print_function
11
Justin Cohenae7265c2017-09-15 13:17:5012import os
13import shutil
14import subprocess
15import sys
16import tarfile
17import tempfile
18
19import mac_toolchain
20
21VERSION = '9A235'
22URL = 'gs://chrome-mac-sdk/ios-toolchain-9A235-1.tgz'
23REMOVE_DIR = '/Applications/Xcode9.0-Beta4.app/'
24OUTPUT_DIR = '/Applications/Xcode9.0.app/'
25
26def main():
27 # Check if it's already installed.
28 if os.path.exists(OUTPUT_DIR):
29 env = os.environ.copy()
30 env['DEVELOPER_DIR'] = OUTPUT_DIR
31 cmd = ['xcodebuild', '-version']
32 found_version = \
33 subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE).communicate()[0]
34 if VERSION in found_version:
Raul Tambre9e24293b2019-05-12 06:11:0735 print("Xcode %s already installed" % VERSION)
Justin Cohenae7265c2017-09-15 13:17:5036 sys.exit(0)
37
38 # Confirm old dir is there first.
39 if not os.path.exists(REMOVE_DIR):
Raul Tambre9e24293b2019-05-12 06:11:0740 print("Failing early since %s isn't there." % REMOVE_DIR)
Justin Cohenae7265c2017-09-15 13:17:5041 sys.exit(1)
42
43 # Download Xcode.
44 with tempfile.NamedTemporaryFile() as temp:
45 env = os.environ.copy()
46 env['PATH'] += ":/b/depot_tools"
47 subprocess.check_call(['gsutil.py', 'cp', URL, temp.name], env=env)
48 if os.path.exists(OUTPUT_DIR):
49 shutil.rmtree(OUTPUT_DIR)
50 if not os.path.exists(OUTPUT_DIR):
51 os.makedirs(OUTPUT_DIR)
52 tarfile.open(mode='r:gz', name=temp.name).extractall(path=OUTPUT_DIR)
53
54 # Accept license, call runFirstLaunch.
55 mac_toolchain.FinalizeUnpack(OUTPUT_DIR, 'ios')
56
57 # Set new Xcode as default.
58 subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', OUTPUT_DIR])
59
60 if os.path.exists(REMOVE_DIR):
61 shutil.rmtree(REMOVE_DIR)
62
63
64if __name__ == '__main__':
65 sys.exit(main())