Class: Pod::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/target.rb,
lib/cocoapods/target/build_settings.rb

Overview

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.

Direct Known Subclasses

AggregateTarget, PodTarget

Defined Under Namespace

Classes: BuildSettings

Constant Summary collapse

DEFAULT_VERSION =
'1.0.0'.freeze
DEFAULT_NAME =
'Default'.freeze
DEFAULT_BUILD_CONFIGURATIONS =
{ 'Release' => :release, 'Debug' => :debug }.freeze

Instance Attribute Summary collapse

Framework support collapse

Support files collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox, build_type, user_build_configurations, archs, platform) ⇒ Target

Initialize a new target

Parameters:

  • sandbox (Sandbox)

    @see #sandbox

  • build_type (BuildType)

    @see #build_type

  • user_build_configurations (Hash{String=>Symbol})

    @see #user_build_configurations

  • archs (Array<String>)

    @see #archs

  • platform (Platform)

    @see #platform



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cocoapods/target.rb', line 59

def initialize(sandbox, build_type, user_build_configurations, archs, platform)
  @sandbox = sandbox
  @user_build_configurations = user_build_configurations
  @archs = archs
  @platform = platform
  @build_type = build_type

  @application_extension_api_only = false
  @build_library_for_distribution = false
  @build_settings = create_build_settings
end

Instance Attribute Details

#application_extension_api_onlyBoolean (readonly)

Returns whether the target can be linked to app extensions only.

Returns:

  • (Boolean)

    whether the target can be linked to app extensions only.



44
45
46
# File 'lib/cocoapods/target.rb', line 44

def application_extension_api_only
  @application_extension_api_only
end

#archsArray<String> (readonly)

Returns The value for the ARCHS build setting.

Returns:

  • (Array<String>)

    The value for the ARCHS build setting.



27
28
29
# File 'lib/cocoapods/target.rb', line 27

def archs
  @archs
end

#build_library_for_distributionBoolean (readonly)

evolution support, necessary for XCFrameworks.

Returns:

  • (Boolean)

    whether the target must be compiled with Swift’s library



49
50
51
# File 'lib/cocoapods/target.rb', line 49

def build_library_for_distribution
  @build_library_for_distribution
end

#build_settingsBuildSettings (readonly)

Returns the build settings for this target.

Returns:



35
36
37
# File 'lib/cocoapods/target.rb', line 35

def build_settings
  @build_settings
end

#platformPlatform (readonly)

Returns the platform of this target.

Returns:

  • (Platform)

    the platform of this target.



31
32
33
# File 'lib/cocoapods/target.rb', line 31

def platform
  @platform
end

#sandboxSandbox (readonly)

Returns The sandbox where the Pods should be installed.

Returns:

  • (Sandbox)

    The sandbox where the Pods should be installed.



17
18
19
# File 'lib/cocoapods/target.rb', line 17

def sandbox
  @sandbox
end

#user_build_configurationsHash{String=>Symbol} (readonly)

Returns 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`).

Returns:

  • (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`).



23
24
25
# File 'lib/cocoapods/target.rb', line 23

def user_build_configurations
  @user_build_configurations
end

Class Method Details

.output_extension_for_resource(input_extension) ⇒ String

Returns an extension in the target that corresponds to the resource’s input extension.

Parameters:

  • input_extension (String)

    The input extension to map to.

Returns:

  • (String)

    The output extension.



340
341
342
343
344
345
346
347
348
349
350
# File 'lib/cocoapods/target.rb', line 340

def self.output_extension_for_resource(input_extension)
  case input_extension
  when '.storyboard'        then '.storyboardc'
  when '.xib'               then '.nib'
  when '.xcdatamodel'       then '.mom'
  when '.xcdatamodeld'      then '.momd'
  when '.xcmappingmodel'    then '.cdm'
  when '.xcassets'          then '.car'
  else                      input_extension
  end
end

.resource_extension_compilable?(input_extension) ⇒ Boolean

Returns:

  • (Boolean)


352
353
354
# File 'lib/cocoapods/target.rb', line 352

def self.resource_extension_compilable?(input_extension)
  output_extension_for_resource(input_extension) != input_extension && input_extension != '.xcassets'
end

Instance Method Details

#bridge_support_pathPathname

Returns the absolute path of the bridge support file.

Returns:

  • (Pathname)

    the absolute path of the bridge support file.



285
286
287
# File 'lib/cocoapods/target.rb', line 285

def bridge_support_path
  support_files_dir + "#{label}.bridgesupport"
end

#build_as_dynamic?Boolean

Returns whether the target is built dynamically.

Returns:

  • (Boolean)

    whether the target is built dynamically



99
100
101
# File 'lib/cocoapods/target.rb', line 99

def build_as_dynamic?
  build_type.dynamic?
end

#build_as_dynamic_framework?Boolean

Returns whether the target is built as a dynamic framework.

Returns:

  • (Boolean)

    whether the target is built as a dynamic framework



105
106
107
# File 'lib/cocoapods/target.rb', line 105

def build_as_dynamic_framework?
  build_type.dynamic_framework?
end

#build_as_dynamic_library?Boolean

Returns whether the target is built as a dynamic library.

Returns:

  • (Boolean)

    whether the target is built as a dynamic library



111
112
113
# File 'lib/cocoapods/target.rb', line 111

def build_as_dynamic_library?
  build_type.dynamic_library?
end

#build_as_framework?Boolean

Returns whether the target is built as a framework.

Returns:

  • (Boolean)

    whether the target is built as a framework



117
118
119
# File 'lib/cocoapods/target.rb', line 117

def build_as_framework?
  build_type.framework?
end

#build_as_library?Boolean

Returns whether the target is built as a library.

Returns:

  • (Boolean)

    whether the target is built as a library



123
124
125
# File 'lib/cocoapods/target.rb', line 123

def build_as_library?
  build_type.library?
end

#build_as_static?Boolean

Returns whether the target is built statically.

Returns:

  • (Boolean)

    whether the target is built statically



129
130
131
# File 'lib/cocoapods/target.rb', line 129

def build_as_static?
  build_type.static?
end

#build_as_static_framework?Boolean

Returns whether the target is built as a static framework.

Returns:

  • (Boolean)

    whether the target is built as a static framework



135
136
137
# File 'lib/cocoapods/target.rb', line 135

def build_as_static_framework?
  build_type.static_framework?
end

#build_as_static_library?Boolean

Returns whether the target is built as a static library.

Returns:

  • (Boolean)

    whether the target is built as a static library



141
142
143
# File 'lib/cocoapods/target.rb', line 141

def build_as_static_library?
  build_type.static_library?
end

#dummy_source_pathPathname

Returns the path of the dummy source generated by CocoaPods.

Returns:

  • (Pathname)

    the path of the dummy source generated by CocoaPods



303
304
305
# File 'lib/cocoapods/target.rb', line 303

def dummy_source_path
  support_files_dir + "#{label}-dummy.m"
end

#framework_nameString

Note:

This may not depend on #requires_frameworks? indirectly as it is used for migration.

Returns the name of the framework, depends on #label.

Returns:

  • (String)

    the name of the framework, depends on #label.



188
189
190
# File 'lib/cocoapods/target.rb', line 188

def framework_name
  "#{product_module_name}.framework"
end

#info_plist_entriesHash

Returns additional entries for the generated Info.plist.

Returns:

  • (Hash)

    additional entries for the generated Info.plist



297
298
299
# File 'lib/cocoapods/target.rb', line 297

def info_plist_entries
  {}
end

#info_plist_pathPathname

Returns the absolute path of the Info.plist file.

Returns:

  • (Pathname)

    the absolute path of the Info.plist file.



291
292
293
# File 'lib/cocoapods/target.rb', line 291

def info_plist_path
  support_files_dir + "#{label}-Info.plist"
end

#inspectString

Returns A string suitable for debugging.

Returns:

  • (String)

    A string suitable for debugging.



210
211
212
# File 'lib/cocoapods/target.rb', line 210

def inspect
  "#<#{self.class} name=#{name}>"
end

#labelString

Returns the label for the target.

Returns:

  • (String)

    the label for the target.



81
82
83
# File 'lib/cocoapods/target.rb', line 81

def label
  DEFAULT_NAME
end

#mark_application_extension_api_onlyObject

Mark the target as extension-only. Translates to APPLICATION_EXTENSION_API_ONLY = YES in the build settings.



310
311
312
# File 'lib/cocoapods/target.rb', line 310

def mark_application_extension_api_only
  @application_extension_api_only = true
end

#mark_build_library_for_distributionObject

Compiles the target with Swift’s library evolution support, necessary to build XCFrameworks. Translates to BUILD_LIBRARY_FOR_DISTRIBUTION = YES in the build settings.



318
319
320
# File 'lib/cocoapods/target.rb', line 318

def mark_build_library_for_distribution
  @build_library_for_distribution = true
end

#module_map_pathPathname

Returns the absolute path of the LLVM module map file that defines the module structure for the compiler.

Returns:

  • (Pathname)

    the absolute path of the LLVM module map file that defines the module structure for the compiler.



268
269
270
# File 'lib/cocoapods/target.rb', line 268

def module_map_path
  module_map_path_to_write
end

#module_map_path_to_writePathname

Returns 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.

Returns:

  • (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.



278
279
280
281
# File 'lib/cocoapods/target.rb', line 278

def module_map_path_to_write
  basename = "#{label}.modulemap"
  support_files_dir + basename
end

#nameString Also known as: to_s

Returns the name of the library.

Returns:

  • (String)

    the name of the library.



73
74
75
# File 'lib/cocoapods/target.rb', line 73

def name
  label
end

#prepare_artifacts_script_pathPathname

Deprecated.
TODO:

Remove in 2.0

Returns The absolute path of the prepare artifacts script.

Returns:

  • (Pathname)

    The absolute path of the prepare artifacts script.



328
329
330
# File 'lib/cocoapods/target.rb', line 328

def prepare_artifacts_script_path
  support_files_dir + "#{label}-artifacts.sh"
end

#product_basenameString

Returns 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.

Returns:

  • (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.



175
176
177
178
179
180
181
# File 'lib/cocoapods/target.rb', line 175

def product_basename
  if build_as_framework?
    product_module_name
  else
    label
  end
end

#product_module_nameString

Returns 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.

Returns:

  • (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.



157
158
159
# File 'lib/cocoapods/target.rb', line 157

def product_module_name
  c99ext_identifier(label)
end

#product_nameString

Returns the name of the product.

Returns:

  • (String)

    the name of the product.



163
164
165
166
167
168
169
# File 'lib/cocoapods/target.rb', line 163

def product_name
  if build_as_framework?
    framework_name
  else
    static_library_name
  end
end

#product_typeSymbol

Returns either :framework or :static_library, depends on #build_as_framework?.

Returns:

  • (Symbol)

    either :framework or :static_library, depends on #build_as_framework?.



204
205
206
# File 'lib/cocoapods/target.rb', line 204

def product_type
  build_as_framework? ? :framework : :static_library
end

#requires_frameworks?Boolean

Deprecated.

Returns whether the generated target needs to be implemented as a framework.

Returns:

  • (Boolean)

    whether the generated target needs to be implemented as a framework



223
224
225
# File 'lib/cocoapods/target.rb', line 223

def requires_frameworks?
  build_as_framework?
end

#static_framework?Boolean

Deprecated.

Returns Whether the target should build a static framework.

Returns:

  • (Boolean)

    Whether the target should build a static framework.



149
150
151
# File 'lib/cocoapods/target.rb', line 149

def static_framework?
  build_as_static_framework?
end

#static_library_nameString

Note:

This may not depend on #requires_frameworks? indirectly as it is used for migration.

Returns the name of the library, depends on #label.

Returns:

  • (String)

    the name of the library, depends on #label.



197
198
199
# File 'lib/cocoapods/target.rb', line 197

def static_library_name
  "lib#{label}.a"
end

#support_files_dirPathname

Returns the folder where to store the support files of this library.

Returns:

  • (Pathname)

    the folder where to store the support files of this library.



234
235
236
# File 'lib/cocoapods/target.rb', line 234

def support_files_dir
  sandbox.target_support_files_dir(name)
end

#umbrella_header_pathPathname

Returns 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.

Returns:

  • (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.



257
258
259
# File 'lib/cocoapods/target.rb', line 257

def umbrella_header_path
  module_map_path.parent + "#{label}-umbrella.h"
end

#umbrella_header_path_to_writeObject



261
262
263
# File 'lib/cocoapods/target.rb', line 261

def umbrella_header_path_to_write
  module_map_path_to_write.parent + "#{label}-umbrella.h"
end

#uses_swift?Boolean

Returns Whether the target uses Swift code.

Returns:

  • (Boolean)

    Whether the target uses Swift code



93
94
95
# File 'lib/cocoapods/target.rb', line 93

def uses_swift?
  false
end

#versionString

Returns The version associated with this target.

Returns:

  • (String)

    The version associated with this target



87
88
89
# File 'lib/cocoapods/target.rb', line 87

def version
  DEFAULT_VERSION
end

#xcconfig_path(variant = nil) ⇒ Pathname

Returns the absolute path of the xcconfig file.

Parameters:

  • variant (String) (defaults to: nil)

    The variant of the xcconfig. Used to differentiate build configurations.

Returns:

  • (Pathname)

    the absolute path of the xcconfig file.



244
245
246
247
248
249
250
# File 'lib/cocoapods/target.rb', line 244

def xcconfig_path(variant = nil)
  if variant
    support_files_dir + "#{label}.#{variant.to_s.gsub(File::SEPARATOR, '-').downcase}.xcconfig"
  else
    support_files_dir + "#{label}.xcconfig"
  end
end