forked from CocoaPods/CocoaPods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.rb
339 lines (287 loc) · 9.36 KB
/
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
require 'cocoapods/target/build_settings'
require 'cocoapods/target/build_type'
module Pod
# Model class which describes a Pods target.
#
# The Target class stores and provides the information necessary for
# working with a target in the Podfile and its dependent libraries.
# This class is used to represent both the targets and their libraries.
#
class Target
DEFAULT_VERSION = '1.0.0'.freeze
DEFAULT_NAME = 'Default'.freeze
DEFAULT_BUILD_CONFIGURATIONS = { 'Release' => :release, 'Debug' => :debug }.freeze
# @return [Sandbox] The sandbox where the Pods should be installed.
#
attr_reader :sandbox
# @return [Boolean] Whether the target needs to be implemented as a framework.
# Computed by analyzer.
#
attr_reader :host_requires_frameworks
alias_method :host_requires_frameworks?, :host_requires_frameworks
# @return [Hash{String=>Symbol}] A hash representing the user build
# configurations where each key corresponds to the name of a
# configuration and its value to its type (`:debug` or `:release`).
#
attr_reader :user_build_configurations
# @return [Array<String>] The value for the ARCHS build setting.
#
attr_reader :archs
# @return [Platform] the platform of this target.
#
attr_reader :platform
# @return [BuildSettings] the build settings for this target.
#
attr_reader :build_settings
# @return [Target::BuildType] the build type for this target.
#
attr_reader :build_type
private :build_type
# @return [Boolean] whether the target can be linked to app extensions only.
#
attr_reader :application_extension_api_only
# Initialize a new target
#
# @param [Sandbox] sandbox @see #sandbox
# @param [Boolean] host_requires_frameworks @see #host_requires_frameworks
# @param [Hash{String=>Symbol}] user_build_configurations @see #user_build_configurations
# @param [Array<String>] archs @see #archs
# @param [Platform] platform @see #platform
#
def initialize(sandbox, host_requires_frameworks, user_build_configurations, archs, platform,
build_type: Target::BuildType.infer_from_spec(nil, :host_requires_frameworks => host_requires_frameworks?))
@sandbox = sandbox
@host_requires_frameworks = host_requires_frameworks
@user_build_configurations = user_build_configurations
@archs = archs
@platform = platform
@build_type = build_type
@application_extension_api_only = false
@build_settings = create_build_settings
end
# @return [String] the name of the library.
#
def name
label
end
alias to_s name
# @return [String] the label for the target.
#
def label
DEFAULT_NAME
end
# @return [String] The version associated with this target
#
def version
DEFAULT_VERSION
end
# @return [Boolean] Whether the target uses Swift code
#
def uses_swift?
false
end
# @return [Boolean] whether the target is built dynamically
#
def build_as_dynamic?
build_type.dynamic?
end
# @return [Boolean] whether the target is built as a dynamic framework
#
def build_as_dynamic_framework?
build_type.dynamic_framework?
end
# @return [Boolean] whether the target is built as a dynamic library
#
def build_as_dynamic_library?
build_type.dynamic_library?
end
# @return [Boolean] whether the target is built as a framework
#
def build_as_framework?
build_type.framework?
end
# @return [Boolean] whether the target is built as a library
#
def build_as_library?
build_type.library?
end
# @return [Boolean] whether the target is built statically
#
def build_as_static?
build_type.static?
end
# @return [Boolean] whether the target is built as a static framework
#
def build_as_static_framework?
build_type.static_framework?
end
# @return [Boolean] whether the target is built as a static library
#
def build_as_static_library?
build_type.static_library?
end
# @deprecated Prefer {build_as_static_framework?}.
#
# @return [Boolean] Whether the target should build a static framework.
#
def static_framework?
build_as_static_framework?
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
c99ext_identifier(label)
end
# @return [String] the name of the product.
#
def product_name
if build_as_framework?
framework_name
else
static_library_name
end
end
# @return [String] the name of the product excluding the file extension or
# a product type specific prefix, depends on #requires_frameworks?
# and #product_module_name or #label.
#
def product_basename
if build_as_framework?
product_module_name
else
label
end
end
# @return [String] the name of the framework, depends on #label.
#
# @note This may not depend on #requires_frameworks? indirectly as it is
# used for migration.
#
def framework_name
"#{product_module_name}.framework"
end
# @return [String] the name of the library, depends on #label.
#
# @note This may not depend on #requires_frameworks? indirectly as it is
# used for migration.
#
def static_library_name
"lib#{label}.a"
end
# @return [Symbol] either :framework or :static_library, depends on
# #build_as_framework?.
#
def product_type
build_as_framework? ? :framework : :static_library
end
# @return [String] A string suitable for debugging.
#
def inspect
"<#{self.class} name=#{name} >"
end
#-------------------------------------------------------------------------#
# @!group Framework support
# @deprecated Prefer {build_as_framework?}.
#
# @return [Boolean] whether the generated target needs to be implemented
# as a framework
#
def requires_frameworks?
build_as_framework?
end
#-------------------------------------------------------------------------#
# @!group Support files
# @return [Pathname] the folder where to store the support files of this
# library.
#
def support_files_dir
sandbox.target_support_files_dir(name)
end
# @param [String] variant
# The variant of the xcconfig. Used to differentiate build
# configurations.
#
# @return [Pathname] the absolute path of the xcconfig file.
#
def xcconfig_path(variant = nil)
if variant
support_files_dir + "#{label}.#{variant.gsub(File::SEPARATOR, '-').downcase}.xcconfig"
else
support_files_dir + "#{label}.xcconfig"
end
end
# @return [Pathname] the absolute path of the header file which contains
# the exported foundation constants with framework version
# information and all headers, which should been exported in the
# module map.
#
def umbrella_header_path
module_map_path.parent + "#{label}-umbrella.h"
end
def umbrella_header_path_to_write
module_map_path_to_write.parent + "#{label}-umbrella.h"
end
# @return [Pathname] the absolute path of the LLVM module map file that
# defines the module structure for the compiler.
#
def module_map_path
module_map_path_to_write
end
# @!private
#
# @return [Pathname] the absolute path of the module map file that
# CocoaPods writes. This can be different from `module_map_path`
# if the module map gets symlinked.
#
def module_map_path_to_write
basename = "#{label}.modulemap"
support_files_dir + basename
end
# @return [Pathname] the absolute path of the bridge support file.
#
def bridge_support_path
support_files_dir + "#{label}.bridgesupport"
end
# @return [Pathname] the absolute path of the Info.plist file.
#
def info_plist_path
support_files_dir + "#{label}-Info.plist"
end
# @return [Hash] additional entries for the generated Info.plist
#
def info_plist_entries
{}
end
# @return [Pathname] the path of the dummy source generated by CocoaPods
#
def dummy_source_path
support_files_dir + "#{label}-dummy.m"
end
# mark the target as extension-only,
# translates to APPLICATION_EXTENSION_API_ONLY = YES in the build settings
#
def mark_application_extension_api_only
@application_extension_api_only = true
end
#-------------------------------------------------------------------------#
private
# Transforms the given string into a valid +identifier+ after C99ext
# standard, so that it can be used in source code where escaping of
# ambiguous characters is not applicable.
#
# @param [String] name
# any name, which may contain leading numbers, spaces or invalid
# characters.
#
# @return [String]
#
def c99ext_identifier(name)
name.gsub(/^([0-9])/, '_\1').gsub(/[^a-zA-Z0-9_]/, '_')
end
def create_build_settings
BuildSettings.new(self)
end
end
end