forked from CocoaPods/CocoaPods
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pod_target.rb
1168 lines (1045 loc) · 46.8 KB
/
pod_target.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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
require 'cocoapods/xcode/framework_paths'
require 'cocoapods/xcode/xcframework'
module Pod
# Stores the information relative to the target used to compile a single Pod.
# A pod can have one or more activated spec, subspecs and test specs.
#
class PodTarget < Target
# @return [Array<Specification>] the spec, subspecs and test specs of the target.
#
attr_reader :specs
# @return [Array<Specification>] All of the test specs within this target.
# Subset of #specs.
#
attr_reader :test_specs
# @return [Array<Specification>] All of the specs within this target that are library specs.
# Subset of #specs.
#
attr_reader :library_specs
# @return [Array<Specification>] All of the specs within this target that are app specs.
# Subset of #specs.
#
attr_reader :app_specs
# @return [Array<TargetDefinition>] the target definitions of the Podfile
# that generated this target.
#
attr_reader :target_definitions
# @return [Array<Sandbox::FileAccessor>] the file accessors for the
# specifications of this target.
#
attr_reader :file_accessors
# @return [String] the suffix used for this target when deduplicated. May be `nil`.
#
# @note This affects the value returned by #configuration_build_dir
# and accessors relying on this as #build_product_path.
#
attr_reader :scope_suffix
# @return [HeadersStore] the header directory for the target.
#
attr_reader :build_headers
# @return [Array<PodTarget>] the targets that this target has a dependency
# upon.
#
attr_reader :dependent_targets
attr_reader :dependent_targets_by_config
# @deprecated
def dependent_targets=(dependent_targets)
@dependent_targets = dependent_targets
@dependent_targets_by_config = { :debug => dependent_targets, :release => dependent_targets }
end
def dependent_targets_by_config=(dependent_targets_by_config)
@dependent_targets_by_config = dependent_targets_by_config
@dependent_targets = dependent_targets_by_config.each_value.reduce([], &:|)
end
# @return [Hash{String=>Array<PodTarget>}] all target dependencies by test spec name.
#
attr_reader :test_dependent_targets_by_spec_name
attr_reader :test_dependent_targets_by_spec_name_by_config
# @deprecated
def test_dependent_targets_by_spec_name=(test_dependent_targets_by_spec_name)
@test_dependent_targets_by_spec_name = test_dependent_targets_by_spec_name
@test_dependent_targets_by_spec_name_by_config = Hash[test_dependent_targets_by_spec_name.map do |k, v|
[k, { :debug => v, :release => v }]
end]
end
def test_dependent_targets_by_spec_name_by_config=(test_dependent_targets_by_spec_name_by_config)
@test_dependent_targets_by_spec_name_by_config = test_dependent_targets_by_spec_name_by_config
@test_dependent_targets_by_spec_name = Hash[test_dependent_targets_by_spec_name_by_config.map do |k, v|
[k, v.each_value.reduce(Set.new, &:|).to_a]
end]
end
# @return [Hash{String=>Array<PodTarget>}] all target dependencies by app spec name.
#
attr_reader :app_dependent_targets_by_spec_name
attr_reader :app_dependent_targets_by_spec_name_by_config
# @deprecated
def app_dependent_targets_by_spec_name=(app_dependent_targets_by_spec_name)
@app_dependent_targets_by_spec_name = app_dependent_targets_by_spec_name
@app_dependent_targets_by_spec_name_by_config = Hash[app_dependent_targets_by_spec_name.map do |k, v|
[k, { :debug => v, :release => v }]
end]
end
def app_dependent_targets_by_spec_name_by_config=(app_dependent_targets_by_spec_name_by_config)
@app_dependent_targets_by_spec_name_by_config = app_dependent_targets_by_spec_name_by_config
@app_dependent_targets_by_spec_name = Hash[app_dependent_targets_by_spec_name_by_config.map do |k, v|
[k, v.each_value.reduce(Set.new, &:|).to_a]
end]
end
# @return [Hash{Specification => (Specification,PodTarget)}] tuples of app specs and pod targets by test spec.
#
attr_accessor :test_app_hosts_by_spec
# @return [Hash{String => BuildSettings}] the test spec build settings for this target.
#
attr_reader :test_spec_build_settings
attr_reader :test_spec_build_settings_by_config
# @return [Hash{String => BuildSettings}] the app spec build settings for this target.
#
attr_reader :app_spec_build_settings
attr_reader :app_spec_build_settings_by_config
# @return [String] the Swift version for this target.
#
attr_reader :swift_version
# Initialize a new instance
#
# @param [Sandbox] sandbox @see Target#sandbox
# @param [BuildType] build_type @see Target#build_type
# @param [Hash{String=>Symbol}] user_build_configurations @see Target#user_build_configurations
# @param [Array<String>] archs @see Target#archs
# @param [Platform] platform @see Target#platform
# @param [Array<Specification>] specs @see #specs
# @param [Array<TargetDefinition>] target_definitions @see #target_definitions
# @param [Array<Sandbox::FileAccessor>] file_accessors @see #file_accessors
# @param [String] scope_suffix @see #scope_suffix
# @param [String] swift_version @see #swift_version
#
def initialize(sandbox, build_type, user_build_configurations, archs, platform, specs, target_definitions,
file_accessors = [], scope_suffix = nil, swift_version = nil)
super(sandbox, build_type, user_build_configurations, archs, platform)
raise "Can't initialize a PodTarget without specs!" if specs.nil? || specs.empty?
raise "Can't initialize a PodTarget without TargetDefinition!" if target_definitions.nil? || target_definitions.empty?
raise "Can't initialize a PodTarget with an empty string scope suffix!" if scope_suffix == ''
@specs = specs.dup.freeze
@target_definitions = target_definitions
@file_accessors = file_accessors
@scope_suffix = scope_suffix
@swift_version = swift_version
all_specs_by_type = @specs.group_by(&:spec_type)
@library_specs = all_specs_by_type[:library] || []
@test_specs = all_specs_by_type[:test] || []
@app_specs = all_specs_by_type[:app] || []
@build_headers = Sandbox::HeadersStore.new(sandbox, 'Private', :private)
self.dependent_targets = []
self.test_dependent_targets_by_spec_name = Hash[test_specs.map { |ts| [ts.name, []] }]
self.app_dependent_targets_by_spec_name = Hash[app_specs.map { |as| [as.name, []] }]
@test_app_hosts_by_spec = {}
@build_config_cache = {}
@test_spec_build_settings_by_config = create_test_build_settings_by_config
@app_spec_build_settings_by_config = create_app_build_settings_by_config
end
# Scopes the current target based on the existing pod targets within the cache.
#
# @param [Hash{Array => PodTarget}] cache
# the cached target for a previously scoped target.
#
# @return [Array<PodTarget>] a scoped copy for each target definition.
#
def scoped(cache = {})
target_definitions.map do |target_definition|
cache_key = [specs, target_definition]
cache[cache_key] ||= begin
target = PodTarget.new(sandbox, build_type, user_build_configurations, archs, platform, specs,
[target_definition], file_accessors, target_definition.label, swift_version)
scope_dependent_targets = ->(dependent_targets) do
dependent_targets.flat_map do |pod_target|
pod_target.scoped(cache).select { |pt| pt.target_definitions == [target_definition] }
end
end
target.dependent_targets_by_config = Hash[dependent_targets_by_config.map { |k, v| [k, scope_dependent_targets[v]] }]
target.test_dependent_targets_by_spec_name_by_config = Hash[test_dependent_targets_by_spec_name_by_config.map do |spec_name, test_pod_targets_by_config|
[spec_name, Hash[test_pod_targets_by_config.map { |k, v| [k, scope_dependent_targets[v]] }]]
end]
target.app_dependent_targets_by_spec_name_by_config = Hash[app_dependent_targets_by_spec_name_by_config.map do |spec_name, app_pod_targets_by_config|
[spec_name, Hash[app_pod_targets_by_config.map { |k, v| [k, scope_dependent_targets[v]] }]]
end]
target.test_app_hosts_by_spec = Hash[test_app_hosts_by_spec.map do |spec, (app_host_spec, app_pod_target)|
[spec, [app_host_spec, app_pod_target.scoped(cache).find { |pt| pt.target_definitions == [target_definition] }]]
end]
target
end
end
end
# @return [String] the label for the target.
#
def label
if scope_suffix.nil? || scope_suffix[0] == '.'
"#{root_spec.name}#{scope_suffix}"
else
"#{root_spec.name}-#{scope_suffix}"
end
end
# @return [Array<String>] The list of all files tracked.
#
def all_files
Sandbox::FileAccessor.all_files(file_accessors)
end
# @return [Pathname] the pathname for headers in the sandbox.
#
def headers_sandbox
Pathname.new(pod_name)
end
# @return [Hash{FileAccessor => Hash}] Hash of file accessors by header mappings.
#
def header_mappings_by_file_accessor
valid_accessors = file_accessors.reject { |fa| fa.spec.non_library_specification? }
Hash[valid_accessors.map do |file_accessor|
# Private headers will always end up in Pods/Headers/Private/PodA/*.h
# This will allow for `""` imports to work.
[file_accessor, header_mappings(file_accessor, file_accessor.headers)]
end]
end
# @return [Hash{FileAccessor => Hash}] Hash of file accessors by public header mappings.
#
def public_header_mappings_by_file_accessor
valid_accessors = file_accessors.reject { |fa| fa.spec.non_library_specification? }
Hash[valid_accessors.map do |file_accessor|
# Public headers on the other hand will be added in Pods/Headers/Public/PodA/PodA/*.h
# The extra folder is intentional in order for `<>` imports to work.
[file_accessor, header_mappings(file_accessor, file_accessor.public_headers)]
end]
end
# @return [Array<Version>] the Swift versions supported. Might be empty if the author has not
# specified any versions, most likely due to legacy reasons.
#
def spec_swift_versions
root_spec.swift_versions
end
# @return [Podfile] The podfile which declares the dependency.
#
def podfile
target_definitions.first.podfile
end
# @return [String] the project name derived from the target definitions that integrate this pod. If none is
# specified then the name of the pod is used by default.
#
# @note The name is guaranteed to be the same across all target definitions and is validated by the target
# validator during installation.
#
def project_name
target_definitions.map { |td| td.project_name_for_pod(pod_name) }.compact.first || pod_name
end
# @return [String] The name to use for the source code module constructed
# for this target, and which will be used to import the module in
# implementation source files.
#
def product_module_name
root_spec.module_name
end
# @param [Specification] spec the specification
#
# @return [String] the product basename of the specification's target
def product_basename_for_spec(spec)
user_specified = build_settings_by_config_for_spec(spec).
each_value.
map { |settings| settings.merged_pod_target_xcconfigs['PRODUCT_NAME'] }.
compact.
uniq
if user_specified.size == 1
user_specified.first
else
spec_label(spec)
end
end
# @return [Bool] Whether or not this target should be built.
#
# A target should not be built if it has no source files.
#
def should_build?
return @should_build if defined? @should_build
accessors = file_accessors.select { |fa| fa.spec.library_specification? }
source_files = accessors.flat_map(&:source_files)
source_files -= accessors.flat_map(&:headers)
@should_build = !source_files.empty?
end
# @return [Array<Specification::Consumer>] the specification consumers for
# the target.
#
def spec_consumers
specs.map { |spec| spec.consumer(platform) }
end
# @return [Array<Specification::Consumer>] the test specification consumers for
# the target.
#
def test_spec_consumers
test_specs.map { |test_spec| test_spec.consumer(platform) }
end
# @return [Array<Specification::Consumer>] the app specification consumers for
# the target.
#
def app_spec_consumers
app_specs.map { |app_spec| app_spec.consumer(platform) }
end
# Checks whether the target itself plus its specs uses Swift code.
# This check excludes source files from non library specs.
# Note that if a target does not need to be built (no source code),
# we fallback to check whether it indicates a swift version.
#
# @return [Boolean] Whether the target uses Swift code.
#
def uses_swift?
return @uses_swift if defined? @uses_swift
@uses_swift = (!should_build? && !spec_swift_versions.empty?) ||
file_accessors.select { |a| a.spec.library_specification? }.any? do |file_accessor|
uses_swift_for_spec?(file_accessor.spec)
end
end
# Checks whether a specification uses Swift or not.
#
# @param [Specification] spec
# The spec to query against.
#
# @return [Boolean] Whether the target uses Swift code within the requested non library spec.
#
def uses_swift_for_spec?(spec)
@uses_swift_for_spec_cache ||= {}
return @uses_swift_for_spec_cache[spec.name] if @uses_swift_for_spec_cache.key?(spec.name)
@uses_swift_for_spec_cache[spec.name] = begin
file_accessor = file_accessors.find { |fa| fa.spec == spec }
raise "[Bug] Unable to find file accessor for spec `#{spec.inspect}` in pod target `#{label}`" unless file_accessor
file_accessor.source_files.any? { |sf| sf.extname == '.swift' }
end
end
# @return [Boolean] Whether the target defines a "module"
# (and thus will need a module map and umbrella header).
#
# @note Static library targets can temporarily opt in to this behavior by setting
# `DEFINES_MODULE = YES` in their specification's `pod_target_xcconfig`.
#
def defines_module?
return @defines_module if defined?(@defines_module)
return @defines_module = true if uses_swift? || build_as_framework?
explicit_target_definitions = target_definitions.select { |td| td.dependencies.any? { |d| d.root_name == pod_name } }
tds_by_answer = explicit_target_definitions.group_by { |td| td.build_pod_as_module?(pod_name) }
if tds_by_answer.size > 1
UI.warn "Unable to determine whether to build `#{label}` as a module due to a conflict " \
"between the following target definitions:\n\t- #{tds_by_answer.map do |a, td|
"`#{td.to_sentence}` #{a ? "requires `#{label}` as a module" : "does not require `#{label}` as a module"}"
end.join("\n\t- ")}\n\n" \
"Defaulting to skip building `#{label}` as a module."
elsif tds_by_answer.keys.first == true || target_definitions.all? { |td| td.build_pod_as_module?(pod_name) }
return @defines_module = true
end
@defines_module = library_specs.any? { |s| s.consumer(platform).pod_target_xcconfig['DEFINES_MODULE'] == 'YES' }
end
# @return [Array<Hash{Symbol=>String}>] An array of hashes where each hash represents a single script phase.
#
def script_phases
spec_consumers.flat_map(&:script_phases)
end
# @return [Boolean] Whether the target contains any script phases.
#
def contains_script_phases?
!script_phases.empty?
end
# @return [Boolean] Whether the target has any tests specifications.
#
def contains_test_specifications?
!test_specs.empty?
end
# @return [Boolean] Whether the target has any app specifications.
#
def contains_app_specifications?
!app_specs.empty?
end
# @return [Hash{String=>Array<Xcode::FrameworkPaths>}] The vendored and non vendored framework paths this target
# depends upon keyed by spec name. For the root spec and subspecs the framework path of the target itself
# is included.
#
def framework_paths
@framework_paths ||= begin
file_accessors.each_with_object({}) do |file_accessor, hash|
frameworks = file_accessor.vendored_dynamic_artifacts.map do |framework_path|
relative_path_to_sandbox = framework_path.relative_path_from(sandbox.root)
framework_source = "${PODS_ROOT}/#{relative_path_to_sandbox}"
# Until this can be configured, assume the dSYM file uses the file name as the framework.
# See https://github.com/CocoaPods/CocoaPods/issues/1698
dsym_name = "#{framework_path.basename}.dSYM"
dsym_path = Pathname.new("#{framework_path.dirname}/#{dsym_name}")
dsym_source = if dsym_path.exist?
"${PODS_ROOT}/#{relative_path_to_sandbox}.dSYM"
end
dirname = framework_path.dirname
bcsymbolmap_paths = if dirname.exist?
Dir.chdir(dirname) do
Dir.glob('*.bcsymbolmap').map do |bcsymbolmap_file_name|
bcsymbolmap_path = dirname + bcsymbolmap_file_name
"${PODS_ROOT}/#{bcsymbolmap_path.relative_path_from(sandbox.root)}"
end
end
end
Xcode::FrameworkPaths.new(framework_source, dsym_source, bcsymbolmap_paths)
end
if file_accessor.spec.library_specification? && should_build? && build_as_dynamic_framework?
frameworks << Xcode::FrameworkPaths.new(build_product_path('${BUILT_PRODUCTS_DIR}'))
end
hash[file_accessor.spec.name] = frameworks
end
end
end
# @return [Hash{String=>Array<Xcode::XCFramework>}] The vendored xcframeworks this target
# depends upon keyed by spec name.
#
def xcframeworks
@xcframeworks ||= begin
file_accessors.each_with_object({}) do |file_accessor, hash|
frameworks = file_accessor.vendored_xcframeworks.map do |framework_path|
Xcode::XCFramework.new(file_accessor.spec.name, framework_path)
end
hash[file_accessor.spec.name] = frameworks
end
end
end
# @return [Hash{String=>Array<String>}] The resource and resource bundle paths this target depends upon keyed by
# spec name. Resource (not resource bundles) paths can vary depending on the type of spec:
# - App specs _always_ get their resource paths added to "Copy Bundle Resources" phase from
# [PodTargetInstaller] therefore their resource paths are never included here.
# - Test specs may have their resource paths added to "Copy Bundle Resources" if the target itself is
# built as a framework, which is again checked and handled by PodTargetInstaller. If that is true then
# the resource paths are not included, otherwise they are included and handled via the CocoaPods copy
# resources script phase.
# - Library specs _do not_ have per-configuration CocoaPods copy resources script phase and their resource
# paths will be added to "Copy Bundle Resources" phase if the target is built as a framework because
# it supports it. We always include the resource paths for library specs because they are also
# integrated to the user target.
#
def resource_paths
@resource_paths ||= begin
file_accessors.each_with_object({}) do |file_accessor, hash|
resource_paths = if file_accessor.spec.app_specification? || (file_accessor.spec.test_specification? && build_as_framework?)
[]
else
file_accessor.resources.map do |res|
"${PODS_ROOT}/#{res.relative_path_from(sandbox.project_path.dirname)}"
end
end
prefix = Pod::Target::BuildSettings::CONFIGURATION_BUILD_DIR_VARIABLE
prefix = configuration_build_dir unless file_accessor.spec.test_specification?
resource_bundle_paths = file_accessor.resource_bundles.keys.map { |name| "#{prefix}/#{name.shellescape}.bundle" }
hash[file_accessor.spec.name] = (resource_paths + resource_bundle_paths).map(&:to_s)
end
end
end
# @param [Specification] spec The non library spec to calculate the deployment target for.
#
# @return [String] The deployment target to use for the non library spec. If the non library spec explicitly
# specifies one then this is the one used otherwise the one that was determined by the analyzer is used.
#
def deployment_target_for_non_library_spec(spec)
raise ArgumentError, 'Must be a non library spec.' unless spec.non_library_specification?
spec.deployment_target(platform.name.to_s) || platform.deployment_target.to_s
end
# Returns the corresponding native product type to use given the test type.
# This is primarily used when creating the native targets in order to produce the correct test bundle target
# based on the type of tests included.
#
# @param [Symbol] test_type
# The test type to map to provided by the test specification DSL.
#
# @return [Symbol] The native product type to use.
#
def product_type_for_test_type(test_type)
case test_type
when :unit
:unit_test_bundle
when :ui
:ui_test_bundle
else
raise ArgumentError, "Unknown test type `#{test_type}`."
end
end
# Returns the label to use for the given test type.
# This is used to generate native target names for test specs.
#
# @param [Symbol] test_type
# The test type to map to provided by the test specification DSL.
#
# @return [String] The native product type to use.
#
def label_for_test_type(test_type)
case test_type
when :unit
'Unit'
when :ui
'UI'
else
raise ArgumentError, "Unknown test type `#{test_type}`."
end
end
# @return [Specification] The root specification for the target.
#
def root_spec
@root_spec ||= specs.first.root
end
# @return [String] The name of the Pod that this target refers to.
#
def pod_name
root_spec.name
end
# @return [Pathname] the absolute path of the LLVM module map file that
# defines the module structure for the compiler.
#
def module_map_path
basename = "#{label}.modulemap"
if build_as_framework?
super
elsif file_accessors.any?(&:module_map)
build_headers.root + product_module_name + basename
else
sandbox.public_headers.root + product_module_name + basename
end
end
# @return [Pathname] the absolute path of the prefix header file.
#
def prefix_header_path
support_files_dir + "#{label}-prefix.pch"
end
# @return [Hash] the additional entries to add to the generated Info.plist
#
def info_plist_entries
root_spec.info_plist
end
# @param [String] bundle_name
# The name of the bundle product, which is given by the +spec+.
#
# @return [String] The derived name of the resource bundle target.
#
def resources_bundle_target_label(bundle_name)
"#{label}-#{bundle_name}"
end
# @param [Specification] subspec
# The subspec to use for producing the label.
#
# @return [String] The derived name of the target.
#
def subspec_label(subspec)
raise ArgumentError, 'Must not be a root spec' if subspec.root?
subspec.name.split('/')[1..-1].join('-').to_s
end
# @param [Specification] test_spec
# The test spec to use for producing the test label.
#
# @return [String] The derived name of the test target.
#
def test_target_label(test_spec)
"#{label}-#{label_for_test_type(test_spec.test_type)}-#{subspec_label(test_spec)}"
end
# @param [Specification] app_spec
# The app spec to use for producing the app label.
#
# @return [String] The derived name of the app target.
#
def app_target_label(app_spec)
"#{label}-#{subspec_label(app_spec)}"
end
# @param [Specification] test_spec
# the test spec to use for producing the app host target label.
#
# @return [(String,String)] a tuple, where the first item is the PodTarget#label of the pod target that defines the
# app host, and the second item is the target name of the app host
#
def app_host_target_label(test_spec)
app_spec, app_target = test_app_hosts_by_spec[test_spec]
if app_spec
[app_target.name, app_target.app_target_label(app_spec)]
elsif test_spec.consumer(platform).requires_app_host?
[name, "AppHost-#{label}-#{label_for_test_type(test_spec.test_type)}-Tests"]
end
end
# @param [Specification] spec
# the spec to return app host dependencies for
#
# @param [String] configuration
# the configuration to retrieve the app host dependent targets for.
#
# @return [Array<PodTarget>] the app host dependent targets for the given spec.
#
def app_host_dependent_targets_for_spec(spec, configuration: nil)
return [] unless spec.test_specification? && spec.consumer(platform).test_type == :unit
app_host_info = test_app_hosts_by_spec[spec]
if app_host_info.nil?
[]
else
app_spec, app_target = *app_host_info
app_target.dependent_targets_for_app_spec(app_spec, :configuration => configuration)
end
end
def spec_label(spec)
case spec.spec_type
when :library then label
when :test then test_target_label(spec)
when :app then app_target_label(spec)
else raise ArgumentError, "Unhandled spec type #{spec.spec_type.inspect} for #{spec.inspect}"
end
end
# for backwards compatibility
alias non_library_spec_label spec_label
# @param [Specification] spec
# The spec to return scheme configuration for.
#
# @return [Hash] The scheme configuration used or empty if none is specified.
#
def scheme_for_spec(spec)
return {} if (spec.library_specification? && !spec.root?) || spec.available_platforms.none? do |p|
p.name == platform.name
end
spec.consumer(platform).scheme
end
# @param [Specification] spec
# The spec this copy resources script path is for.
#
# @return [Pathname] The absolute path of the copy resources script for the given spec.
#
def copy_resources_script_path_for_spec(spec)
support_files_dir + "#{spec_label(spec)}-resources.sh"
end
# @param [Specification] spec
# The spec this copy resources script path is for.
#
# @return [Pathname] The absolute path of the copy resources script input file list for the given spec.
#
def copy_resources_script_input_files_path_for_spec(spec)
support_files_dir + "#{spec_label(spec)}-resources-input-files.xcfilelist"
end
# @param [Specification] spec
# The spec this copy resources script path is for.
#
# @return [Pathname] The absolute path of the copy resources script output file list for the given spec.
#
def copy_resources_script_output_files_path_for_spec(spec)
support_files_dir + "#{spec_label(spec)}-resources-output-files.xcfilelist"
end
# @param [Specification] spec
# The spec this embed frameworks script path is for.
#
# @return [Pathname] The absolute path of the embed frameworks script for the given spec.
#
def embed_frameworks_script_path_for_spec(spec)
support_files_dir + "#{spec_label(spec)}-frameworks.sh"
end
# @param [Specification] spec
# The spec this embed frameworks script path is for.
#
# @return [Pathname] The absolute path of the embed frameworks script input file list for the given spec.
#
def embed_frameworks_script_input_files_path_for_spec(spec)
support_files_dir + "#{spec_label(spec)}-frameworks-input-files.xcfilelist"
end
# @param [Specification] spec
# The spec this embed frameworks script path is for.
#
# @return [Pathname] The absolute path of the embed frameworks script output file list for the given spec.
#
def embed_frameworks_script_output_files_path_for_spec(spec)
support_files_dir + "#{spec_label(spec)}-frameworks-output-files.xcfilelist"
end
# @return [Pathname] The absolute path of the copy xcframeworks script.
#
def copy_xcframeworks_script_path
support_files_dir + "#{label}-xcframeworks.sh"
end
# @return [String] The path of the copy xcframeworks input files file list
#
def copy_xcframeworks_script_input_files_path
support_files_dir + "#{label}-xcframeworks-input-files.xcfilelist"
end
# @return [String] The path of the copy xcframeworks output files file list
#
def copy_xcframeworks_script_output_files_path
support_files_dir + "#{label}-xcframeworks-output-files.xcfilelist"
end
# @param [Specification] spec
# The spec this script path is for.
#
# @return [Pathname] The absolute path of the prepare artifacts script for the given spec.
#
# @deprecated
#
# @todo Remove in 2.0
#
def prepare_artifacts_script_path_for_spec(spec)
support_files_dir + "#{spec_label(spec)}-artifacts.sh"
end
# @param [Specification] spec
# The spec this script path is for.
#
# @return [Pathname] The absolute path of the prepare artifacts script input file list for the given spec.
#
# @deprecated
#
# @todo Remove in 2.0
#
def prepare_artifacts_script_input_files_path_for_spec(spec)
support_files_dir + "#{spec_label(spec)}-artifacts-input-files.xcfilelist"
end
# @param [Specification] spec
# The spec this script path is for.
#
# @return [Pathname] The absolute path of the prepare artifacts script output file list for the given spec.
#
# @deprecated
#
# @todo Remove in 2.0
#
def prepare_artifacts_script_output_files_path_for_spec(spec)
support_files_dir + "#{spec_label(spec)}-artifacts-output-files.xcfilelist"
end
# @return [Pathname] The absolute path of the copy dSYMs script.
#
def copy_dsyms_script_path
support_files_dir + "#{label}-copy-dsyms.sh"
end
# @return [Pathname] The absolute path of the copy dSYM script phase input file list.
#
def copy_dsyms_script_input_files_path
support_files_dir + "#{label}-copy-dsyms-input-files.xcfilelist"
end
# @return [Pathname] The absolute path of the copy dSYM script phase output file list.
#
def copy_dsyms_script_output_files_path
support_files_dir + "#{label}-copy-dsyms-output-files.xcfilelist"
end
# @param [Specification] spec
# The spec this Info.plist path is for.
#
# @return [Pathname] The absolute path of the Info.plist for the given spec.
#
def info_plist_path_for_spec(spec)
support_files_dir + "#{spec_label(spec)}-Info.plist"
end
# @param [Specification] spec
# The spec this prefix header path is for.
#
# @return [Pathname] the absolute path of the prefix header file for the given spec.
#
def prefix_header_path_for_spec(spec)
support_files_dir + "#{spec_label(spec)}-prefix.pch"
end
# @return [Array<String>] The names of the Pods on which this target
# depends.
#
def dependencies
spec_consumers.flat_map do |consumer|
consumer.dependencies.map { |dep| Specification.root_name(dep.name) }
end.uniq
end
# Returns all dependent targets of this target. If a configuration is passed then the list can be scoped to a given
# configuration.
#
# @param [String] configuration
# The configuration to return the dependent targets for or `nil` if all configurations should be included.
#
# @return [Array<PodTarget>] the recursive targets that this target has a dependency upon.
#
def recursive_dependent_targets(configuration: nil)
@recursive_dependent_targets ||= begin
hash = Hash[config_variants.map do |config|
[config, _add_recursive_dependent_targets(Set.new, :configuration => config).delete(self).to_a.freeze]
end]
hash[nil] = hash.each_value.reduce(Set.new, &:|).to_a
hash
end
@recursive_dependent_targets.fetch(configuration) { raise ArgumentError, "No configuration #{configuration} for #{self}, known configurations are #{@recursive_dependent_targets.keys}" }
end
def _add_recursive_dependent_targets(set, configuration: nil)
if defined?(@recursive_dependent_targets)
return set.merge(@recursive_dependent_targets[configuration])
end
dependent_targets = configuration ? dependent_targets_by_config[configuration] : self.dependent_targets
dependent_targets.each do |target|
target._add_recursive_dependent_targets(set, :configuration => configuration) if set.add?(target)
end
set
end
protected :_add_recursive_dependent_targets
# @param [Specification] test_spec
# the test spec to scope dependencies for
#
# @param [String] configuration
# the configuration to retrieve the test dependent targets for.
#
# @return [Array<PodTarget>] the recursive targets that this target has a
# test dependency upon.
#
def recursive_test_dependent_targets(test_spec, configuration: nil)
@recursive_test_dependent_targets ||= {}
@recursive_test_dependent_targets[test_spec] ||= begin
hash = Hash[config_variants.map do |config|
[config, _add_recursive_test_dependent_targets(test_spec, Set.new, :configuration => config).to_a.freeze]
end]
hash[nil] = hash.each_value.reduce(Set.new, &:|).to_a.freeze
hash
end
@recursive_test_dependent_targets[test_spec][configuration]
end
def _add_recursive_test_dependent_targets(test_spec, set, configuration: nil)
raise ArgumentError, 'Must give a test spec' unless test_spec
dependent_targets = configuration ? test_dependent_targets_by_spec_name_by_config[test_spec.name][configuration] : test_dependent_targets_by_spec_name[test_spec.name]
raise ArgumentError, "Unable to find deps for #{test_spec} for config #{configuration.inspect} (out of #{test_dependent_targets_by_spec_name_by_config.inspect})" unless dependent_targets
dependent_targets.each do |target|
target._add_recursive_dependent_targets(set, :configuration => configuration) if set.add?(target)
end
set
end
private :_add_recursive_test_dependent_targets
# @param [Specification] test_spec
# the test spec to scope dependencies for
#
# @param [String] configuration
# the configuration to retrieve the test dependent targets for.
#
# @return [Array<PodTarget>] the canonical list of dependent targets this target has a dependency upon.
# This list includes the target itself as well as its recursive dependent and test dependent targets.
#
def dependent_targets_for_test_spec(test_spec, configuration: nil)
[self, *recursive_dependent_targets(:configuration => configuration), *recursive_test_dependent_targets(test_spec, :configuration => configuration)].uniq
end
# @param [Specification] app_spec
# the app spec to scope dependencies for
#
# @param [String] configuration
# the configuration to retrieve the app dependent targets for.
#
# @return [Array<PodTarget>] the recursive targets that this target has a
# app dependency upon.
#
def recursive_app_dependent_targets(app_spec, configuration: nil)
@recursive_app_dependent_targets ||= {}
@recursive_app_dependent_targets[app_spec] ||= begin
hash = Hash[config_variants.map do |config|
[config, _add_recursive_app_dependent_targets(app_spec, Set.new, :configuration => config).to_a.freeze]
end]
hash[nil] = hash.each_value.reduce(Set.new, &:|).to_a.freeze
hash
end
@recursive_app_dependent_targets[app_spec][configuration]
end
def _add_recursive_app_dependent_targets(app_spec, set, configuration: nil)
raise ArgumentError, 'Must give a app spec' unless app_spec
dependent_targets = configuration ? app_dependent_targets_by_spec_name_by_config[app_spec.name][configuration] : app_dependent_targets_by_spec_name[app_spec.name]
raise ArgumentError, "Unable to find deps for #{app_spec} for config #{configuration.inspect} #{app_dependent_targets_by_spec_name_by_config.inspect}" unless dependent_targets
dependent_targets.each do |target|
target._add_recursive_dependent_targets(set, :configuration => configuration) if set.add?(target)
end
set
end
private :_add_recursive_app_dependent_targets
# @param [Specification] app_spec
# the app spec to scope dependencies for
#
# @param [String] configuration
# the configuration to retrieve the app dependent targets for.
#
# @return [Array<PodTarget>] the canonical list of dependent targets this target has a dependency upon.
# This list includes the target itself as well as its recursive dependent and app dependent targets.
#
def dependent_targets_for_app_spec(app_spec, configuration: nil)
[self, *recursive_dependent_targets(:configuration => configuration), *recursive_app_dependent_targets(app_spec, :configuration => configuration)].uniq
end
# Checks if warnings should be inhibited for this pod.
#
# @return [Bool]
#
def inhibit_warnings?
return @inhibit_warnings if defined? @inhibit_warnings
whitelists = target_definitions.map do |target_definition|
target_definition.inhibits_warnings_for_pod?(root_spec.name)
end.uniq
if whitelists.empty?
@inhibit_warnings = false
false
elsif whitelists.count == 1
@inhibit_warnings = whitelists.first
whitelists.first
else
UI.warn "The pod `#{pod_name}` is linked to different targets " \
"(#{target_definitions.map { |td| "`#{td.name}`" }.to_sentence}), which contain different " \
'settings to inhibit warnings. CocoaPods does not currently ' \
'support different settings and will fall back to your preference ' \
'set in the root target definition.'
@inhibit_warnings = podfile.root_target_definitions.first.inhibits_warnings_for_pod?(root_spec.name)
end
end
# @param [String] dir
# The directory (which might be a variable) relative to which
# the returned path should be. This must be used if the
# $CONFIGURATION_BUILD_DIR is modified.
#
# @return [String] The absolute path to the configuration build dir
#
def configuration_build_dir(dir = BuildSettings::CONFIGURATION_BUILD_DIR_VARIABLE)
"#{dir}/#{label}"
end
# @param [String] dir
# @see #configuration_build_dir
#
# @return [String] The absolute path to the build product
#
def build_product_path(dir = BuildSettings::CONFIGURATION_BUILD_DIR_VARIABLE)
"#{configuration_build_dir(dir)}/#{product_name}"
end
# @return [String] The source path of the root for this target relative to `$(PODS_ROOT)`
#
def pod_target_srcroot
"${PODS_ROOT}/#{sandbox.pod_dir(pod_name).relative_path_from(sandbox.root)}"
end
# @return [String] The version associated with this target