forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xcode_util.py
93 lines (74 loc) · 2.54 KB
/
xcode_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import distutils.version
import logging
import subprocess
LOGGER = logging.getLogger(__name__)
def select(xcode_app_path):
"""Invoke sudo xcode-select -s {xcode_app_path}
Raises:
subprocess.CalledProcessError on exit codes non zero
"""
cmd = [
'sudo',
'xcode-select',
'-s',
xcode_app_path,
]
LOGGER.debug('Selecting XCode with command: %s and "xcrun simctl list".' % cmd)
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
# This is to avoid issues caused by mixed usage of different Xcode versions on
# one machine.
xcrun_simctl_cmd = ['xcrun', 'simctl', 'list']
output += subprocess.check_output(xcrun_simctl_cmd, stderr=subprocess.STDOUT)
return output
def install(mac_toolchain, xcode_build_version, xcode_path):
"""Invoke mactoolchain to install the given xcode version.
Args:
xcode_build_version: (string) Xcode build version to install.
mac_toolchain: (string) Path to mac_toolchain command to install Xcode
See https://chromium.googlesource.com/infra/infra/+/master/go/src/infra/cmd/mac_toolchain/
xcode_path: (string) Path to install the contents of Xcode.app.
Raises:
subprocess.CalledProcessError on exit codes non zero
"""
cmd = [
mac_toolchain,
'install',
'-kind',
'ios',
'-xcode-version',
xcode_build_version.lower(),
'-output-dir',
xcode_path,
]
LOGGER.debug("Installing xcode with command: %s" % cmd)
output = subprocess.check_call(cmd, stderr=subprocess.STDOUT)
return output
def version():
"""Invoke xcodebuild -version
Raises:
subprocess.CalledProcessError on exit codes non zero
Returns:
version (12.0), build_version (12a6163b)
"""
cmd = [
'xcodebuild',
'-version',
]
LOGGER.debug("Checking XCode version with command: %s" % cmd)
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
output = output.splitlines()
# output sample:
# Xcode 12.0
# Build version 12A6159
logging.info(output)
version = output[0].decode('UTF-8').split(' ')[1]
build_version = output[1].decode('UTF-8').split(' ')[2].lower()
return version, build_version
def using_xcode_11_or_higher():
"""Returns true if using Xcode version 11 or higher."""
LOGGER.debug("Checking if Xcode version is 11 or higher")
return distutils.version.LooseVersion(
'11.0') <= distutils.version.LooseVersion(version()[0])