Skip to content

Commit e0d63f0

Browse files
authored
Add Swift Package Manager (#47)
* Adds support for Swift Package Manager. * Moves source files to new structure. * Minor source changes to work with new structure. * Adds CI job to build via SPM.
1 parent 80b38a9 commit e0d63f0

28 files changed

+148
-13
lines changed

.github/workflows/ci.yml

+14
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,17 @@ jobs:
4343
run: bundle exec --gemfile=Example/Gemfile pod install --project-directory=Example
4444
- name: Lint Podspec
4545
run: bundle exec --gemfile=Example/Gemfile pod lib lint --verbose --fail-fast
46+
spm:
47+
name: SPM Build
48+
runs-on: macOS-latest
49+
strategy:
50+
matrix:
51+
platform: ['iOS_14']
52+
fail-fast: false
53+
steps:
54+
- name: Checkout Repo
55+
uses: actions/checkout@v2
56+
- name: Select Xcode Version
57+
run: sudo xcode-select --switch /Applications/Xcode_12.2.app/Contents/Developer
58+
- name: Build
59+
run: Scripts/build.swift spm ${{ matrix.platform }}

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ Carthage/Build
2727

2828
# CocoaPods
2929
Pods/
30+
31+
# Swift Package Manager
32+
generated/
33+
.build/
34+
.swiftpm/

AccessibilitySnapshot.podspec

+6-9
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,25 @@ Pod::Spec.new do |s|
1515
s.default_subspecs = 'Core', 'SnapshotTesting'
1616

1717
s.subspec 'Core' do |ss|
18-
ss.source_files = 'AccessibilitySnapshot/Core/Classes/**/*.{swift,h,m}'
19-
ss.public_header_files = [
20-
'AccessibilitySnapshot/Core/Classes/UIAccessibilityStatusUtility.h',
21-
'AccessibilitySnapshot/Core/Classes/UIView+DynamicTypeSnapshotting.h',
22-
]
18+
ss.source_files = 'Sources/AccessibilitySnapshot/Core/Swift/Classes/**/*.swift', 'Sources/AccessibilitySnapshot/Core/ObjC/**/*.{h,m}'
19+
ss.public_header_files = 'Sources/AccessibilitySnapshot/Core/ObjC/include/*.h'
2320
ss.resource_bundles = {
24-
'AccessibilitySnapshot' => ['AccessibilitySnapshot/Core/Assets/**/*.{strings,xcassets}']
21+
'AccessibilitySnapshot' => ['Sources/AccessibilitySnapshot/Core/Swift/Assets/**/*.{strings,xcassets}']
2522
}
2623
end
2724

2825
s.subspec 'iOSSnapshotTestCase' do |ss|
29-
ss.source_files = 'AccessibilitySnapshot/iOSSnapshotTestCase/Classes/**/*.{swift,h,m}'
26+
ss.source_files = 'Sources/AccessibilitySnapshot/iOSSnapshotTestCase/**/*.{swift,h,m}'
3027
ss.public_header_files = [
31-
'AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase_Accessibility.h',
28+
'Sources/AccessibilitySnapshot/iOSSnapshotTestCase/FBSnapshotTestCase_Accessibility.h',
3229
]
3330

3431
ss.dependency 'AccessibilitySnapshot/Core'
3532
ss.dependency 'iOSSnapshotTestCase', '~> 6.0'
3633
end
3734

3835
s.subspec 'SnapshotTesting' do |ss|
39-
ss.source_files = 'AccessibilitySnapshot/SnapshotTesting/Classes/**/*.{swift,h,m}'
36+
ss.source_files = 'Sources/AccessibilitySnapshot/SnapshotTesting/**/*.{swift,h,m}'
4037

4138
ss.dependency 'AccessibilitySnapshot/Core'
4239
ss.dependency 'SnapshotTesting', '~> 1.0'

Example/Podfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ CHECKOUT OPTIONS:
3737
:git: https://github.com/square/Paralayout
3838

3939
SPEC CHECKSUMS:
40-
AccessibilitySnapshot: cb80a36813f8897825eada35ca5b09b210e472c3
40+
AccessibilitySnapshot: 4e1a6b6a16d945a4aca3a7459490fc6e1ccc867e
4141
iOSSnapshotTestCase: 9ab44cb5aa62b84d31847f40680112e15ec579a6
4242
Paralayout: f4d6727fca5b592eb93a7cc408e45404599a4b0a
4343
SnapshotTesting: 38947050d13960d57a4a9c166fcf51bca7d56970

Package.resolved

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"object": {
3+
"pins": [
4+
{
5+
"package": "SnapshotTesting",
6+
"repositoryURL": "https://github.com/pointfreeco/swift-snapshot-testing.git",
7+
"state": {
8+
"branch": null,
9+
"revision": "c466812aa2e22898f27557e2e780d3aad7a27203",
10+
"version": "1.8.2"
11+
}
12+
}
13+
]
14+
},
15+
"version": 1
16+
}

Package.swift

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// swift-tools-version:5.3
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "AccessibilitySnapshot",
8+
defaultLocalization: "en",
9+
platforms: [
10+
.iOS(.v12),
11+
],
12+
products: [
13+
// Core + SnapshotTesting for image comparison
14+
.library(
15+
name: "AccessibilitySnapshot",
16+
targets: ["AccessibilitySnapshot"]
17+
),
18+
19+
.library(
20+
name: "AccessibilitySnapshotCore",
21+
targets: ["AccessibilitySnapshotCore"]
22+
),
23+
],
24+
dependencies: [
25+
.package(
26+
name: "SnapshotTesting",
27+
url: "https://github.com/pointfreeco/swift-snapshot-testing.git",
28+
.upToNextMajor(from: "1.8.0")
29+
)
30+
],
31+
targets: [
32+
.target(
33+
name: "AccessibilitySnapshotCore-ObjC",
34+
path: "Sources/AccessibilitySnapshot/Core/ObjC"
35+
),
36+
.target(
37+
name: "AccessibilitySnapshotCore",
38+
dependencies: ["AccessibilitySnapshotCore-ObjC"],
39+
path: "Sources/AccessibilitySnapshot/Core/Swift"
40+
),
41+
.target(
42+
name: "AccessibilitySnapshot",
43+
dependencies: ["AccessibilitySnapshotCore", "SnapshotTesting"],
44+
path: "Sources/AccessibilitySnapshot/SnapshotTesting"
45+
)
46+
]
47+
)

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,36 @@ Alternatively, if you wish to use [iOSSnapshotTestCase](https://github.com/uber/
3131
pod 'AccessibilitySnapshot/iOSSnapshotTestCase'
3232
```
3333

34+
### Swift Package Manager
35+
36+
Install with [Swift Package Manager](https://swift.org/package-manager/) by adding the following to your `Package.swift`:
37+
38+
```swift
39+
dependencies: [
40+
.package(name: "AccessibilitySnapshot", url: "https://github.com/cashapp/AccessibilitySnapshot.git", from: "0.4.1"),
41+
]
42+
```
43+
44+
Next, add AccessibilitySnapshot as a dependency to your test target:
45+
46+
```swift
47+
targets: [
48+
.target(name: "MyApp"),
49+
.testTarget(name: "MyAppTests", dependencies: ["MyApp", "AccessibilitySnapshot"])
50+
]
51+
```
52+
53+
To use only the core accessibility parser, add a dependency on the Core library alone:
54+
55+
```swift
56+
targets: [
57+
.target(name: "MyApp"),
58+
.testTarget(name: "MyAppTests", dependencies: ["MyApp", "AccessibilitySnapshotCore"])
59+
]
60+
```
61+
62+
We do not currently support AccessibilitySnapshot and [iOSSnapshotTestCase](https://github.com/uber/ios-snapshot-test-case) through Swift Package Manager.
63+
3464
## Usage
3565

3666
AccessibilitySnapshot builds on top of existing snapshot frameworks to add support for snapshotting your app's accessibility. By default it uses the [SnapshotTesting](https://github.com/pointfreeco/swift-snapshot-testing) framework for snapshotting, but can be switched over to [iOSSnapshotTestCase](https://github.com/uber/ios-snapshot-test-case) as well.

Scripts/build.swift

+12
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ enum TaskError: Error {
4646
}
4747

4848
enum Platform: String, CustomStringConvertible {
49+
case iOS_14
4950
case iOS_13
5051
case iOS_12
5152

5253
var destination: String {
5354
switch self {
55+
case .iOS_14:
56+
return "platform=iOS Simulator,OS=14.2,name=iPhone 12 Pro"
5457
case .iOS_13:
5558
return "platform=iOS Simulator,OS=13.3,name=iPhone 11 Pro"
5659
case .iOS_12:
@@ -68,31 +71,40 @@ enum Platform: String, CustomStringConvertible {
6871
}
6972

7073
enum Task: String, CustomStringConvertible {
74+
case spm
7175
case xcode
7276

7377
var workspace: String? {
7478
switch self {
79+
case .spm:
80+
return nil
7581
case .xcode:
7682
return "Example/AccessibilitySnapshot.xcworkspace"
7783
}
7884
}
7985

8086
var project: String? {
8187
switch self {
88+
case .spm:
89+
return nil
8290
case .xcode:
8391
return nil
8492
}
8593
}
8694

8795
var scheme: String {
8896
switch self {
97+
case .spm:
98+
return "AccessibilitySnapshot"
8999
case .xcode:
90100
return "AccessibilitySnapshotDemo"
91101
}
92102
}
93103

94104
var shouldRunTests: Bool {
95105
switch self {
106+
case .spm:
107+
return false
96108
case .xcode:
97109
return true
98110
}

AccessibilitySnapshot/Core/Classes/UIAccessibilityStatusUtility.m renamed to Sources/AccessibilitySnapshot/Core/ObjC/UIAccessibilityStatusUtility.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4040
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4141

42-
#import "UIAccessibilityStatusUtility.h"
42+
#import "include/UIAccessibilityStatusUtility.h"
4343

4444
#import <dlfcn.h>
4545

AccessibilitySnapshot/Core/Classes/UIView+DynamicTypeSnapshotting.m renamed to Sources/AccessibilitySnapshot/Core/ObjC/UIView+DynamicTypeSnapshotting.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// limitations under the License.
1515
//
1616

17-
#import "UIView+DynamicTypeSnapshotting.h"
17+
#import "include/UIView+DynamicTypeSnapshotting.h"
1818

1919
#import <objc/runtime.h>
2020

AccessibilitySnapshot/Core/Classes/UIAccessibilityStatusUtility.h renamed to Sources/AccessibilitySnapshot/Core/ObjC/include/UIAccessibilityStatusUtility.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// limitations under the License.
1515
//
1616

17-
@import Foundation;
17+
#import <UIKit/UIKit.h>
1818

1919
NS_ASSUME_NONNULL_BEGIN
2020

AccessibilitySnapshot/Core/Classes/AccessibilitySnapshotView.swift renamed to Sources/AccessibilitySnapshot/Core/Swift/Classes/AccessibilitySnapshotView.swift

+4
Original file line numberDiff line numberDiff line change
@@ -771,9 +771,13 @@ private extension Bundle {
771771
private final class Sentinel {}
772772

773773
static var accessibilitySnapshotResources: Bundle = {
774+
#if SWIFT_PACKAGE
775+
return Bundle.module
776+
#else
774777
let container = Bundle(for: Sentinel.self)
775778
let resources = container.url(forResource: "AccessibilitySnapshot", withExtension: "bundle")!
776779
return Bundle(url: resources)!
780+
#endif
777781
}()
778782

779783
}

AccessibilitySnapshot/Core/Classes/String+Localization.swift renamed to Sources/AccessibilitySnapshot/Core/Swift/Classes/String+Localization.swift

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ private enum StringLocalization {
3535
private static var localeToBundleMap: [String: Bundle] = [:]
3636

3737
private static let resourceBundle: Bundle = {
38+
#if SWIFT_PACKAGE
39+
return Bundle.module
40+
#else
3841
let frameworkBundle = Bundle(for: AccessibilityHierarchyParser.self)
3942

4043
guard let resourceBundlePath = frameworkBundle.path(forResource: "AccessibilitySnapshot", ofType: "bundle") else {
@@ -46,6 +49,7 @@ private enum StringLocalization {
4649
}
4750

4851
return resourceBundle
52+
#endif
4953
}()
5054

5155
// MARK: - Public Static Methods

AccessibilitySnapshot/SnapshotTesting/Classes/SnapshotTesting+Accessibility.swift renamed to Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+Accessibility.swift

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
//
1616

1717
import SnapshotTesting
18+
import UIKit
19+
20+
#if SWIFT_PACKAGE
21+
import AccessibilitySnapshotCore
22+
import AccessibilitySnapshotCore_ObjC
23+
#endif
1824

1925
extension Snapshotting where Value == UIView, Format == UIImage {
2026

0 commit comments

Comments
 (0)