Commit 7b6b842d authored by Jeff Yoon's avatar Jeff Yoon Committed by Commit Bot

[ios] refactor xcode calls, add logging

Move xcode calls into an xcode util, and add logging for cmd being run.
Print the test runner class being used for the run in logs so
we can trace which one's being used without walking through.

TBR=lindsayw@chromium.org

Bug: 1110060
Change-Id: I1134cfb39a18b05d3072a468d59503924fd264d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317772
Commit-Queue: Jeff Yoon <jeffyoon@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792082}
parent fa4b0e74
...@@ -29,6 +29,7 @@ import shard_util ...@@ -29,6 +29,7 @@ import shard_util
import test_runner import test_runner
import wpr_runner import wpr_runner
import xcodebuild_runner import xcodebuild_runner
import xcode_util as xcode
class Runner(): class Runner():
...@@ -69,17 +70,8 @@ class Runner(): ...@@ -69,17 +70,8 @@ class Runner():
if not os.path.exists(xcode_app_path): if not os.path.exists(xcode_app_path):
raise test_runner.XcodePathNotFoundError(xcode_app_path) raise test_runner.XcodePathNotFoundError(xcode_app_path)
subprocess.check_call([ xcode.install(mac_toolchain_cmd, xcode_build_version, xcode_app_path)
mac_toolchain_cmd, xcode.select(xcode_app_path)
'install',
'-kind',
'ios',
'-xcode-version',
xcode_build_version.lower(),
'-output-dir',
xcode_app_path,
])
self.xcode_select(xcode_app_path)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
# Flush buffers to ensure correct output ordering. # Flush buffers to ensure correct output ordering.
sys.stdout.flush() sys.stdout.flush()
...@@ -90,18 +82,6 @@ class Runner(): ...@@ -90,18 +82,6 @@ class Runner():
return True return True
def xcode_select(self, xcode_app_path):
"""Switch the default Xcode system-wide to `xcode_app_path`.
Raises subprocess.CalledProcessError on failure.
To be mocked in tests.
"""
subprocess.check_call([
'sudo',
'xcode-select',
'-switch',
xcode_app_path,
])
def run(self, args): def run(self, args):
""" """
...@@ -206,6 +186,7 @@ class Runner(): ...@@ -206,6 +186,7 @@ class Runner():
xctest=self.args.xctest, xctest=self.args.xctest,
) )
logging.info("Using test runner %s" % type(tr).__name__)
return 0 if tr.launch() else 1 return 0 if tr.launch() else 1
except test_runner.DeviceError as e: except test_runner.DeviceError as e:
sys.stderr.write(traceback.format_exc()) sys.stderr.write(traceback.format_exc())
...@@ -469,6 +450,7 @@ def main(args): ...@@ -469,6 +450,7 @@ def main(args):
test_runner.defaults_delete('com.apple.CoreSimulator', test_runner.defaults_delete('com.apple.CoreSimulator',
'FramebufferServerRendererPolicy') 'FramebufferServerRendererPolicy')
runner = Runner() runner = Runner()
logging.debug("Arg values passed for this run: %s" % args)
return runner.run(args) return runner.run(args)
......
# 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 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" % cmd)
output = subprocess.check_output(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
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