forked from parse-community/Parse-SDK-iOS-OSX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
445 lines (386 loc) · 15.1 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
#
# Copyright (c) 2015-present, Parse, LLC.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
#
require_relative 'Vendor/xctoolchain/Scripts/xctask/build_task'
require_relative 'Vendor/xctoolchain/Scripts/xctask/build_framework_task'
script_folder = File.expand_path(File.dirname(__FILE__))
build_folder = File.join(script_folder, 'build')
release_folder = File.join(build_folder, 'release')
bolts_folder = File.join(script_folder, 'Carthage', 'Checkouts', 'Bolts-ObjC')
bolts_build_folder = File.join(bolts_folder, 'build')
module Constants
require 'plist'
script_folder = File.expand_path(File.dirname(__FILE__))
PARSE_CONSTANTS_HEADER = File.join(script_folder, 'Parse', 'PFConstants.h')
PLISTS = [
File.join(script_folder, 'Parse', 'Resources', 'Parse-iOS.Info.plist'),
File.join(script_folder, 'Parse', 'Resources', 'Parse-OSX.Info.plist'),
File.join(script_folder, 'Parse', 'Resources', 'Parse-watchOS.Info.plist'),
File.join(script_folder, 'Parse', 'Resources', 'Parse-tvOS.Info.plist'),
File.join(script_folder, 'ParseStarterProject', 'iOS', 'ParseStarterProject', 'Resources', 'Info.plist'),
File.join(script_folder, 'ParseStarterProject', 'iOS', 'ParseStarterProject-Swift', 'Resources', 'Info.plist'),
File.join(script_folder, 'ParseStarterProject', 'OSX', 'ParseOSXStarterProject', 'Resources', 'Info.plist'),
File.join(script_folder, 'ParseStarterProject', 'OSX', 'ParseOSXStarterProject-Swift', 'Resources', 'Info.plist'),
File.join(script_folder, 'ParseStarterProject', 'tvOS', 'ParseStarterProject-Swift', 'ParseStarter', 'Info.plist'),
File.join(script_folder, 'ParseStarterProject', 'watchOS', 'ParseStarterProject-Swift', 'ParseStarter', 'Info.plist'),
File.join(script_folder, 'ParseStarterProject', 'watchOS', 'ParseStarterProject-Swift', 'ParseStarter Extension', 'Info.plist'),
File.join(script_folder, 'ParseStarterProject', 'watchOS', 'ParseStarterProject-Swift', 'Resources', 'Info.plist'),
]
def self.current_version
constants_file = File.open(PARSE_CONSTANTS_HEADER, 'r').read
matches = constants_file.match(/(.*PARSE_VERSION\s*@")(.*)(")/)
matches[2] # Return the second match, which is the version itself
end
def self.update_version(version)
constants_file = File.open(PARSE_CONSTANTS_HEADER, 'r+')
constants = constants_file.read
constants.gsub!(/(.*PARSE_VERSION\s*@")(.*)(")/, "\\1#{version}\\3")
constants_file.seek(0)
constants_file.write(constants)
PLISTS.each do |plist|
update_info_plist_version(plist, version)
end
end
def self.update_info_plist_version(plist_path, version)
info_plist = Plist.parse_xml(plist_path)
info_plist['CFBundleShortVersionString'] = version
info_plist['CFBundleVersion'] = version
File.open(plist_path, 'w') { |f| f.write(info_plist.to_plist) }
end
end
namespace :build do
desc 'Build iOS framework.'
task :ios do
task = XCTask::BuildFrameworkTask.new do |t|
t.directory = script_folder
t.build_directory = build_folder
t.framework_type = XCTask::FrameworkType::IOS
t.framework_name = 'Parse.framework'
t.workspace = 'Parse.xcworkspace'
t.scheme = 'Parse-iOS'
t.configuration = 'Release'
end
result = task.execute
unless result
puts 'Failed to build iOS Framework.'
exit(1)
end
end
desc 'Build watchOS framework.'
task :watchos do
task = XCTask::BuildFrameworkTask.new do |t|
t.directory = script_folder
t.build_directory = build_folder
t.framework_type = XCTask::FrameworkType::WATCHOS
t.framework_name = 'Parse.framework'
t.workspace = 'Parse.xcworkspace'
t.scheme = 'Parse-watchOS'
t.configuration = 'Release'
end
result = task.execute
unless result
puts 'Failed to build watchOS Framework.'
exit(1)
end
end
desc 'Build macOS framework.'
task :macos do
task = XCTask::BuildFrameworkTask.new do |t|
t.directory = script_folder
t.build_directory = build_folder
t.framework_type = XCTask::FrameworkType::OSX
t.framework_name = 'Parse.framework'
t.workspace = 'Parse.xcworkspace'
t.scheme = 'Parse-macOS'
t.configuration = 'Release'
end
result = task.execute
unless result
puts 'Failed to build macOS Framework.'
exit(1)
end
end
desc 'Build tvOS framework.'
task :tvos do
task = XCTask::BuildFrameworkTask.new do |t|
t.directory = script_folder
t.build_directory = build_folder
t.framework_type = XCTask::FrameworkType::TVOS
t.framework_name = 'Parse.framework'
t.workspace = 'Parse.xcworkspace'
t.scheme = 'Parse-tvOS'
t.configuration = 'Release'
end
result = task.execute
unless result
puts 'Failed to build tvOS Framework.'
exit(1)
end
end
end
namespace :package do
package_ios_name = 'Parse-iOS.zip'
package_macos_name = 'Parse-macOS.zip'
package_tvos_name = 'Parse-tvOS.zip'
package_watchos_name = 'Parse-watchOS.zip'
package_starter_ios_name = 'ParseStarterProject-iOS.zip'
package_starter_osx_name = 'ParseStarterProject-OSX.zip'
package_starter_tvos_name = 'ParseStarterProject-tvOS.zip'
package_starter_watchos_name = 'ParseStarterProject-watchOS.zip'
task :prepare do
`rm -rf #{build_folder} && mkdir -p #{build_folder}`
`rm -rf #{bolts_build_folder} && mkdir -p #{bolts_build_folder}`
`#{bolts_folder}/scripts/build_framework.sh -n -c Release --with-watchos --with-tvos`
end
desc 'Build and package all frameworks for the release'
task :frameworks, [:version] => :prepare do |_, args|
version = args[:version] || Constants.current_version
Constants.update_version(version)
## Build iOS Framework
Rake::Task['build:ios'].invoke
bolts_path = File.join(bolts_build_folder, 'ios', 'Bolts.framework')
ios_framework_path = File.join(build_folder, 'Parse.framework')
make_package(release_folder,
[ios_framework_path, bolts_path],
package_ios_name)
## Build macOS Framework
Rake::Task['build:macos'].invoke
bolts_path = File.join(bolts_build_folder, 'osx', 'Bolts.framework')
osx_framework_path = File.join(build_folder, 'Parse.framework')
make_package(release_folder,
[osx_framework_path, bolts_path],
package_macos_name)
## Build tvOS Framework
Rake::Task['build:tvos'].invoke
bolts_path = File.join(bolts_build_folder, 'tvOS', 'Bolts.framework')
tvos_framework_path = File.join(build_folder, 'Parse.framework')
make_package(release_folder,
[tvos_framework_path, bolts_path],
package_tvos_name)
## Build watchOS Framework
Rake::Task['build:watchos'].invoke
bolts_path = File.join(bolts_build_folder, 'watchOS', 'Bolts.framework')
watchos_framework_path = File.join(build_folder, 'Parse.framework')
make_package(release_folder,
[watchos_framework_path, bolts_path],
package_watchos_name)
end
desc 'Build and package all starter projects for the release'
task :starters, [:version] => :frameworks do |_, _args|
require 'xcodeproj'
ios_starters = [
File.join(script_folder, 'ParseStarterProject', 'iOS', 'ParseStarterProject'),
File.join(script_folder, 'ParseStarterProject', 'iOS', 'ParseStarterProject-Swift')
]
ios_framework_archive = File.join(release_folder, package_ios_name)
make_starter_package(release_folder, ios_starters, ios_framework_archive, package_starter_ios_name)
osx_starters = [
File.join(script_folder, 'ParseStarterProject', 'OSX', 'ParseOSXStarterProject'),
File.join(script_folder, 'ParseStarterProject', 'OSX', 'ParseOSXStarterProject-Swift')
]
osx_framework_archive = File.join(release_folder, package_macos_name)
make_starter_package(release_folder, osx_starters, osx_framework_archive, package_starter_osx_name)
tvos_starters = [
File.join(script_folder, 'ParseStarterProject', 'tvOS', 'ParseStarterProject-Swift')
]
tvos_framework_archive = File.join(release_folder, package_tvos_name)
make_starter_package(release_folder, tvos_starters, tvos_framework_archive, package_starter_tvos_name)
watchos_starters = [
File.join(script_folder, 'ParseStarterProject', 'watchOS', 'ParseStarterProject-Swift')
]
watchos_framework_archive = File.join(release_folder, package_watchos_name)
watchos_starters.each do |project_path|
`git clean -xfd #{project_path}`
`mkdir -p #{project_path}/Frameworks/iOS && mkdir -p #{project_path}/Frameworks/watchOS`
`cd #{project_path}/Frameworks/iOS && unzip -o #{ios_framework_archive}`
`cd #{project_path}/Frameworks/watchOS && unzip -o #{watchos_framework_archive}`
xcodeproj_path = Dir.glob(File.join(project_path, '*.xcodeproj'))[0]
prepare_xcodeproj(xcodeproj_path)
end
make_package(release_folder, watchos_starters, package_starter_watchos_name)
watchos_starters.each do |project_path|
`git clean -xfd #{project_path}`
`git checkout #{project_path}`
end
end
def make_package(target_path, items, archive_name)
temp_folder = File.join(target_path, 'tmp')
`mkdir -p #{temp_folder}`
item_list = ''
items.each do |item|
`cp -R #{item} #{temp_folder}`
file_name = File.basename(item)
item_list << " #{file_name}"
end
archive_path = File.join(target_path, archive_name)
`cd #{temp_folder}; zip -r --symlinks #{archive_path} #{item_list}`
`rm -rf #{temp_folder}`
puts "Release archive created: #{File.join(target_path, archive_name)}"
end
def make_starter_package(target_path, starter_projects, framework_archive, archive_name)
starter_projects.each do |project_path|
`git clean -xfd #{project_path}`
`cd #{project_path} && unzip -o #{framework_archive}`
xcodeproj_path = Dir.glob(File.join(project_path, '*.xcodeproj'))[0]
prepare_xcodeproj(xcodeproj_path)
end
make_package(target_path, starter_projects, archive_name)
starter_projects.each do |project_path|
`git clean -xfd #{project_path}`
`git checkout #{project_path}`
end
end
def prepare_xcodeproj(path)
project = Xcodeproj::Project.open(path)
project.targets.each do |target|
if target.name == 'Bootstrap'
target.remove_from_project
else
target.dependencies.each do |dependency|
dependency.remove_from_project if dependency.display_name == 'Bootstrap'
end
end
end
project.save
`rm -rf #{File.join(path, 'xcshareddata', 'xcschemes', '*')}`
end
end
namespace :test do
desc 'Run iOS Tests'
task :ios do |_, args|
task = XCTask::BuildTask.new do |t|
t.directory = script_folder
t.workspace = 'Parse.xcworkspace'
t.scheme = 'Parse-iOS'
t.sdk = 'iphonesimulator'
t.destinations = ["\"platform=iOS Simulator,OS=9.1,name=iPhone 4s\"",
"\"platform=iOS Simulator,OS=9.1,name=iPhone 6s\"",]
t.configuration = 'Debug'
t.additional_options = { "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS" => "YES",
"GCC_GENERATE_TEST_COVERAGE_FILES" => "YES" }
t.actions = [XCTask::BuildAction::TEST]
t.formatter = XCTask::BuildFormatter::XCPRETTY
end
unless task.execute
puts 'iOS Tests Failed!'
exit(1)
end
end
desc 'Run macOS Tests'
task :macos do |_, args|
task = XCTask::BuildTask.new do |t|
t.directory = script_folder
t.workspace = 'Parse.xcworkspace'
t.scheme = 'Parse-macOS'
t.sdk = 'macosx'
t.destinations = ['arch=x86_64']
t.configuration = 'Debug'
t.additional_options = { "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS" => "YES",
"GCC_GENERATE_TEST_COVERAGE_FILES" => "YES" }
t.actions = [XCTask::BuildAction::TEST]
t.formatter = XCTask::BuildFormatter::XCPRETTY
end
unless task.execute
puts 'OS X Tests Failed!'
exit(1)
end
end
desc 'Run Deployment Tests'
task :deployment do |_|
Rake::Task['package:frameworks'].invoke
Rake::Task['package:starters'].invoke
end
desc 'Run Starter Project Tests'
task :starters do |_|
results = []
ios_schemes = ['ParseStarterProject',
'ParseStarterProject-Swift']
osx_schemes = ['ParseOSXStarterProject',
'ParseOSXStarterProject-Swift']
tvos_schemes = ['ParseStarter-tvOS']
watchos_schemes = ['ParseWatchStarter-watchOS']
ios_schemes.each do |scheme|
task = XCTask::BuildTask.new do |t|
t.directory = script_folder
t.workspace = 'Parse.xcworkspace'
t.scheme = scheme
t.configuration = 'Debug'
t.sdk = 'iphonesimulator'
t.destinations = ['"platform=iOS Simulator,name=iPhone 6s"']
t.actions = [XCTask::BuildAction::CLEAN, XCTask::BuildAction::BUILD]
t.formatter = XCTask::BuildFormatter::XCPRETTY
end
results << task.execute
end
osx_schemes.each do |scheme|
task = XCTask::BuildTask.new do |t|
t.directory = script_folder
t.workspace = 'Parse.xcworkspace'
t.scheme = scheme
t.configuration = 'Debug'
t.sdk = 'macosx'
t.actions = [XCTask::BuildAction::CLEAN, XCTask::BuildAction::BUILD]
t.formatter = XCTask::BuildFormatter::XCPRETTY
end
results << task.execute
end
watchos_schemes.each do |scheme|
task = XCTask::BuildTask.new do |t|
t.directory = script_folder
t.workspace = 'Parse.xcworkspace'
t.scheme = scheme
t.configuration = 'Debug'
t.destinations = ["\"platform=iOS Simulator,name=iPhone 6s\"",]
t.actions = [XCTask::BuildAction::CLEAN, XCTask::BuildAction::BUILD]
t.formatter = XCTask::BuildFormatter::XCPRETTY
end
results << task.execute
end
tvos_schemes.each do |scheme|
task = XCTask::BuildTask.new do |t|
t.directory = script_folder
t.workspace = 'Parse.xcworkspace'
t.scheme = scheme
t.configuration = 'Debug'
t.destinations = ["\"platform=tvOS Simulator,OS=9.0,name=Apple TV 1080p\"",]
t.actions = [XCTask::BuildAction::CLEAN, XCTask::BuildAction::BUILD]
t.formatter = XCTask::BuildFormatter::XCPRETTY
end
results << task.execute
end
results.each do |result|
unless result
puts 'Starter Project Tests Failed!'
exit(1)
end
end
end
desc 'Run Podspec Lint'
task :cocoapods do |_|
podspecs = ['Parse.podspec']
results = []
system("pod repo update --silent")
podspecs.each do |podspec|
results << system("pod lib lint #{podspec}")
results << system("pod lib lint #{podspec} --use-libraries")
end
results.each do |result|
unless result
puts 'Podspec Tests Failed!'
exit(1)
end
end
end
desc 'Run Carthage Build'
task :carthage do |_|
if !system('carthage build --no-skip-current')
puts 'Carthage Tests Failed!'
exit(1)
end
end
end