Justin Cohen | ae7265c | 2017-09-15 13:17:50 | [diff] [blame] | 1 | #!/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 | """ |
| 7 | Script used to install Xcode on the swarming bots. |
| 8 | """ |
| 9 | |
Raul Tambre | 9e24293b | 2019-05-12 06:11:07 | [diff] [blame] | 10 | from __future__ import print_function |
| 11 | |
Justin Cohen | ae7265c | 2017-09-15 13:17:50 | [diff] [blame] | 12 | import os |
| 13 | import shutil |
| 14 | import subprocess |
| 15 | import sys |
| 16 | import tarfile |
| 17 | import tempfile |
| 18 | |
| 19 | import mac_toolchain |
| 20 | |
| 21 | VERSION = '9A235' |
| 22 | URL = 'gs://chrome-mac-sdk/ios-toolchain-9A235-1.tgz' |
| 23 | REMOVE_DIR = '/Applications/Xcode9.0-Beta4.app/' |
| 24 | OUTPUT_DIR = '/Applications/Xcode9.0.app/' |
| 25 | |
| 26 | def 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 Tambre | 9e24293b | 2019-05-12 06:11:07 | [diff] [blame] | 35 | print("Xcode %s already installed" % VERSION) |
Justin Cohen | ae7265c | 2017-09-15 13:17:50 | [diff] [blame] | 36 | sys.exit(0) |
| 37 | |
| 38 | # Confirm old dir is there first. |
| 39 | if not os.path.exists(REMOVE_DIR): |
Raul Tambre | 9e24293b | 2019-05-12 06:11:07 | [diff] [blame] | 40 | print("Failing early since %s isn't there." % REMOVE_DIR) |
Justin Cohen | ae7265c | 2017-09-15 13:17:50 | [diff] [blame] | 41 | 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 | |
| 64 | if __name__ == '__main__': |
| 65 | sys.exit(main()) |