forked from pivotal-legacy/PivotalCoreKit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
338 lines (279 loc) · 10.8 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
CONFIGURATION = "Release"
BUILD_SDK_VERSION = ENV['BUILD_SDK_VERSION'] || ""
SIMULATOR_VERSIONS = ENV['SIMULATOR_VERSIONS'] || "8.4"
SIMULATOR_DEVICES = ENV['SIMULATOR_DEVICES'] || "iPhone 5s"
BUILD_DIR = File.join(File.dirname(__FILE__), "build")
require 'tmpdir'
def build_dir(effective_platform_name)
File.join(BUILD_DIR, CONFIGURATION + effective_platform_name)
end
def system_or_exit(cmd, env_overrides = {}, stdout = nil)
puts "Executing #{cmd}"
cmd += " >#{stdout}" if stdout
old_env = {}
env_overrides.each do |key, value|
old_env[key] = ENV[key]
ENV[key] = value
end
system(cmd) or begin
puts "******** Build failed ********"
exit(1)
end
env_overrides.each do |key, value|
ENV[key] = old_env[key]
end
end
def output_file(target)
output_dir = if ENV['IS_CI_BOX']
ENV['CC_BUILD_ARTIFACTS']
else
build_dir = File.join(File.dirname(__FILE__), "build")
Dir.mkdir(build_dir) unless File.exists?(build_dir)
build_dir
end
output_file = File.join(output_dir, "#{target}.output")
puts "Output: #{output_file}"
output_file
end
def build_and_test_scheme(scheme)
sdk = 'iphonesimulator' + BUILD_SDK_VERSION
devices = SIMULATOR_DEVICES.split(",")
versions = SIMULATOR_VERSIONS.split(",")
system_or_exit(
%Q[xcodebuild -workspace PivotalCoreKit.xcworkspace \
-scheme #{scheme} \
-sdk #{sdk} \
build]
)
devices.each do |device|
versions.each do |version|
`osascript -e 'tell application "iPhone Simulator" to quit'`
system_or_exit(
%Q[xcodebuild -workspace PivotalCoreKit.xcworkspace \
-scheme #{scheme} \
-sdk #{sdk} \
-destination platform='iOS Simulator',name='#{device},OS=#{version}' \
test]
)
`osascript -e 'tell application "iPhone Simulator" to quit'`
end
end
end
def build_target(target, project: project, output_file: output_file, sdk: sdk)
command = ["xcodebuild",
"-project",
"#{project}.xcodeproj",
"-target",
"#{target}",
"-configuration",
"#{CONFIGURATION}",
"build",
"SYMROOT=#{BUILD_DIR}",
]
if sdk then
command = command << "-sdk" << sdk
end
system_or_exit(command.join(" "), {}, output_file)
end
desc "Trim edited files and run all specs"
task :default => [:trim_whitespace, "all:spec"]
desc "Do what travis will do"
task :travis => ["foundation:clean", "uikit:clean", "core_location:clean", "foundation:spec", "uikit:spec", "core_location:spec"]
desc "Trim whitespace in recently edited files"
task :trim_whitespace do
system_or_exit(%Q[git status --short | awk '{if ($1 != "D" && $1 != "R") print $2}' | grep -e '.*\.[mh]$' | xargs sed -i '' -e 's/ / /g;s/ *$//g;'])
end
namespace :foundation do
project = "Foundation/Foundation"
namespace :build do
namespace :core do
desc "Build Foundation+PivotalCore framework for OS X"
task :osx do
output_file = output_file("foundation:build:core:osx")
build_target("Foundation+PivotalCore", project: project, output_file: output_file)
end
desc "Build Foundation+PivotalCore-StaticLib for iOS"
task :ios do
output_file = output_file("foundation:build:core:ios")
build_target("Foundation+PivotalCore-StaticLib", project: project, output_file: output_file)
end
end
task :core => ["core:osx", "core:ios"]
namespace :framework do
desc "Build Foundation+PivotalCore-iOS universal static framework"
task :ios do
output_file = output_file("foundation:build:framework:ios")
build_target("Foundation+PivotalCore-iOS", project: project, output_file: output_file)
end
end
task :framework => ["framework:ios"]
namespace :spec_helper do
desc "Build Foundation+PivotalSpecHelper framework for OS X"
task :osx do
output_file = output_file("foundation:build:spec_helper:osx")
build_target("Foundation+PivotalSpecHelper", project: project, output_file: output_file)
end
desc "Build Foundation+PivotalSpecHelper-StaticLib for iOS"
task :ios do
output_file = output_file("foundation:build:spec_helper:ios")
build_target("Foundation+PivotalSpecHelper-StaticLib", project: project, output_file: output_file)
end
end
task :spec_helper => ["spec_helper:osx", "spec_helper:ios"]
namespace :spec_helper_framework do
desc "Build Foundation+PivotalSpecHelper-iOS universal static framework"
task :ios do
output_file = output_file("foundation:build:spec_helper_framework:ios")
build_target("Foundation+PivotalSpecHelper-iOS", project: project, output_file: output_file)
end
end
task :spec_helper_framework => ["spec_helper_framework:ios"]
end
namespace :spec do
desc "Build and run all OS X specs"
task :osx => ["build:core:osx", "build:spec_helper:osx"] do
output_file = output_file("foundation:spec:osx")
build_target("FoundationSpec", project: project, output_file: output_file)
build_dir = build_dir("")
env_vars = {
"CEDAR_REPORTER_CLASS" => "CDRColorizedReporter",
"CFFIXED_USER_HOME" => Dir.tmpdir,
"DYLD_FRAMEWORK_PATH" => build_dir
}
system_or_exit("cd #{build_dir}; ./FoundationSpec", env_vars)
end
desc "Build and run all Foundation specs on iOS"
task :ios do
build_and_test_scheme("Foundation-StaticLibSpec")
end
end
task :build => ["foundation:build:core", "foundation:build:spec_helper"]
task :spec => ["foundation:spec:osx", "foundation:spec:ios"]
task :clean do
system_or_exit(%Q[xcodebuild -project #{project}.xcodeproj -alltargets -configuration #{CONFIGURATION} clean SYMROOT=#{BUILD_DIR}], {}, output_file("foundation:clean"))
end
end
task :foundation => ["foundation:build", "foundation:spec"]
namespace :uikit do
project = "UIKit/UIKit"
namespace :build do
namespace :core do
desc "Build UIKit+PivotalCore-StaticLib"
task :ios do
output_file = output_file("uikit:build:core:ios")
build_target("UIKit+PivotalCore-StaticLib", project: project, output_file: output_file)
end
end
task :core => ["core:ios"]
namespace :spec_helper do
desc "Build UIKit+PivotalSpecHelper-StaticLib"
task :ios do
output_file = output_file("uikit:build:spec_helper:ios")
build_target("UIKit+PivotalSpecHelper-StaticLib", project: project, output_file: output_file)
end
desc "Build UIKit+PivotalSpecHelperStubs-StaticLib"
task :ios_stubs do
output_file = output_file("uikit:build:spec_helper:ios_stubs")
build_target("UIKit+PivotalSpecHelperStubs-StaticLib", project: project, output_file: output_file)
end
end
task :spec_helper => ["spec_helper:ios", "spec_helper:ios_stubs"]
namespace :spec_helper_framework do
desc "Build UIKit+PivotalSpecHelper-iOS universal static framework"
task :ios do
output_file = output_file("uikit:build:spec_helper_framework:ios")
build_target("UIKit+PivotalSpecHelper-iOS", project: project, output_file: output_file)
end
desc "Build UIKit+PivotalSpecHelperStubs-iOS universal static framework"
task :ios_stubs do
output_file = output_file("uikit:build:spec_helper_framework:ios_stubs")
build_target("UIKit+PivotalSpecHelperStubs-iOS", project: project, output_file: output_file)
end
end
task :spec_helper_framework => ["spec_helper_framework:ios", "spec_helper_framework:ios_stubs"]
end
namespace :spec do
desc "Build and run all UIKit specs"
task :ios do
build_and_test_scheme("UIKit-StaticLibSpec")
end
end
task :build => ["build:core"]
task :spec => ["spec:ios"]
task :clean do
system_or_exit(%Q[xcodebuild -project #{project}.xcodeproj -alltargets -configuration #{CONFIGURATION} clean SYMROOT=#{BUILD_DIR}], {}, output_file("uikit:clean"))
end
end
task :uikit => ["uikit:build", "uikit:spec"]
namespace :core_location do
project = "CoreLocation/CoreLocation"
namespace :build do
namespace :spec_helper do
desc "Build CoreLocation+PivotalSpecHelper framework for OS X"
task :osx do
output_file = output_file("core_location:build:spec_helper:osx")
build_target("CoreLocation+PivotalSpecHelper", project: project, output_file: output_file)
end
desc "Build CoreLocation+PivotalSpecHelper-StaticLib for iOS"
task :ios do
output_file = output_file("core_location:build:spec_helper:ios")
build_target("CoreLocation+PivotalSpecHelper-StaticLib", project: project, output_file: output_file)
end
end
task :spec_helper => ["spec_helper:osx", "spec_helper:ios"]
end
namespace :spec do
desc "Build and run CoreLocation specs on OS X"
task :osx => ["build:spec_helper:osx"] do
output_file = output_file("core_location:spec:osx")
build_target("CoreLocationSpec", project: project, output_file: output_file)
build_dir = build_dir("")
env_vars = {
"DYLD_FRAMEWORK_PATH" => build_dir,
"CEDAR_REPORTER_CLASS" => "CDRColorizedReporter"
}
system_or_exit("cd #{build_dir}; ./CoreLocationSpec", env_vars)
end
desc "Build and run CoreLocation specs on iOS"
task :ios do
build_and_test_scheme("CoreLocation-StaticLibSpec")
end
end
task :build => ["build:spec_helper"]
task :spec => ["spec:osx", "spec:ios"]
task :clean do
system_or_exit(%Q[xcodebuild -project #{project}.xcodeproj -alltargets -configuration #{CONFIGURATION} clean SYMROOT=#{BUILD_DIR}], {}, output_file("core_location:clean"))
end
end
task :core_location => ["core_location:build", "core_location:spec"]
namespace :watchkit do
project = "WatchKit/WatchKit"
target = "WatchKit"
namespace :build do
desc "Build Fake WatchKit dynamic framework for iOS"
task :ios do
build_output_filename = output_file("watchkit:build:ios")
build_target(target, project: project, sdk: 'iphonesimulator', output_file: build_output_filename)
end
end
namespace :spec do
desc "Build and run WatchKit specs on iOS"
task :ios do
system_or_exit(%Q[xcodebuild -project WatchKit/WatchKit.xcodeproj -scheme WatchKit -configuration Debug build test -destination 'platform=iOS Simulator,name=iPhone 6'])
end
end
task :spec => ["spec:ios"]
task :build => ["build:ios"]
task :clean do
system_or_exit(%Q[xcodebuild -project #{project}.xcodeproj -alltargets -configuration #{CONFIGURATION} clean SYMROOT=#{BUILD_DIR}], {}, output_file("watchkit:clean"))
end
end
task :watchkit => ["watchkit:build", "watchkit:spec"]
namespace :all do
desc "Build everything"
task :build => ["foundation:build", "uikit:build", "core_location:build", "watchkit:build"]
desc "Run all specs"
task :spec => ["foundation:spec", "uikit:spec", "core_location:spec", "watchkit:spec"]
desc "Clean all targets"
task :clean => ["foundation:clean", "uikit:clean", "core_location:clean", "watchkit:clean"]
end