-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
build_settings.rb
1388 lines (1158 loc) · 55.1 KB
/
build_settings.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
# frozen_string_literal: true
module Pod
class Target
# @since 1.5.0
class BuildSettings
#-------------------------------------------------------------------------#
# @!group Constants
# @return [Set<String>]
# The build settings that should be treated as arrays, rather than strings.
#
PLURAL_SETTINGS = %w(
ALTERNATE_PERMISSIONS_FILES
ARCHS
BUILD_VARIANTS
EXCLUDED_SOURCE_FILE_NAMES
FRAMEWORK_SEARCH_PATHS
GCC_PREPROCESSOR_DEFINITIONS
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS
HEADER_SEARCH_PATHS
INCLUDED_SOURCE_FILE_NAMES
INFOPLIST_PREPROCESSOR_DEFINITIONS
LD_RUNPATH_SEARCH_PATHS
LIBRARY_SEARCH_PATHS
LOCALIZED_STRING_MACRO_NAMES
OTHER_CFLAGS
OTHER_CPLUSPLUSFLAGS
OTHER_LDFLAGS
OTHER_SWIFT_FLAGS
REZ_SEARCH_PATHS
SECTORDER_FLAGS
SWIFT_ACTIVE_COMPILATION_CONDITIONS
SWIFT_INCLUDE_PATHS
SYSTEM_FRAMEWORK_SEARCH_PATHS
SYSTEM_HEADER_SEARCH_PATHS
USER_HEADER_SEARCH_PATHS
WARNING_CFLAGS
WARNING_LDFLAGS
).to_set.freeze
# @return [String]
# The variable for the configuration build directory used when building pod targets.
#
CONFIGURATION_BUILD_DIR_VARIABLE = '${PODS_CONFIGURATION_BUILD_DIR}'
# @return [String]
# The variable for the configuration intermediate frameworks directory used for building pod targets
# that contain vendored xcframeworks.
#
XCFRAMEWORKS_BUILD_DIR_VARIABLE = '${PODS_XCFRAMEWORKS_BUILD_DIR}'
#-------------------------------------------------------------------------#
# @!group DSL
# Creates a method that calculates a part of the build settings for the {#target}.
#
# @!visibility private
#
# @param [Symbol,String] method_name
# The name of the method to define
#
# @param [Boolean] build_setting
# Whether the method name should be added (upcased) to {.build_setting_names}
#
# @param [Boolean] memoized
# Whether the method should be memoized
#
# @param [Boolean] sorted
# Whether the return value should be sorted
#
# @param [Boolean] uniqued
# Whether the return value should be uniqued
#
# @param [Boolean] compacted
# Whether the return value should be compacted
#
# @param [Boolean] frozen
# Whether the return value should be frozen
#
# @param [Boolean, Symbol] from_search_paths_aggregate_targets
# If truthy, the method from {Aggregate} that should be used to concatenate build settings from
# {::Pod::AggregateTarget#search_paths_aggregate_target}
#
# @param [Symbol] from_pod_targets_to_link
# If truthy, the `_to_import` values from `BuildSettings#pod_targets_to_link` will be concatenated
#
# @param [Block] implementation
#
# @macro [attach] define_build_settings_method
# @!method $1
#
# The `$1` build setting for the {#target}.
#
# The return value from this method will be: `${1--1}`.
#
def self.define_build_settings_method(method_name, build_setting: false,
memoized: false, sorted: false, uniqued: false, compacted: false, frozen: true,
from_search_paths_aggregate_targets: false, from_pod_targets_to_link: false,
&implementation)
memoized_key = "#{self}##{method_name}"
(@build_settings_names ||= Set.new) << method_name.to_s.upcase if build_setting
raw_method_name = :"_raw_#{method_name}"
define_method(raw_method_name, &implementation)
private(raw_method_name)
dup_before_freeze = frozen && (from_pod_targets_to_link || from_search_paths_aggregate_targets || uniqued || sorted)
define_method(method_name) do
if memoized
retval = @__memoized.fetch(memoized_key, :not_found)
return retval if :not_found != retval
end
retval = send(raw_method_name)
if retval.nil?
@__memoized[memoized_key] = retval if memoized
return
end
retval = retval.dup if dup_before_freeze && retval.frozen?
retval.concat(pod_targets_to_link.flat_map { |pod_target| pod_target.build_settings_for_spec(pod_target.root_spec, :configuration => configuration_name).public_send("#{method_name}_to_import") }) if from_pod_targets_to_link
retval.concat(search_paths_aggregate_target_pod_target_build_settings.flat_map(&from_search_paths_aggregate_targets)) if from_search_paths_aggregate_targets
retval.compact! if compacted
retval.uniq! if uniqued
retval.sort! if sorted
retval.freeze if frozen
@__memoized[memoized_key] = retval if memoized
retval
end
end
private_class_method :define_build_settings_method
# @param [XCFramework] xcframework the xcframework slice that will be copied to the intermediates dir
#
# @return [String] the path to the directory containing the xcframework slice
#
def self.xcframework_intermediate_dir(xcframework)
"#{XCFRAMEWORKS_BUILD_DIR_VARIABLE}/#{xcframework.target_name}"
end
class << self
#-------------------------------------------------------------------------#
# @!group Public API
# @return [Set<String>] a set of all the build settings names that will
# be present in the #xcconfig
#
attr_reader :build_settings_names
end
#-------------------------------------------------------------------------#
# @!group Public API
# @return [Target]
# The target this build settings object is generating build settings for
#
attr_reader :target
# Initialize a new instance
#
# @param [Target] target
# see {#target}
#
def initialize(target)
@target = target
@__memoized = {}
end
def initialize_copy(other)
super
@__memoized = {}
end
# @return [Xcodeproj::Config]
define_build_settings_method :xcconfig, :memoized => true do
settings = add_inherited_to_plural(to_h)
Xcodeproj::Config.new(settings)
end
alias generate xcconfig
# Saves the generated xcconfig to the given path
#
# @return [Xcodeproj::Config]
#
# @see #xcconfig
#
# @param [String,Pathname] path
# The path the xcconfig will be saved to
#
def save_as(path)
xcconfig.save_as(path)
end
#-------------------------------------------------------------------------#
# @!group Build System
# @return [String]
define_build_settings_method :pods_build_dir, :build_setting => true do
'${BUILD_DIR}'
end
# @return [String]
define_build_settings_method :pods_configuration_build_dir, :build_setting => true do
'${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)'
end
define_build_settings_method :pods_xcframeworks_build_dir, :build_setting => true do
'$(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates'
end
# @return [String]
define_build_settings_method :use_recursive_script_inputs_in_script_phases, :build_setting => true do
'YES'
end
#-------------------------------------------------------------------------#
# @!group Code Signing
# @return [String]
define_build_settings_method :code_sign_identity, :build_setting => true do
return unless target.build_as_dynamic?
return unless target.platform.to_sym == :osx
''
end
#-------------------------------------------------------------------------#
# @!group Frameworks
# @return [Array<String>]
define_build_settings_method :frameworks do
[]
end
# @return [Array<String>]
define_build_settings_method :weak_frameworks do
[]
end
# @return [Array<String>]
define_build_settings_method :framework_search_paths, :build_setting => true, :memoized => true do
framework_search_paths_to_import_developer_frameworks(frameworks + weak_frameworks)
end
# @param [Array<String>] frameworks
# The list of framework names
#
# @return [Array<String>]
# the `FRAMEWORK_SEARCH_PATHS` needed to import developer frameworks
def framework_search_paths_to_import_developer_frameworks(frameworks)
if frameworks.include?('XCTest') || frameworks.include?('SenTestingKit')
%w[ $(PLATFORM_DIR)/Developer/Library/Frameworks ]
else
[]
end
end
#-------------------------------------------------------------------------#
# @!group Libraries
# @return [Array<String>]
define_build_settings_method :libraries do
[]
end
#-------------------------------------------------------------------------#
# @!group Clang
# @return [Array<String>]
define_build_settings_method :gcc_preprocessor_definitions, :build_setting => true do
%w( COCOAPODS=1 )
end
# @return [Array<String>]
define_build_settings_method :other_cflags, :build_setting => true, :memoized => true do
module_map_files.map { |f| "-fmodule-map-file=#{f}" }
end
# @return [Array<String>]
define_build_settings_method :module_map_files do
[]
end
#-------------------------------------------------------------------------#
# @!group Swift
# @return [Boolean]
# Whether `OTHER_SWIFT_FLAGS` should be generated when the target
# does not use swift.
#
def other_swift_flags_without_swift?
false
end
# @return [Array<String>]
define_build_settings_method :other_swift_flags, :build_setting => true, :memoized => true do
return unless target.uses_swift? || other_swift_flags_without_swift?
flags = %w(-D COCOAPODS)
flags.concat module_map_files.flat_map { |f| ['-Xcc', "-fmodule-map-file=#{f}"] }
flags
end
#-------------------------------------------------------------------------#
# @!group Linking
# @return [Boolean]
define_build_settings_method :requires_objc_linker_flag? do
false
end
# @return [Boolean]
define_build_settings_method :requires_fobjc_arc? do
false
end
# Xcode 12 turns on this warning by default which is problematic for CocoaPods-generated
# imports which use double-quoted paths.
# @return [Boolean]
define_build_settings_method :clang_warn_quoted_include_in_framework_header, :build_setting => true do
'NO'
end
# @return [Array<String>]
# the `LD_RUNPATH_SEARCH_PATHS` needed for dynamically linking the {#target}
#
# @param [Boolean] requires_host_target
#
# @param [Boolean] test_bundle
#
def _ld_runpath_search_paths(requires_host_target: false, test_bundle: false, uses_swift: false)
paths = []
if uses_swift
paths << '/usr/lib/swift'
paths << '$(PLATFORM_DIR)/Developer/Library/Frameworks' if test_bundle
end
if target.platform.symbolic_name == :osx
paths << "'@executable_path/../Frameworks'"
paths << if test_bundle
"'@loader_path/../Frameworks'"
else
"'@loader_path/Frameworks'"
end
paths << '${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}' if uses_swift
else
paths << "'@executable_path/Frameworks'"
paths << "'@loader_path/Frameworks'"
paths << "'@executable_path/../../Frameworks'" if requires_host_target
end
paths
end
private :_ld_runpath_search_paths
# @return [Array<String>]
define_build_settings_method :other_ldflags, :build_setting => true, :memoized => true do
ld_flags = []
ld_flags << '-ObjC' if requires_objc_linker_flag?
if requires_fobjc_arc?
ld_flags << '-fobjc-arc'
end
libraries.each { |l| ld_flags << %(-l"#{l}") }
frameworks.each { |f| ld_flags << '-framework' << %("#{f}") }
weak_frameworks.each { |f| ld_flags << '-weak_framework' << %("#{f}") }
ld_flags
end
#-------------------------------------------------------------------------#
# @!group Private Methods
private
# @return [Hash<String => String|Array<String>>]
def to_h
hash = {}
self.class.build_settings_names.sort.each do |setting|
hash[setting] = public_send(setting.downcase)
end
hash
end
# @return [Hash<String => String>]
def add_inherited_to_plural(hash)
Hash[hash.map do |key, value|
next [key, '$(inherited)'] if value.nil?
if PLURAL_SETTINGS.include?(key)
raise ArgumentError, "#{key} is a plural setting, cannot have #{value.inspect} as its value" unless value.is_a? Array
value = "$(inherited) #{quote_array(value)}"
else
raise ArgumentError, "#{key} is not a plural setting, cannot have #{value.inspect} as its value" unless value.is_a? String
end
[key, value]
end]
end
# @return [Array<String>]
#
# @param [Array<String>] array
#
def quote_array(array)
array.map do |element|
case element
when /\A([\w-]+?)=(.+)\z/
key = Regexp.last_match(1)
value = Regexp.last_match(2)
value = %("#{value}") if value =~ /[^\w\d]/
%(#{key}=#{value})
when /[\$\[\]\ ]/
%("#{element}")
else
element
end
end.join(' ')
end
# @param [Hash] xcconfig_values_by_consumer_by_key
#
# @param [#to_s] attribute
# The name of the attribute being merged
#
# @return [Hash<String, String>]
#
def merged_xcconfigs(xcconfig_values_by_consumer_by_key, attribute, overriding: {})
xcconfig_values_by_consumer_by_key.each_with_object(overriding.dup) do |(key, values_by_consumer), xcconfig|
uniq_values = values_by_consumer.values.uniq
values_are_bools = uniq_values.all? { |v| v =~ /\A(yes|no)\z/i }
if values_are_bools
# Boolean build settings
if uniq_values.count > 1
UI.warn "Can't merge #{attribute} for pod targets: " \
"#{values_by_consumer.keys.map(&:name)}. Boolean build " \
"setting #{key} has different values."
else
xcconfig[key] = uniq_values.first
end
elsif PLURAL_SETTINGS.include? key
# Plural build settings
if xcconfig.key?(key)
overridden = xcconfig[key]
uniq_values.prepend(overridden)
end
xcconfig[key] = uniq_values.uniq.join(' ')
elsif uniq_values.count > 1
# Singular build settings
UI.warn "Can't merge #{attribute} for pod targets: " \
"#{values_by_consumer.keys.map(&:name)}. Singular build " \
"setting #{key} has different values."
else
xcconfig[key] = uniq_values.first
end
end
end
# Merges the spec-defined xcconfig into the derived xcconfig,
# overriding any singular settings and merging plural settings.
#
# @param [Hash<String,String>] spec_xcconfig_hash the merged xcconfig defined in the spec.
#
# @param [Xcodeproj::Config] xcconfig the config to merge into.
#
# @return [Xcodeproj::Config] the merged config.
#
def merge_spec_xcconfig_into_xcconfig(spec_xcconfig_hash, xcconfig)
plural_configs, singlular_configs = spec_xcconfig_hash.partition { |k, _v| PLURAL_SETTINGS.include?(k) }.map { |a| Hash[a] }
xcconfig.attributes.merge!(singlular_configs)
xcconfig.merge!(plural_configs)
xcconfig
end
# Filters out pod targets whose `specs` are a subset of
# another target's.
#
# @param [Array<PodTarget>] pod_targets
#
# @return [Array<PodTarget>]
#
def select_maximal_pod_targets(pod_targets)
subset_targets = []
pod_targets.uniq.group_by(&:pod_name).each do |_pod_name, targets|
targets.combination(2) do |a, b|
if (a.specs - b.specs).empty?
subset_targets << a
elsif (b.specs - a.specs).empty?
subset_targets << b
end
end
end
pod_targets - subset_targets
end
# @param [String] target_name the name of the target this xcframework belongs to
#
# @param [Pathname,String] path the path to the xcframework bundle
#
# @return [Xcode::XCFramework] the xcframework at the given path
#
def load_xcframework(target_name, path)
Xcode::XCFramework.new(target_name, path)
end
# A subclass that generates build settings for a {PodTarget}
class PodTargetSettings < BuildSettings
#-------------------------------------------------------------------------#
# @!group Public API
# @see BuildSettings.build_settings_names
def self.build_settings_names
@build_settings_names | BuildSettings.build_settings_names
end
# @return [Boolean]
# whether settings are being generated for a test bundle
#
attr_reader :test_xcconfig
alias test_xcconfig? test_xcconfig
# @return [Boolean]
# whether settings are being generated for an application bundle
#
attr_reader :app_xcconfig
alias app_xcconfig? app_xcconfig
# @return [Boolean]
# whether settings are being generated for an library bundle
#
attr_reader :library_xcconfig
alias library_xcconfig? library_xcconfig
def non_library_xcconfig?
!library_xcconfig?
end
# @return [Specification]
# The non-library specification these build settings are for or `nil`.
#
attr_reader :non_library_spec
# Initializes a new instance
#
# @param [PodTarget] target
# see {#target}
#
# @param [Specification] non_library_spec
# see {#non_library_spec}
#
# @param [Symbol] configuration
# see {#configuration}
#
def initialize(target, non_library_spec = nil, configuration: nil)
super(target)
if @non_library_spec = non_library_spec
@test_xcconfig = non_library_spec.test_specification?
@app_xcconfig = non_library_spec.app_specification?
@xcconfig_spec_type = non_library_spec.spec_type
@library_xcconfig = false
else
@test_xcconfig = @app_xcconfig = false
@xcconfig_spec_type = :library
@library_xcconfig = true
end
(@configuration = configuration) || raise("No configuration for #{self}.")
end
# @return [Xcodeproj::Xconfig]
define_build_settings_method :xcconfig, :memoized => true do
xcconfig = super()
merge_spec_xcconfig_into_xcconfig(merged_pod_target_xcconfigs, xcconfig)
end
#-------------------------------------------------------------------------#
# @!group Paths
# @return [String]
define_build_settings_method :pods_root, :build_setting => true do
'${SRCROOT}'
end
# @return [String]
define_build_settings_method :pods_target_srcroot, :build_setting => true do
target.pod_target_srcroot
end
# @return [String]
define_build_settings_method :pods_development_language, :build_setting => true do
'${DEVELOPMENT_LANGUAGE}'
end
#-------------------------------------------------------------------------#
# @!group Frameworks
# @return [Array<String>]
define_build_settings_method :consumer_frameworks, :memoized => true do
spec_consumers.flat_map(&:frameworks)
end
# @return [Array<String>]
define_build_settings_method :frameworks, :memoized => true, :sorted => true, :uniqued => true do
return [] if target.build_as_static? && library_xcconfig?
frameworks = []
frameworks.concat consumer_frameworks
if library_xcconfig?
# We know that this library target is being built dynamically based
# on the guard above, so include any vendored static frameworks and vendored xcframeworks.
if target.should_build?
frameworks.concat vendored_static_frameworks.map { |l| File.basename(l, '.framework') }
frameworks.concat vendored_xcframeworks.
select { |xcf| xcf.build_type.static_framework? }.
map(&:name).
uniq
# Include direct dynamic dependencies to the linker flags. We used to add those in the 'Link Binary With Libraries'
# phase but we no longer do since we cannot differentiate between debug or release configurations within
# that phase.
frameworks.concat target.dependent_targets_by_config[@configuration].flat_map { |pt| pt.build_settings[@configuration].dynamic_frameworks_to_import }
else
# Also include any vendored dynamic frameworks of dependencies.
frameworks.concat dependent_targets.reject(&:should_build?).flat_map { |pt| pt.build_settings[@configuration].dynamic_frameworks_to_import }
end
else
frameworks.concat dependent_targets_to_link.flat_map { |pt| pt.build_settings[@configuration].frameworks_to_import }
end
frameworks
end
# @return [Array<String>]
define_build_settings_method :static_frameworks_to_import, :memoized => true do
static_frameworks_to_import = []
static_frameworks_to_import.concat vendored_static_frameworks.map { |f| File.basename(f, '.framework') } unless target.should_build? && target.build_as_dynamic?
unless target.should_build? && target.build_as_dynamic?
static_frameworks_to_import.concat vendored_xcframeworks.
select { |xcf| xcf.build_type.static_framework? }.
map(&:name).
uniq
end
static_frameworks_to_import << target.product_basename if target.should_build? && target.build_as_static_framework?
static_frameworks_to_import
end
# @return [Array<String>]
define_build_settings_method :dynamic_frameworks_to_import, :memoized => true do
dynamic_frameworks_to_import = vendored_dynamic_frameworks.map { |f| File.basename(f, '.framework') }
dynamic_frameworks_to_import.concat vendored_xcframeworks.
select { |xcf| xcf.build_type.dynamic_framework? }.
map(&:name).
uniq
dynamic_frameworks_to_import << target.product_basename if target.should_build? && target.build_as_dynamic_framework?
dynamic_frameworks_to_import.concat consumer_frameworks
dynamic_frameworks_to_import
end
# @return [Array<String>]
define_build_settings_method :weak_frameworks, :memoized => true do
return [] if target.build_as_static? && library_xcconfig?
weak_frameworks = spec_consumers.flat_map(&:weak_frameworks)
weak_frameworks.concat dependent_targets.flat_map { |pt| pt.build_settings[@configuration].weak_frameworks_to_import }
weak_frameworks
end
# @return [Array<String>]
define_build_settings_method :frameworks_to_import, :memoized => true, :sorted => true, :uniqued => true do
static_frameworks_to_import + dynamic_frameworks_to_import
end
# @return [Array<String>]
define_build_settings_method :weak_frameworks_to_import, :memoized => true, :sorted => true, :uniqued => true do
spec_consumers.flat_map(&:weak_frameworks)
end
# @return [Array<String>]
define_build_settings_method :framework_search_paths, :build_setting => true, :memoized => true, :sorted => true, :uniqued => true do
paths = super().dup
paths.concat dependent_targets.flat_map { |pt| pt.build_settings[@configuration].framework_search_paths_to_import }
paths.concat framework_search_paths_to_import
paths.delete(target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE)) if library_xcconfig?
paths
end
# @return [String]
define_build_settings_method :framework_header_search_path, :memoized => true do
return unless target.build_as_framework?
"#{target.build_product_path}/Headers"
end
# @return [Array<String>]
define_build_settings_method :vendored_framework_search_paths, :memoized => true do
search_paths = []
search_paths.concat file_accessors.
flat_map(&:vendored_frameworks).
map { |f| File.join '${PODS_ROOT}', f.dirname.relative_path_from(target.sandbox.root) }
xcframework_intermediates = vendored_xcframeworks.
select { |xcf| xcf.build_type.framework? }.
map { |xcf| BuildSettings.xcframework_intermediate_dir(xcf) }.
uniq
search_paths.concat xcframework_intermediates
search_paths
end
# @return [Array<String>]
define_build_settings_method :framework_search_paths_to_import, :memoized => true do
paths = framework_search_paths_to_import_developer_frameworks(consumer_frameworks)
paths.concat vendored_framework_search_paths
return paths unless target.build_as_framework? && target.should_build?
paths + [target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE)]
end
# @return [Array<String>]
define_build_settings_method :vendored_static_frameworks, :memoized => true do
file_accessors.flat_map(&:vendored_static_frameworks)
end
# @return [Array<String>]
define_build_settings_method :vendored_dynamic_frameworks, :memoized => true do
file_accessors.flat_map(&:vendored_dynamic_frameworks)
end
# @return [Array<Xcode::XCFramework>]
define_build_settings_method :vendored_xcframeworks, :memoized => true do
file_accessors.flat_map do |file_accessor|
file_accessor.vendored_xcframeworks.map { |path| load_xcframework(file_accessor.spec.name, path) }
end
end
# @return [Array<String>]
define_build_settings_method :system_framework_search_paths, :build_setting => true, :memoized => true, :sorted => true, :uniqued => true do
return ['$(PLATFORM_DIR)/Developer/Library/Frameworks'] if should_apply_xctunwrap_fix?
[]
end
#-------------------------------------------------------------------------#
# @!group Libraries
# Converts array of library path references to just the names to use
# link each library, e.g. from '/path/to/libSomething.a' to 'Something'
#
# @param [Array<String>] libraries
#
# @return [Array<String>]
#
def linker_names_from_libraries(libraries)
libraries.map { |l| File.basename(l, File.extname(l)).sub(/\Alib/, '') }
end
# @return [Array<String>]
define_build_settings_method :libraries, :memoized => true, :sorted => true, :uniqued => true do
return [] if library_xcconfig? && target.build_as_static?
libraries = []
if non_library_xcconfig? || target.build_as_dynamic?
libraries.concat linker_names_from_libraries(vendored_static_libraries)
libraries.concat libraries_to_import
xcframework_libraries = vendored_xcframeworks.
select { |xcf| xcf.build_type.static_library? }.
flat_map { |xcf| linker_names_from_libraries([xcf.slices.first.binary_path]) }.
uniq
libraries.concat xcframework_libraries
end
if non_library_xcconfig?
libraries.concat dependent_targets.flat_map { |pt| pt.build_settings[@configuration].dynamic_libraries_to_import }
libraries.concat dependent_targets_to_link.flat_map { |pt| pt.build_settings[@configuration].static_libraries_to_import }
end
libraries
end
# @return [Array<String>]
define_build_settings_method :static_libraries_to_import, :memoized => true do
static_libraries_to_import = []
unless target.should_build? && target.build_as_dynamic?
static_libraries_to_import.concat linker_names_from_libraries(vendored_static_libraries)
xcframework_libraries = vendored_xcframeworks.
select { |xcf| xcf.build_type.static_library? }.
flat_map { |xcf| linker_names_from_libraries([xcf.slices.first.binary_path]) }.
uniq
static_libraries_to_import.concat linker_names_from_libraries(xcframework_libraries)
end
static_libraries_to_import << target.product_basename if target.should_build? && target.build_as_static_library?
static_libraries_to_import
end
# @return [Array<String>]
define_build_settings_method :dynamic_libraries_to_import, :memoized => true do
dynamic_libraries_to_import = linker_names_from_libraries(vendored_dynamic_libraries)
dynamic_libraries_to_import.concat spec_consumers.flat_map(&:libraries)
dynamic_libraries_to_import << target.product_basename if target.should_build? && target.build_as_dynamic_library?
dynamic_libraries_to_import
end
# @return [Array<String>]
define_build_settings_method :libraries_to_import, :memoized => true, :sorted => true, :uniqued => true do
static_libraries_to_import + dynamic_libraries_to_import
end
# @return [Array<String>]
define_build_settings_method :library_search_paths, :build_setting => true, :memoized => true, :sorted => true, :uniqued => true do
library_search_paths = should_apply_xctunwrap_fix? ? ['$(PLATFORM_DIR)/Developer/usr/lib'] : []
return library_search_paths if library_xcconfig? && target.build_as_static?
library_search_paths.concat library_search_paths_to_import.dup
library_search_paths.concat dependent_targets.flat_map { |pt| pt.build_settings[@configuration].vendored_dynamic_library_search_paths }
if library_xcconfig?
library_search_paths.delete(target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE))
else
library_search_paths.concat(dependent_targets.flat_map { |pt| pt.build_settings[@configuration].library_search_paths_to_import })
end
library_search_paths
end
# @return [Array<String>]
define_build_settings_method :vendored_static_libraries, :memoized => true do
file_accessors.flat_map(&:vendored_static_libraries)
end
# @return [Array<String>]
define_build_settings_method :vendored_dynamic_libraries, :memoized => true do
file_accessors.flat_map(&:vendored_dynamic_libraries)
end
# @return [Array<String>]
define_build_settings_method :vendored_static_library_search_paths, :memoized => true do
paths = vendored_static_libraries.map { |f| File.join '${PODS_ROOT}', f.dirname.relative_path_from(target.sandbox.root) }
paths.concat vendored_xcframeworks.
select { |xcf| xcf.build_type.static_library? }.
map { |xcf| BuildSettings.xcframework_intermediate_dir(xcf) }
paths
end
# @return [Array<String>]
define_build_settings_method :vendored_dynamic_library_search_paths, :memoized => true do
paths = vendored_dynamic_libraries.map { |f| File.join '${PODS_ROOT}', f.dirname.relative_path_from(target.sandbox.root) }
paths.concat vendored_xcframeworks.
select { |xcf| xcf.build_type.dynamic_library? }.
map { |xcf| BuildSettings.xcframework_intermediate_dir(xcf) }
paths
end
# @return [Array<String>]
define_build_settings_method :library_search_paths_to_import, :memoized => true do
search_paths = vendored_static_library_search_paths + vendored_dynamic_library_search_paths
if target.uses_swift? || other_swift_flags_without_swift?
search_paths << '/usr/lib/swift'
search_paths << '${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}'
search_paths << '$(PLATFORM_DIR)/Developer/Library/Frameworks' if test_xcconfig?
end
return search_paths if target.build_as_framework? || !target.should_build?
search_paths << target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE)
end
#-------------------------------------------------------------------------#
# @!group Clang
# @return [Array<String>]
define_build_settings_method :module_map_files, :memoized => true do
dependent_targets.map { |pt| pt.build_settings[@configuration].module_map_file_to_import }.compact.sort
end
# @return [Array<String>]
define_build_settings_method :module_map_file_to_import, :memoized => true do
return unless target.should_build?
return if target.build_as_framework? # framework module maps are automatically discovered
return unless target.defines_module?
if target.uses_swift?
# for swift, we have a custom build phase that copies in the module map, appending the .Swift module
"${PODS_CONFIGURATION_BUILD_DIR}/#{target.label}/#{target.product_module_name}.modulemap"
else
"${PODS_ROOT}/#{target.module_map_path.relative_path_from(target.sandbox.root)}"
end
end
# @return [Array<String>]
define_build_settings_method :header_search_paths, :build_setting => true, :memoized => true, :sorted => true do
paths = target.header_search_paths(:include_dependent_targets_for_test_spec => test_xcconfig? && non_library_spec, :include_dependent_targets_for_app_spec => app_xcconfig? && non_library_spec, :configuration => @configuration)
dependent_vendored_xcframeworks = []
dependent_vendored_xcframeworks.concat vendored_xcframeworks
dependent_vendored_xcframeworks.concat dependent_targets.flat_map { |pt| pt.build_settings[@configuration].vendored_xcframeworks }
paths.concat dependent_vendored_xcframeworks.
select { |xcf| xcf.build_type.static_library? }.
map { |xcf| "#{BuildSettings.xcframework_intermediate_dir(xcf)}/Headers" }.
compact
paths
end
# @return [Array<String>]
define_build_settings_method :public_header_search_paths, :memoized => true, :sorted => true do
target.header_search_paths(:include_dependent_targets_for_test_spec => test_xcconfig? && non_library_spec, :include_dependent_targets_for_app_spec => app_xcconfig? && non_library_spec, :include_private_headers => false, :configuration => @configuration)
end
#-------------------------------------------------------------------------#
# @!group Swift
# @see BuildSettings#other_swift_flags_without_swift?
def other_swift_flags_without_swift?
return false if library_xcconfig?
target.uses_swift_for_spec?(non_library_spec)
end
# @return [Array<String>]
define_build_settings_method :other_swift_flags, :build_setting => true, :memoized => true do
return unless target.uses_swift? || other_swift_flags_without_swift?
flags = super()
flags << '-suppress-warnings' if target.inhibit_warnings? && library_xcconfig?
if !target.build_as_framework? && target.defines_module? && library_xcconfig?
flags.concat %w( -import-underlying-module -Xcc -fmodule-map-file=${SRCROOT}/${MODULEMAP_FILE} )
end
flags
end
# @return [Array<String>]
define_build_settings_method :swift_include_paths, :build_setting => true, :memoized => true, :sorted => true, :uniqued => true do
paths = dependent_targets.flat_map { |pt| pt.build_settings[@configuration].swift_include_paths_to_import }
paths.concat swift_include_paths_to_import if non_library_xcconfig?
paths.concat ['$(PLATFORM_DIR)/Developer/usr/lib'] if should_apply_xctunwrap_fix?
paths
end
# @return [Array<String>]
define_build_settings_method :swift_include_paths_to_import, :memoized => true do
return [] unless target.uses_swift? && !target.build_as_framework?
[target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE)]
end
#-------------------------------------------------------------------------#
# @!group Linking
# @return [Boolean] whether the `-ObjC` linker flag is required.
#
# @note this is only true when generating build settings for a test bundle
#
def requires_objc_linker_flag?
test_xcconfig? || app_xcconfig?
end
# @return [Boolean] whether the `-fobjc-arc` linker flag is required.
#
define_build_settings_method :requires_fobjc_arc?, :memoized => true do
target.podfile.set_arc_compatibility_flag? &&
file_accessors.any? { |fa| fa.spec_consumer.requires_arc? }
end
# @return [Array<String>]
define_build_settings_method :ld_runpath_search_paths, :build_setting => true, :memoized => true do
return if library_xcconfig?
_ld_runpath_search_paths(:test_bundle => test_xcconfig?,
:uses_swift => other_swift_flags_without_swift? || dependent_targets.any?(&:uses_swift?))
end
#-------------------------------------------------------------------------#
# @!group Packaging
# @return [String]
define_build_settings_method :skip_install, :build_setting => true do
'YES'
end
# @return [String]
define_build_settings_method :product_bundle_identifier, :build_setting => true do
'org.cocoapods.${PRODUCT_NAME:rfc1034identifier}'
end
# @return [String]
define_build_settings_method :configuration_build_dir, :build_setting => true, :memoized => true do
return if non_library_xcconfig?
target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE)