-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
build_settings_spec.rb
429 lines (396 loc) · 22.4 KB
/
build_settings_spec.rb
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
require File.expand_path('../../../spec_helper', __FILE__)
module Pod
class Target
describe BuildSettings do
def pod(pod_target)
BuildSettings::PodTargetSettings.new(pod_target, nil, :configuration => :debug)
end
def aggregate(aggregate_target, configuration_name = 'Release')
BuildSettings::AggregateTargetSettings.new(aggregate_target, configuration_name, :configuration => configuration_name.downcase.to_sym)
end
describe 'memoization' do
it 'memoizes methods when requested' do
cls = Class.new(BuildSettings) do
define_build_settings_method :foobar, :memoized => true do
Object.new
end
end
settings = cls.new(stub('Target'))
object = settings.foobar
object.should.be.frozen
object.should.equal?(settings.foobar)
end
it 'memoizes array methods when requested' do
cls = Class.new(BuildSettings) do
define_build_settings_method :foobar, :memoized => true, :sorted => true, :uniqued => true do
%w(b a c a)
end
end
settings = cls.new(stub('Target'))
object = settings.foobar
object.should.be.frozen
object.should == %w(a b c)
object.should.equal?(settings.foobar)
end
end
#---------------------------------------------------------------------#
describe '::add_developers_frameworks_if_needed' do
it 'adds the developer frameworks search paths to the xcconfig if SenTestingKit has been detected' do
xcconfig = BuildSettings.new(stub('Target'))
xcconfig.stubs(:frameworks => %w(SenTestingKit))
frameworks_search_paths = xcconfig.framework_search_paths
frameworks_search_paths.should == %w($(PLATFORM_DIR)/Developer/Library/Frameworks)
end
it 'adds the developer frameworks search paths to the xcconfig if XCTest has been detected' do
xcconfig = BuildSettings.new(stub('Target'))
xcconfig.stubs(:frameworks => %w(XCTest))
frameworks_search_paths = xcconfig.framework_search_paths
frameworks_search_paths.should == %w($(PLATFORM_DIR)/Developer/Library/Frameworks)
end
it 'adds the developer frameworks search paths to the xcconfig if XCTest has been detected as a weak framework' do
xcconfig = BuildSettings.new(stub('Target'))
xcconfig.stubs(:weak_frameworks => %w(XCTest))
frameworks_search_paths = xcconfig.framework_search_paths
frameworks_search_paths.should == %w($(PLATFORM_DIR)/Developer/Library/Frameworks)
end
end
#---------------------------------------------------------------------#
describe '::application_extension_api_only' do
it 'does not set APPLICATION_EXTENSION_API_ONLY missing in the target' do
target = fixture_pod_target('integration/Reachability/Reachability.podspec')
build_settings = pod(target)
other_swift_flags = build_settings.xcconfig.to_hash['APPLICATION_EXTENSION_API_ONLY']
other_swift_flags.should.be.nil
end
it 'does not set APPLICATION_EXTENSION_API_ONLY when false in the target' do
target = fixture_pod_target('integration/Reachability/Reachability.podspec')
target.instance_variable_set(:@application_extension_api_only, false)
build_settings = pod(target)
other_swift_flags = build_settings.xcconfig.to_hash['APPLICATION_EXTENSION_API_ONLY']
other_swift_flags.should.be.nil
end
it 'sets APPLICATION_EXTENSION_API_ONLY to YES when true in the target' do
target = fixture_pod_target('integration/Reachability/Reachability.podspec')
target.instance_variable_set(:@application_extension_api_only, true)
build_settings = pod(target)
other_swift_flags = build_settings.xcconfig.to_hash['APPLICATION_EXTENSION_API_ONLY']
other_swift_flags.should.== 'YES'
end
end
#---------------------------------------------------------------------#
describe '::add_language_specific_settings' do
it 'does not add OTHER_SWIFT_FLAGS to the xcconfig if the target does not use swift' do
target = fixture_pod_target('integration/Reachability/Reachability.podspec')
build_settings = pod(target)
other_swift_flags = build_settings.xcconfig.to_hash['OTHER_SWIFT_FLAGS']
other_swift_flags.should.be.nil
end
it 'does not add the -suppress-warnings flag to the xcconfig if the target uses swift, but does not inhibit warnings' do
target = fixture_pod_target('integration/Reachability/Reachability.podspec')
target.stubs(:uses_swift? => true, :inhibit_warnings? => false)
build_settings = pod(target)
other_swift_flags = build_settings.xcconfig.to_hash['OTHER_SWIFT_FLAGS']
other_swift_flags.should.not.include '-suppress-warnings'
end
it 'adds the -suppress-warnings flag to the xcconfig if the target uses swift and inhibits warnings' do
target = fixture_pod_target('integration/Reachability/Reachability.podspec')
target.stubs(:uses_swift? => true, :inhibit_warnings? => true)
build_settings = pod(target)
other_swift_flags = build_settings.xcconfig.to_hash['OTHER_SWIFT_FLAGS']
other_swift_flags.should.include '-suppress-warnings'
end
end
#---------------------------------------------------------------------#
describe '#merge_spec_xcconfig_into_xcconfig' do
before do
@build_settings = BuildSettings.new(stub('Target'))
@xcconfig = Xcodeproj::Config.new
end
it 'merges into an empty xcconfig' do
@build_settings.send(:merge_spec_xcconfig_into_xcconfig, { 'A' => 'A', 'OTHER_LDFLAGS' => '-f Frame', 'EMPTY' => '' }, @xcconfig)
@xcconfig.to_hash.should == { 'A' => 'A', 'OTHER_LDFLAGS' => '-f Frame', 'EMPTY' => '' }
end
it 'merges into an xcconfig with overlapping settings' do
@xcconfig.merge!('A' => 'NOT A', 'OTHER_LDFLAGS' => '-lLib', 'B' => 'B', 'FRAMEWORK_SEARCH_PATHS' => 'FWSP')
@build_settings.send(:merge_spec_xcconfig_into_xcconfig, { 'A' => 'A', 'OTHER_LDFLAGS' => %w(-f Frame), 'EMPTY' => [] }, @xcconfig)
@xcconfig.to_hash.should == { 'A' => 'A', 'B' => 'B', 'FRAMEWORK_SEARCH_PATHS' => 'FWSP', 'OTHER_LDFLAGS' => '-f Frame -l"Lib"', 'EMPTY' => [] }
end
end
#---------------------------------------------------------------------#
describe 'concerning settings for file accessors' do
it 'does not propagate framework or libraries from a test specification to an aggregate target' do
target_definition = fixture_target_definition(:contents => { 'inheritance' => 'complete' })
spec = stub('spec', :library_specification? => false, :spec_type => :test)
consumer = stub('consumer',
:libraries => ['xml2'],
:frameworks => ['XCTest'],
:weak_frameworks => [],
:spec => spec,
)
file_accessor = stub('file_accessor',
:spec => spec,
:spec_consumer => consumer,
:vendored_static_frameworks => [config.sandbox.root + 'StaticFramework.framework'],
:vendored_static_libraries => [config.sandbox.root + 'libStaticLibrary.a'],
:vendored_static_artifacts => [config.sandbox.root + 'StaticFramework.framework', config.sandbox.root + 'libStaticLibrary.a'],
:vendored_dynamic_frameworks => [config.sandbox.root + 'VendoredFramework.framework'],
:vendored_dynamic_libraries => [config.sandbox.root + 'VendoredDyld.dyld'],
)
pod_target = stub('pod_target',
:file_accessors => [file_accessor],
:requires_frameworks? => true,
:dependent_targets => [],
:recursive_dependent_targets => [],
:sandbox => config.sandbox,
:include_in_build_config? => true,
:should_build? => false,
:spec_consumers => [consumer],
:build_as_static? => false,
:build_as_dynamic? => true,
:build_settings => [],
:product_basename => 'PodTarget',
:target_definitions => [target_definition],
:root_spec => spec,
)
pod_target.stubs(:build_settings_for_spec => pod(pod_target))
aggregate_target = fixture_aggregate_target([pod_target])
aggregate(aggregate_target).other_ldflags.should.not.include '-framework'
end
it 'does not propagate framework or libraries from a app specification to an aggregate target' do
target_definition = fixture_target_definition(:contents => { 'inheritance' => 'complete' })
spec = stub('spec', :library_specification? => false, :spec_type => :app)
consumer = stub('consumer',
:libraries => ['xml2'],
:frameworks => ['XCTest'],
:weak_frameworks => [],
:spec => spec,
)
file_accessor = stub('file_accessor',
:spec => spec,
:spec_consumer => consumer,
:vendored_static_frameworks => [config.sandbox.root + 'StaticFramework.framework'],
:vendored_static_libraries => [config.sandbox.root + 'libStaticLibrary.a'],
:vendored_static_artifacts => [config.sandbox.root + 'StaticFramework.framework', config.sandbox.root + 'libStaticLibrary.a'],
:vendored_dynamic_frameworks => [config.sandbox.root + 'VendoredFramework.framework'],
:vendored_dynamic_libraries => [config.sandbox.root + 'VendoredDyld.dyld'],
)
pod_target = stub('pod_target',
:file_accessors => [file_accessor],
:requires_frameworks? => true,
:dependent_targets => [],
:recursive_dependent_targets => [],
:sandbox => config.sandbox,
:include_in_build_config? => true,
:should_build? => false,
:spec_consumers => [consumer],
:build_as_static? => false,
:build_as_dynamic? => true,
:build_settings => [],
:product_basename => 'PodTarget',
:target_definitions => [target_definition],
:root_spec => spec,
)
pod_target.stubs(:build_settings_for_spec => pod(pod_target))
aggregate_target = fixture_aggregate_target([pod_target])
aggregate(aggregate_target).other_ldflags.should.not.include '-framework'
end
end
describe 'concerning other_ld_flags' do
it 'other_ld_flags should not include -ObjC when there are not static frameworks' do
target_definition = fixture_target_definition(:contents => { 'inheritance' => 'complete' })
spec = stub('spec', :library_specification? => false, :spec_type => :test)
consumer = stub('consumer',
:libraries => ['xml2'],
:frameworks => ['XCTest'],
:weak_frameworks => [],
:spec => spec,
)
file_accessor = stub('file_accessor',
:spec => spec,
:spec_consumer => consumer,
:vendored_static_artifacts => [],
)
pod_target = stub('pod_target',
:file_accessors => [file_accessor],
:requires_frameworks? => true,
:dependent_targets => [],
:recursive_dependent_targets => [],
:sandbox => config.sandbox,
:include_in_build_config? => true,
:should_build? => false,
:spec_consumers => [consumer],
:build_as_static? => false,
:build_as_dynamic? => true,
:build_settings => [],
:product_basename => 'PodTarget',
:target_definitions => [target_definition],
:root_spec => spec,
)
pod_target.stubs(:build_settings_for_spec => pod(pod_target))
aggregate_target = fixture_aggregate_target([pod_target], true)
aggregate(aggregate_target).other_ldflags.should.not.include '-ObjC'
end
it 'other_ld_flags should include -ObjC when linking static frameworks' do
target_definition = fixture_target_definition(:contents => { 'inheritance' => 'complete' })
spec = stub('spec', :library_specification? => true, :spec_type => :library)
consumer = stub('consumer',
:libraries => ['xml2'],
:frameworks => ['XCTest'],
:weak_frameworks => [],
:spec => spec,
)
file_accessor = stub('file_accessor',
:spec => spec,
:spec_consumer => consumer,
:vendored_static_artifacts => [],
:vendored_static_libraries => [],
:vendored_dynamic_libraries => [],
:vendored_static_frameworks => [],
:vendored_dynamic_frameworks => [],
:vendored_xcframeworks => [],
)
pod_target = stub('pod_target',
:file_accessors => [file_accessor],
:requires_frameworks? => true,
:dependent_targets => [],
:recursive_dependent_targets => [],
:sandbox => config.sandbox,
:include_in_build_config? => true,
:should_build? => false,
:spec_consumers => [consumer],
:build_as_static? => true,
:build_as_dynamic? => false,
:build_settings => [],
:product_basename => 'PodTarget',
:target_definitions => [target_definition],
:root_spec => spec,
)
pod_target.stubs(:build_settings_for_spec => pod(pod_target))
aggregate_target = fixture_aggregate_target([pod_target], true)
aggregate(aggregate_target).other_ldflags.should.include '-ObjC'
end
it 'other_ld_flags should include -ObjC when linking vendored static frameworks' do
target_definition = fixture_target_definition(:contents => { 'inheritance' => 'complete' })
spec = stub('spec', :library_specification? => true, :spec_type => :library)
consumer = stub('consumer',
:libraries => ['xml2'],
:frameworks => ['XCTest'],
:weak_frameworks => [],
:spec => spec,
)
file_accessor = stub('file_accessor',
:spec => spec,
:spec_consumer => consumer,
:vendored_static_artifacts => ['Foo'],
:vendored_static_libraries => [],
:vendored_dynamic_libraries => [],
:vendored_static_frameworks => [],
:vendored_dynamic_frameworks => [],
:vendored_xcframeworks => [],
)
pod_target = stub('pod_target',
:any_vendored_static_artifacts? => true,
:file_accessors => [file_accessor],
:requires_frameworks? => true,
:dependent_targets => [],
:recursive_dependent_targets => [],
:sandbox => config.sandbox,
:include_in_build_config? => true,
:should_build? => false,
:spec_consumers => [consumer],
:build_as_static? => false,
:build_as_dynamic? => false,
:build_settings => [],
:product_basename => 'PodTarget',
:target_definitions => [target_definition],
:root_spec => spec,
)
pod_target.stubs(:build_settings_for_spec => pod(pod_target))
aggregate_target = fixture_aggregate_target([pod_target], true)
aggregate(aggregate_target).other_ldflags.should.include '-ObjC'
end
it 'other_ld_flags should include -ObjC when linking vendored static xcframeworks' do
target_definition = fixture_target_definition(:contents => { 'inheritance' => 'complete' })
spec = stub('spec', :library_specification? => true, :spec_type => :library)
consumer = stub('consumer',
:libraries => ['xml2'],
:frameworks => ['XCTest'],
:weak_frameworks => [],
:spec => spec,
)
file_accessor = stub('file_accessor',
:spec => spec,
:spec_consumer => consumer,
:vendored_static_artifacts => [1, 2, 3],
:vendored_static_libraries => [],
:vendored_dynamic_libraries => [],
:vendored_static_frameworks => [],
:vendored_dynamic_frameworks => [],
:vendored_xcframeworks => [],
)
pod_target = stub('pod_target',
:any_vendored_static_artifacts? => true,
:file_accessors => [file_accessor],
:requires_frameworks? => true,
:dependent_targets => [],
:recursive_dependent_targets => [],
:sandbox => config.sandbox,
:include_in_build_config? => true,
:should_build? => false,
:spec_consumers => [consumer],
:build_as_static? => false,
:build_as_dynamic? => false,
:product_basename => 'PodTarget',
:target_definitions => [target_definition],
:root_spec => spec,
:configuration => 0,
)
pod_target.stubs(:build_settings_for_spec => pod(pod_target))
aggregate_target = fixture_aggregate_target([pod_target], true)
aggregate(aggregate_target).other_ldflags.should.include '-ObjC'
end
it 'other_ld_flags should include not -ObjC when linking vendored dynamic xcframeworks' do
target_definition = fixture_target_definition(:contents => { 'inheritance' => 'complete' })
spec = stub('spec', :library_specification? => true, :spec_type => :library)
consumer = stub('consumer',
:libraries => ['xml2'],
:frameworks => ['XCTest'],
:weak_frameworks => [],
:spec => spec,
)
file_accessor = stub('file_accessor',
:spec => spec,
:spec_consumer => consumer,
:vendored_static_artifacts => [],
:vendored_static_libraries => [],
:vendored_dynamic_libraries => [],
:vendored_static_frameworks => [],
:vendored_dynamic_frameworks => [],
:vendored_xcframeworks => [],
)
pod_target = stub('pod_target',
:any_vendored_static_artifacts? => true,
:file_accessors => [file_accessor],
:requires_frameworks? => true,
:dependent_targets => [],
:recursive_dependent_targets => [],
:sandbox => config.sandbox,
:include_in_build_config? => true,
:should_build? => false,
:spec_consumers => [consumer],
:build_as_static? => false,
:build_as_dynamic? => false,
:product_basename => 'PodTarget',
:target_definitions => [target_definition],
:root_spec => spec,
:configuration => 0,
)
pod_target.stubs(:build_settings_for_spec => pod(pod_target))
aggregate_target = fixture_aggregate_target([pod_target], true)
aggregate(aggregate_target).other_ldflags.should.not.include '-ObjC'
end
end
#---------------------------------------------------------------------#
end
end
end