forked from airbnb/lottie-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
160 lines (134 loc) · 5.45 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
namespace :build do
desc 'Builds all packages and executables'
task all: ['package:all', 'example:all']
desc 'Builds the Lottie package for supported platforms'
namespace :package do
desc 'Builds the Lottie package for all supported platforms'
task all: ['iOS', 'macOS', 'tvOS']
desc 'Builds the Lottie package for iOS'
task :iOS do
xcodebuild('build -scheme "Lottie (iOS)" -destination generic/platform=iOS -workspace Lottie.xcworkspace')
end
desc 'Builds the Lottie package for macOS'
task :macOS do
xcodebuild('build -scheme "Lottie (macOS)" -destination generic/platform=macOS -workspace Lottie.xcworkspace')
end
desc 'Builds the Lottie package for tvOS'
task :tvOS do
xcodebuild('build -scheme "Lottie (tvOS)" -destination generic/platform=tvOS -workspace Lottie.xcworkspace')
end
end
desc 'Builds the Lottie example app for supported platforms'
namespace :example do
desc 'Builds the Lottie example apps for all supported platforms'
task all: ['iOS', 'macOS', 'tvOS']
desc 'Builds the iOS Lottie Example app'
task :iOS do
xcodebuild('build -scheme "Example (iOS)" -destination "platform=iOS Simulator,name=iPhone 8" -workspace Lottie.xcworkspace')
end
desc 'Builds the macOS Lottie Example app'
task :macOS do
xcodebuild('build -scheme "Example (macOS)" -workspace Lottie.xcworkspace')
end
desc 'Builds the tvOS Lottie Example app'
task :tvOS do
xcodebuild('build -scheme "Example (tvOS)" -destination "platform=tvOS Simulator,name=Apple TV" -workspace Lottie.xcworkspace')
end
end
end
namespace :test do
desc 'Tests the Lottie package for iOS'
task :package do
sh 'rm -rf Tests/Artifacts'
xcodebuild('test -scheme "Lottie (iOS)" -destination "platform=iOS Simulator,name=iPhone 8" -resultBundlePath Tests/Artifacts/LottieTests.xcresult')
end
desc 'Processes .xcresult artifacts from the most recent test:package execution'
task :process do
sh 'mint run ChargePoint/[email protected] xcparse attachments Tests/Artifacts/LottieTests.xcresult Tests/Artifacts/TestAttachments'
end
desc 'Tests Carthage support'
task :carthage do
# Copy the repo to `Carthage/Checkouts/Lottie-ios`
sh 'rm -rf script/test-carthage/Carthage'
sh 'mkdir script/test-carthage/Carthage script/test-carthage/Carthage/Checkouts script/test-carthage/Carthage/Checkouts/lottie-ios'
sh 'cp -R [^script]* script/test-carthage/Carthage/Checkouts/lottie-ios'
Dir.chdir('script/test-carthage') do
# Build the LottieCarthage framework scheme
sh 'carthage build --use-xcframeworks'
# Delete Carthage's derived data to verify that the built .xcframework doesn't depend on any
# side effects from building on this specific machine.
# https://github.com/airbnb/lottie-ios/issues/1492
sh 'rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData'
# Build a test app that imports and uses the LottieCarthage framework
xcodebuild('build -scheme CarthageTest -destination "platform=iOS Simulator,name=iPhone 8"')
xcodebuild('build -scheme CarthageTest-macOS')
end
end
desc 'Tests Swift Package Manager support'
task :spm do
Dir.chdir('script/test-spm') do
# Build for iOS, macOS, and tvOS using the targets defined in Package.swift
xcodebuild('build -scheme "Lottie" -destination generic/platform=iOS')
xcodebuild('build -scheme "Lottie" -destination generic/platform=macOS')
xcodebuild('build -scheme "Lottie" -destination generic/platform=tvOS')
end
end
end
namespace :lint do
desc 'Lints swift files'
task :swift do
formatTool('format --lint')
end
desc 'Lints the CocoaPods podspec'
task :podspec do
sh 'pod lib lint lottie-ios.podspec'
end
end
namespace :format do
desc 'Formats swift files'
task :swift do
formatTool('format')
end
end
def xcodebuild(command)
# Check if the mint tool is installed -- if so, pipe the xcodebuild output through xcbeautify
`which mint`
if $?.success?
sh "set -o pipefail && xcodebuild #{command} | mint run thii/[email protected]"
else
sh "xcodebuild #{command}"
end
end
def formatTool(command)
# As of Xcode 13.4 / Xcode 14 beta 4, including airbnb/swift as a dependency
# causes Xcode to spin indefinitely at 100% CPU (due to the remote binary dependencies
# used by that package). As a workaround, we can specifically add that dependency
# to our Package.swift file when linting / formatting and remove it afterwards.
packageDefinition = File.read('Package.swift')
packageDefinitionWithFormatDependency = packageDefinition +
<<~EOC
#if swift(>=5.6)
// Add the Airbnb Swift formatting plugin if possible
package.dependencies.append(
.package(
url: "https://github.com/airbnb/swift",
// Since we don't have a Package.resolved for this, we need to reference a specific commit
// so changes to the style guide don't cause this repo's checks to start failing.
.revision("7884f265499752cc5eccaa9eba08b4a2f8b73357")))
#endif
EOC
# Add the format tool dependency to our Package.swift
File.write('Package.swift', packageDefinitionWithFormatDependency)
exitCode = 0
# Run the given command
begin
sh "swift package --allow-writing-to-package-directory #{command}"
rescue
exitCode = $?.exitstatus
ensure
# Revert the changes to Package.swift
File.write('Package.swift', packageDefinition)
File.delete('Package.resolved')
end
exit exitCode
end