Skip to content

Commit

Permalink
Fix compatibility issues with older Swift versions
Browse files Browse the repository at this point in the history
Drops support for Xcode 11.7 (Swift 5.2.4) due to issues resolving
overloaded methods.
  • Loading branch information
andrewchang-bird committed Aug 2, 2021
1 parent 772b946 commit 65f5d3a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 42 deletions.
38 changes: 0 additions & 38 deletions .github/workflows/build-framework-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,41 +107,3 @@ jobs:
run: make clean-test
- name: Cached Test
run: make test

build-xcode-11_7:
name: Xcode 11.7 toolchain
runs-on: macOS-latest

steps:
- uses: actions/checkout@v2
- name: Set Up Environment
run: sudo xcode-select -s /Applications/Xcode_11.7.app/Contents/Developer
- name: Print Debug Info
run: make print-debug-info
- name: Set Up Project
run: make setup-project
- name: Clean
run: make clean
- name: Build Framework
run: make build-framework
- name: Build and Install CLI
run: |
make print-debug-info | grep "Mockingbird rpath: /var/tmp/mockingbird/$(make get-version)/libs"
PREFIX=$(pwd) HERMETIC=1 make print-debug-info
PREFIX=$(pwd) HERMETIC=1 make install
- name: Set Up Target
run: |
./bin/mockingbird install \
--target MockingbirdTests \
--source MockingbirdTestsHost \
--support Sources/MockingbirdSupport \
--output Tests/MockingbirdTests/Mocks/MockingbirdTestsHostMocks.generated.swift \
--header '// Header line 1' '// Header line 2' \
--diagnostics all \
--loglevel verbose \
--prune stub \
--verbose
- name: Test
run: make clean-test
- name: Cached Test
run: make test
4 changes: 4 additions & 0 deletions Mockingbird.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
28C8E5DB26A64D6C00C68A1D /* MKBInvocationHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 28C8E5D926A64D6C00C68A1D /* MKBInvocationHandler.h */; };
28C8E5DC26A64D6C00C68A1D /* MKBInvocationHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 28C8E5DA26A64D6C00C68A1D /* MKBInvocationHandler.m */; };
28DAD96E251BDD66001A0B3F /* Project.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28DAD96D251BDD66001A0B3F /* Project.swift */; };
28DDDFC126B8571D002556C7 /* DynamicCast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28DDDFC026B8571D002556C7 /* DynamicCast.swift */; };
8356225C26A94CBE005CD5C5 /* TargetDescriptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8356225B26A94CBE005CD5C5 /* TargetDescriptionTests.swift */; };
D314ED7F24CE1C10000CC23D /* GenericsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D314ED7E24CE1C10000CC23D /* GenericsTests.swift */; };
D3643B6C247B78A5002DF069 /* Function.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3643B6B247B78A4002DF069 /* Function.swift */; };
Expand Down Expand Up @@ -586,6 +587,7 @@
28C8E5D926A64D6C00C68A1D /* MKBInvocationHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MKBInvocationHandler.h; sourceTree = "<group>"; };
28C8E5DA26A64D6C00C68A1D /* MKBInvocationHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MKBInvocationHandler.m; sourceTree = "<group>"; };
28DAD96D251BDD66001A0B3F /* Project.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Project.swift; sourceTree = "<group>"; };
28DDDFC026B8571D002556C7 /* DynamicCast.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicCast.swift; sourceTree = "<group>"; };
8356225B26A94CBE005CD5C5 /* TargetDescriptionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TargetDescriptionTests.swift; sourceTree = "<group>"; };
942B00CDCB48ADC877A01AEE /* MockingbirdTestsHostMocks.generated.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; name = MockingbirdTestsHostMocks.generated.swift; path = Tests/MockingbirdTests/Mocks/MockingbirdTestsHostMocks.generated.swift; sourceTree = "<group>"; };
D314ED7E24CE1C10000CC23D /* GenericsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericsTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1550,6 +1552,7 @@
children = (
OBJ_49 /* Array+Extensions.swift */,
D3B3D4C1248C9D1600FEEDA0 /* CwlDemangle.swift */,
28DDDFC026B8571D002556C7 /* DynamicCast.swift */,
28B4F6E126B3C9C7005C0049 /* ObjCTypeEncodings.swift */,
D3E6F67B24844C5B000D1971 /* SourceLocation.swift */,
D3B3D4C5248CC15E00FEEDA0 /* StackTrace.swift */,
Expand Down Expand Up @@ -2301,6 +2304,7 @@
OBJ_883 /* TestKiller.swift in Sources */,
28A1F3C226ADC9DA002F282D /* PropertyProviders.swift in Sources */,
OBJ_884 /* ValueProvider+Collections.swift in Sources */,
28DDDFC126B8571D002556C7 /* DynamicCast.swift in Sources */,
OBJ_885 /* ValueProvider+Foundation.swift in Sources */,
OBJ_886 /* ValueProvider+Tuples.swift in Sources */,
D3E6F67624844999000D1971 /* ImplementationProvider.swift in Sources */,
Expand Down
14 changes: 14 additions & 0 deletions Sources/MockingbirdFramework/Utilities/DynamicCast.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// DynamicCast.swift
// MockingbirdFramework
//
// Created by typealias on 8/2/21.
//

import Foundation

/// Swift versions before 5.4 cannot cast from `Any` to a more optional type.
/// https://forums.swift.org/t/casting-from-any-to-optional/21883
func dynamicCast<T>(_ value: Any?) -> T {
return value as! T
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,26 @@ class ThunkTemplate: Template {
return IfStatementTemplate(
condition: "let mkbImpl = mkbImpl as? \(bridgedSignature)",
body: """
return (\(FunctionCallTemplate(name: "mkbImpl",
unlabeledArguments: unlabledArguments,
isThrowing: isThrowing)) as! \(returnType))
return \(FunctionCallTemplate(
name: "Mockingbird.dynamicCast",
unlabeledArguments: [
FunctionCallTemplate(
name: "mkbImpl",
unlabeledArguments: unlabledArguments,
isThrowing: isThrowing).render()
])) as \(returnType)
""").render()
}()
let callBridgedConvenience: String = {
guard isBridged else { return "" }
return IfStatementTemplate(
condition: "let mkbImpl = mkbImpl as? () -> Any?",
body: """
return (\(FunctionCallTemplate(name: "mkbImpl", isThrowing: isThrowing)) as! \(returnType))
return \(FunctionCallTemplate(
name: "Mockingbird.dynamicCast",
unlabeledArguments: [
FunctionCallTemplate(name: "mkbImpl", isThrowing: isThrowing).render()
])) as \(returnType)
""").render()
}()

Expand Down

0 comments on commit 65f5d3a

Please sign in to comment.