Commit 7f9b4bf8 authored by Sergey Berezin's avatar Sergey Berezin Committed by Commit Bot

[ios test_runner] Delete support for --xcode-version.

This removes the support for system-wide Xcode.

R=huangml@chromium.org

Bug: 835036
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I925587983d618593771522a28ccd4bdf0cd16d78
Reviewed-on: https://chromium-review.googlesource.com/1064829Reviewed-by: default avatarMenglu Huang <huangml@chromium.org>
Commit-Queue: Sergey Berezin <sergeyberezin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560337}
parent ee6a9e4d
#!/usr/bin/python
# Copyright 2016 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.
"""Finds Xcode installations, optionally switching to a desired version.
Usage:
./find_xcode.py -j /tmp/out.json -v 6.0.1
Finds Xcode 6.0.1 and switches to it. Writes a summary to /tmp/out.json
that includes the Xcode installations that were found, the Xcode version
that was active before running this script, and the Xcode version that
is active after running this script.
e.g. {
"installations": {
"/Applications/Xcode5.app": "5.1.1 (5B1008)",
"/Applications/Xcode6.app": "6.0 (6A313)",
"/Applications/Xcode6.0.1.app": "6.0.1 (6A317)",
"/Applications/Xcode6.1.app": "6.1 (6A1046a)",
},
"matches": {
"/Applications/Xcode6.0.1.app": "6.0.1 (6A317)",
},
"previous version": {
"path": "/Application/Xcode5.app",
"version": "5.1.1",
"build": "(5B1008)",
},
"current version": {
"path": "/Applications/Xcode6.0.1.app",
"version": "6.0.1",
"build": "6A317",
},
"found": true,
}
"""
import argparse
import json
import os
import subprocess
import sys
def get_xcodebuild_path(xcode_app):
"""Returns the path to xcodebuild under the given Xcode app.
Args:
xcode_app: The path to an installed Xcode.app. e.g. /Applications/Xcode.app.
Returns:
The absolute path to the xcodebuild binary under the given Xcode app.
"""
return os.path.join(
xcode_app,
'Contents',
'Developer',
'usr',
'bin',
'xcodebuild',
)
def get_xcode_version(xcodebuild):
"""Returns the Xcode version and build version.
Args:
xcodebuild: The absolute path to the xcodebuild binary.
Returns:
A tuple of (version string, build version string).
e.g. ("6.0.1", "6A317")
"""
# Sample output:
# Xcode 6.0.1
# Build version 6A317
out = subprocess.check_output([xcodebuild, '-version']).splitlines()
return out[0].split(' ')[-1], out[1].split(' ')[-1]
def get_current_xcode_info():
"""Returns the current Xcode path, version, and build number.
Returns:
A dict with 'path', 'version', and 'build' keys.
'path': The absolute path to the Xcode installation.
'version': The Xcode version.
'build': The Xcode build version.
"""
try:
version, build_version = get_xcode_version('xcodebuild')
path = subprocess.check_output(['xcode-select', '--print-path']).rstrip()
except subprocess.CalledProcessError:
version = build_version = path = None
return {
'path': path,
'version': version,
'build': build_version,
}
def find_xcode(target_version=None):
"""Finds all Xcode versions, switching to the given Xcode version.
Args:
target_version: The version of Xcode to switch to, or None if the
Xcode version should not be switched.
Returns:
A summary dict as described in the usage section above.
"""
xcode_info = {
'installations': {
},
'current version': {
},
}
if target_version:
xcode_info['found'] = False
xcode_info['matches'] = {}
xcode_info['previous version'] = get_current_xcode_info()
if xcode_info['previous version']['version'] == target_version:
xcode_info['found'] = True
for app in os.listdir(os.path.join('/', 'Applications')):
if app.startswith('Xcode'):
installation_path = os.path.join('/', 'Applications', app)
xcodebuild = get_xcodebuild_path(installation_path)
if os.path.exists(xcodebuild):
version, build_version = get_xcode_version(xcodebuild)
xcode_info['installations'][installation_path] = "%s (%s)" % (
version,
build_version,
)
if target_version and version == target_version:
xcode_info['matches'][installation_path] = "%s (%s)" % (
version,
build_version,
)
# If this is the first match, switch to it.
if not xcode_info['found']:
subprocess.check_call([
'sudo',
'xcode-select',
'-switch',
installation_path,
])
xcode_info['found'] = True
xcode_info['current version'] = get_current_xcode_info()
if target_version and not xcode_info['found']:
# Flush buffers to ensure correct output ordering for buildbot.
sys.stdout.flush()
sys.stderr.write('Target Xcode version not found: %s\n' % target_version)
sys.stderr.flush()
return xcode_info
def main(args):
xcode_info = find_xcode(args.version)
if args.json_file:
with open(args.json_file, 'w') as json_file:
json.dump(xcode_info, json_file)
if args.version and not xcode_info['found']:
return 1
return 0
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'-j',
'--json-file',
help='Location to write a JSON summary.',
metavar='file',
)
parser.add_argument(
'-v',
'--version',
help='Xcode version to find and switch to.',
metavar='ver',
)
sys.exit(main(parser.parse_args()))
...@@ -42,7 +42,6 @@ def main(): ...@@ -42,7 +42,6 @@ def main():
args.iossim, args.iossim,
args.platform, args.platform,
args.version, args.version,
args.xcode_version,
args.xcode_build_version, args.xcode_build_version,
args.out_dir, args.out_dir,
env_vars=args.env_var, env_vars=args.env_var,
...@@ -57,7 +56,6 @@ def main(): ...@@ -57,7 +56,6 @@ def main():
else: else:
tr = test_runner.DeviceTestRunner( tr = test_runner.DeviceTestRunner(
args.app, args.app,
args.xcode_version,
args.xcode_build_version, args.xcode_build_version,
args.out_dir, args.out_dir,
env_vars=args.env_var, env_vars=args.env_var,
...@@ -171,14 +169,9 @@ def parse_args(): ...@@ -171,14 +169,9 @@ def parse_args():
'-b', '-b',
'--xcode-build-version', '--xcode-build-version',
help='Xcode build version to install.', help='Xcode build version to install.',
required=True,
metavar='build_id', metavar='build_id',
) )
parser.add_argument(
'-x',
'--xcode-version',
help='Version of Xcode to use. DEPRECATED by --xcode-build-version.',
metavar='ver',
)
parser.add_argument( parser.add_argument(
'--xcode-path', '--xcode-path',
metavar='PATH', metavar='PATH',
...@@ -208,10 +201,6 @@ def parse_args(): ...@@ -208,10 +201,6 @@ def parse_args():
parser.error( parser.error(
'must specify all or none of -i/--iossim, -p/--platform, -v/--version') 'must specify all or none of -i/--iossim, -p/--platform, -v/--version')
if not (bool(args.xcode_version) ^ bool(args.xcode_build_version)):
parser.error(
'must specify exactly one of --xcode-build-version or --xcode-version')
args_json = json.loads(args.args_json) args_json = json.loads(args.args_json)
args.env_var = args.env_var or [] args.env_var = args.env_var or []
args.env_var.extend(args_json.get('env_var', [])) args.env_var.extend(args_json.get('env_var', []))
......
...@@ -21,7 +21,6 @@ import time ...@@ -21,7 +21,6 @@ import time
from multiprocessing import pool from multiprocessing import pool
import find_xcode
import gtest_utils import gtest_utils
import xctest_utils import xctest_utils
...@@ -211,6 +210,29 @@ def install_xcode(xcode_build_version, mac_toolchain_cmd, xcode_app_path): ...@@ -211,6 +210,29 @@ def install_xcode(xcode_build_version, mac_toolchain_cmd, xcode_app_path):
return True return True
def get_current_xcode_info():
"""Returns the current Xcode path, version, and build number.
Returns:
A dict with 'path', 'version', and 'build' keys.
'path': The absolute path to the Xcode installation.
'version': The Xcode version.
'build': The Xcode build version.
"""
try:
out = subprocess.check_output(['xcodebuild', '-version']).splitlines()
version, build_version = out[0].split(' ')[-1], out[1].split(' ')[-1]
path = subprocess.check_output(['xcode-select', '--print-path']).rstrip()
except subprocess.CalledProcessError:
version = build_version = path = None
return {
'path': path,
'version': version,
'build': build_version,
}
def shard_xctest(object_path, shards, test_cases=None): def shard_xctest(object_path, shards, test_cases=None):
"""Gets EarlGrey test methods inside a test target and splits them into shards """Gets EarlGrey test methods inside a test target and splits them into shards
...@@ -257,7 +279,6 @@ class TestRunner(object): ...@@ -257,7 +279,6 @@ class TestRunner(object):
def __init__( def __init__(
self, self,
app_path, app_path,
xcode_version,
xcode_build_version, xcode_build_version,
out_dir, out_dir,
env_vars=None, env_vars=None,
...@@ -273,8 +294,6 @@ class TestRunner(object): ...@@ -273,8 +294,6 @@ class TestRunner(object):
Args: Args:
app_path: Path to the compiled .app to run. app_path: Path to the compiled .app to run.
xcode_version: (deprecated by xcode_build_version) Version of Xcode to use
when running the test.
xcode_build_version: Xcode build version to install before running tests. xcode_build_version: Xcode build version to install before running tests.
out_dir: Directory to emit test data into. out_dir: Directory to emit test data into.
env_vars: List of environment variables to pass to the test itself. env_vars: List of environment variables to pass to the test itself.
...@@ -297,13 +316,10 @@ class TestRunner(object): ...@@ -297,13 +316,10 @@ class TestRunner(object):
if not os.path.exists(app_path): if not os.path.exists(app_path):
raise AppNotFoundError(app_path) raise AppNotFoundError(app_path)
if xcode_build_version:
if not install_xcode(xcode_build_version, mac_toolchain, xcode_path): if not install_xcode(xcode_build_version, mac_toolchain, xcode_path):
raise XcodeVersionNotFoundError(xcode_build_version) raise XcodeVersionNotFoundError(xcode_build_version)
elif not find_xcode.find_xcode(xcode_version)['found']:
raise XcodeVersionNotFoundError(xcode_version)
xcode_info = find_xcode.get_current_xcode_info() xcode_info = get_current_xcode_info()
print 'Using Xcode version %s build %s at %s' % ( print 'Using Xcode version %s build %s at %s' % (
xcode_info['version'], xcode_info['build'], xcode_info['path']) xcode_info['version'], xcode_info['build'], xcode_info['path'])
...@@ -324,7 +340,6 @@ class TestRunner(object): ...@@ -324,7 +340,6 @@ class TestRunner(object):
self.shards = shards or 1 self.shards = shards or 1
self.test_args = test_args or [] self.test_args = test_args or []
self.test_cases = test_cases or [] self.test_cases = test_cases or []
self.xcode_version = xcode_version
self.xctest_path = '' self.xctest_path = ''
self.test_results = {} self.test_results = {}
...@@ -583,7 +598,6 @@ class SimulatorTestRunner(TestRunner): ...@@ -583,7 +598,6 @@ class SimulatorTestRunner(TestRunner):
iossim_path, iossim_path,
platform, platform,
version, version,
xcode_version,
xcode_build_version, xcode_build_version,
out_dir, out_dir,
env_vars=None, env_vars=None,
...@@ -604,8 +618,6 @@ class SimulatorTestRunner(TestRunner): ...@@ -604,8 +618,6 @@ class SimulatorTestRunner(TestRunner):
by running "iossim -l". e.g. "iPhone 5s", "iPad Retina". by running "iossim -l". e.g. "iPhone 5s", "iPad Retina".
version: Version of iOS the platform should be running. Supported values version: Version of iOS the platform should be running. Supported values
can be found by running "iossim -l". e.g. "9.3", "8.2", "7.1". can be found by running "iossim -l". e.g. "9.3", "8.2", "7.1".
xcode_version: (deprecated by xcode_build_version) Version of Xcode to use
when running the test.
xcode_build_version: Xcode build version to install before running tests. xcode_build_version: Xcode build version to install before running tests.
out_dir: Directory to emit test data into. out_dir: Directory to emit test data into.
env_vars: List of environment variables to pass to the test itself. env_vars: List of environment variables to pass to the test itself.
...@@ -626,7 +638,6 @@ class SimulatorTestRunner(TestRunner): ...@@ -626,7 +638,6 @@ class SimulatorTestRunner(TestRunner):
""" """
super(SimulatorTestRunner, self).__init__( super(SimulatorTestRunner, self).__init__(
app_path, app_path,
xcode_version,
xcode_build_version, xcode_build_version,
out_dir, out_dir,
env_vars=env_vars, env_vars=env_vars,
...@@ -899,7 +910,6 @@ class DeviceTestRunner(TestRunner): ...@@ -899,7 +910,6 @@ class DeviceTestRunner(TestRunner):
def __init__( def __init__(
self, self,
app_path, app_path,
xcode_version,
xcode_build_version, xcode_build_version,
out_dir, out_dir,
env_vars=None, env_vars=None,
...@@ -916,8 +926,6 @@ class DeviceTestRunner(TestRunner): ...@@ -916,8 +926,6 @@ class DeviceTestRunner(TestRunner):
Args: Args:
app_path: Path to the compiled .app to run. app_path: Path to the compiled .app to run.
xcode_version: (deprecated by xcode_build_version) Version of Xcode to use
when running the test.
xcode_build_version: Xcode build version to install before running tests. xcode_build_version: Xcode build version to install before running tests.
out_dir: Directory to emit test data into. out_dir: Directory to emit test data into.
env_vars: List of environment variables to pass to the test itself. env_vars: List of environment variables to pass to the test itself.
...@@ -939,7 +947,6 @@ class DeviceTestRunner(TestRunner): ...@@ -939,7 +947,6 @@ class DeviceTestRunner(TestRunner):
""" """
super(DeviceTestRunner, self).__init__( super(DeviceTestRunner, self).__init__(
app_path, app_path,
xcode_version,
xcode_build_version, xcode_build_version,
out_dir, out_dir,
env_vars=env_vars, env_vars=env_vars,
......
...@@ -120,9 +120,7 @@ class SimulatorTestRunnerTest(TestCase): ...@@ -120,9 +120,7 @@ class SimulatorTestRunnerTest(TestCase):
def install_xcode(build, mac_toolchain_cmd, xcode_app_path): def install_xcode(build, mac_toolchain_cmd, xcode_app_path):
return True return True
self.mock(test_runner.find_xcode, 'find_xcode', self.mock(test_runner, 'get_current_xcode_info', lambda: {
lambda _: {'found': True})
self.mock(test_runner.find_xcode, 'get_current_xcode_info', lambda: {
'version': 'test version', 'build': 'test build', 'path': 'test/path'}) 'version': 'test version', 'build': 'test build', 'path': 'test/path'})
self.mock(test_runner, 'install_xcode', install_xcode) self.mock(test_runner, 'install_xcode', install_xcode)
self.mock(test_runner.subprocess, 'check_output', self.mock(test_runner.subprocess, 'check_output',
...@@ -354,9 +352,7 @@ class DeviceTestRunnerTest(TestCase): ...@@ -354,9 +352,7 @@ class DeviceTestRunnerTest(TestCase):
def install_xcode(build, mac_toolchain_cmd, xcode_app_path): def install_xcode(build, mac_toolchain_cmd, xcode_app_path):
return True return True
self.mock(test_runner.find_xcode, 'find_xcode', self.mock(test_runner, 'get_current_xcode_info', lambda: {
lambda _: {'found': True})
self.mock(test_runner.find_xcode, 'get_current_xcode_info', lambda: {
'version': 'test version', 'build': 'test build', 'path': 'test/path'}) 'version': 'test version', 'build': 'test build', 'path': 'test/path'})
self.mock(test_runner, 'install_xcode', install_xcode) self.mock(test_runner, 'install_xcode', install_xcode)
self.mock(test_runner.subprocess, 'check_output', self.mock(test_runner.subprocess, 'check_output',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment