Skip to content

Commit

Permalink
Update test runner with internal change
Browse files Browse the repository at this point in the history
- Check the OS version when passing the Swift5 fallback libraries (required for Xcode 11.4 or later)
- Parse the xcresult bundle under Xcode 11 or later.
- Remove the Xcode 7 support.
  • Loading branch information
albertdai committed May 1, 2020
1 parent aa821f3 commit 3776f41
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 1,343 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ A tool for running prebuilt iOS tests on iOS real device and simulator.
- It supports iOS 7+ iOS real device, iOS simulator.
- It supports launch options configuration: test methods to run, additional
environment variables, additional arguments.
- It supports Xcode 7+.
- It supports Xcode 8+.

## Prerequisites
- Install Xcode (Xcode 7+). XCUITest support requires Xcode 8+.
- Install Xcode (Xcode 8+). XCUITest support requires Xcode 8+.
- [Install bazel](https://docs.bazel.build/install.html) (optional).
- py module [biplist](https://github.com/wooster/biplist).

Expand Down
4 changes: 4 additions & 0 deletions xctestrunner/shared/ios_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ class SimError(Exception):

class XcodebuildTestError(Exception):
"""Exception class for simulator error."""


class XcresultError(Exception):
"""Exception class for parsing xcresult error."""
26 changes: 26 additions & 0 deletions xctestrunner/shared/version_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Utility methods for Apple version."""


def GetVersionNumber(version_str):
"""Gets the version number of the given version string."""
parts = version_str.split('.')
version_number = int(parts[0]) * 100
if len(parts) > 1:
version_number += int(parts[1]) * 10
if len(parts) > 2:
version_number += int(parts[2])
return version_number
33 changes: 15 additions & 18 deletions xctestrunner/shared/xcode_info_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import subprocess

from xctestrunner.shared import ios_constants
from xctestrunner.shared import version_util


_xcode_version_number = None

Expand All @@ -27,19 +29,20 @@ def GetXcodeDeveloperPath():
return subprocess.check_output(('xcode-select', '-p')).strip()


# Xcode 11+'s Swift dylibs are configured in a way that does not allow them to load the correct
# libswiftFoundation.dylib file from libXCTestSwiftSupport.dylib. This bug only affects tests that
# run on simulators running iOS 12.1 or lower. To fix this bug, we need to provide explicit
# fallbacks to the correct Swift dylibs that have been packaged with Xcode. This method returns the
# path to that fallback directory.
# Xcode 11+'s Swift dylibs are configured in a way that does not allow them to
# load the correct libswiftFoundation.dylib file from
# libXCTestSwiftSupport.dylib. This bug only affects tests that run on fallbacks
# to the correct Swift dylibs that have been packaged with Xcode. This method
# returns the path to that fallback directory.
# See https://github.com/bazelbuild/rules_apple/issues/684 for context.
def GetSwift5FallbackLibsDir():
"""Gets the directory for Swift5 fallback libraries."""
relativePath = "Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0"
swiftLibsDir = os.path.join(GetXcodeDeveloperPath(), relativePath)
swiftLibPlatformDir = os.path.join(swiftLibsDir, ios_constants.SDK.IPHONESIMULATOR)
if os.path.exists(swiftLibPlatformDir):
return swiftLibPlatformDir
"""Gets the Swift5 fallback libraries directory."""
relative_path = 'Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0'
swift_libs_dir = os.path.join(GetXcodeDeveloperPath(), relative_path)
swift_lib_platform_dir = os.path.join(swift_libs_dir,
ios_constants.SDK.IPHONESIMULATOR)
if os.path.exists(swift_lib_platform_dir):
return swift_lib_platform_dir
return None


Expand All @@ -60,15 +63,9 @@ def GetXcodeVersionNumber():
# Build version 8C1002
output = subprocess.check_output(('xcodebuild', '-version'))
xcode_version = output.split('\n')[0].split(' ')[1]
parts = xcode_version.split('.')
xcode_version_number = int(parts[0]) * 100
if len(parts) > 1:
xcode_version_number += int(parts[1]) * 10
if len(parts) > 2:
xcode_version_number += int(parts[2])
# Add cache xcode_version_number to avoid calling subprocess multiple times.
# It is expected that no one changes xcode during the test runner working.
_xcode_version_number = xcode_version_number
_xcode_version_number = version_util.GetVersionNumber(xcode_version)
return _xcode_version_number


Expand Down
1 change: 0 additions & 1 deletion xctestrunner/simulator_control/simulator_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""The utility class for simulator."""

import json
Expand Down
Loading

0 comments on commit 3776f41

Please sign in to comment.