Class: Pod::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/target.rb,
lib/cocoapods/target/build_type.rb,
lib/cocoapods/target/build_settings.rb,
lib/cocoapods/target/framework_paths.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, BuildType, FrameworkPaths

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, host_requires_frameworks, user_build_configurations, archs, platform, build_type: Target::BuildType.infer_from_spec(nil, :host_requires_frameworks => host_requires_frameworks?)) ⇒ Target

Initialize a new target

Parameters:

  • sandbox (Sandbox)

    @see #sandbox

  • host_requires_frameworks (Boolean)

    @see #host_requires_frameworks

  • user_build_configurations (Hash{String=>Symbol})

    @see #user_build_configurations

  • archs (Array<String>)

    @see #archs

  • platform (Platform)

    @see #platform


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

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

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.


51
52
53
# File 'lib/cocoapods/target.rb', line 51

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.


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

def archs
  @archs
end

#build_settingsBuildSettings (readonly)

Returns the build settings for this target.

Returns:


42
43
44
# File 'lib/cocoapods/target.rb', line 42

def build_settings
  @build_settings
end

#host_requires_frameworksBoolean (readonly) Also known as: host_requires_frameworks?

Returns Whether the target needs to be implemented as a framework. Computed by analyzer.

Returns:

  • (Boolean)

    Whether the target needs to be implemented as a framework. Computed by analyzer.


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

def host_requires_frameworks
  @host_requires_frameworks
end

#platformPlatform (readonly)

Returns the platform of this target.

Returns:

  • (Platform)

    the platform of this target.


38
39
40
# File 'lib/cocoapods/target.rb', line 38

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.


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

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


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

def user_build_configurations
  @user_build_configurations
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.


288
289
290
# File 'lib/cocoapods/target.rb', line 288

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


102
103
104
# File 'lib/cocoapods/target.rb', line 102

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


108
109
110
# File 'lib/cocoapods/target.rb', line 108

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


114
115
116
# File 'lib/cocoapods/target.rb', line 114

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


120
121
122
# File 'lib/cocoapods/target.rb', line 120

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


126
127
128
# File 'lib/cocoapods/target.rb', line 126

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


132
133
134
# File 'lib/cocoapods/target.rb', line 132

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


138
139
140
# File 'lib/cocoapods/target.rb', line 138

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


144
145
146
# File 'lib/cocoapods/target.rb', line 144

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


306
307
308
# File 'lib/cocoapods/target.rb', line 306

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.


191
192
193
# File 'lib/cocoapods/target.rb', line 191

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


300
301
302
# File 'lib/cocoapods/target.rb', line 300

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.


294
295
296
# File 'lib/cocoapods/target.rb', line 294

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.


213
214
215
# File 'lib/cocoapods/target.rb', line 213

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

#labelString

Returns the label for the target.

Returns:

  • (String)

    the label for the target.


84
85
86
# File 'lib/cocoapods/target.rb', line 84

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


313
314
315
# File 'lib/cocoapods/target.rb', line 313

def mark_application_extension_api_only
  @application_extension_api_only = 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.


271
272
273
# File 'lib/cocoapods/target.rb', line 271

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.


281
282
283
284
# File 'lib/cocoapods/target.rb', line 281

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.


76
77
78
# File 'lib/cocoapods/target.rb', line 76

def name
  label
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.


178
179
180
181
182
183
184
# File 'lib/cocoapods/target.rb', line 178

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.


160
161
162
# File 'lib/cocoapods/target.rb', line 160

def product_module_name
  c99ext_identifier(label)
end

#product_nameString

Returns the name of the product.

Returns:

  • (String)

    the name of the product.


166
167
168
169
170
171
172
# File 'lib/cocoapods/target.rb', line 166

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


207
208
209
# File 'lib/cocoapods/target.rb', line 207

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


226
227
228
# File 'lib/cocoapods/target.rb', line 226

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.


152
153
154
# File 'lib/cocoapods/target.rb', line 152

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.


200
201
202
# File 'lib/cocoapods/target.rb', line 200

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.


237
238
239
# File 'lib/cocoapods/target.rb', line 237

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.


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

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

#umbrella_header_path_to_writeObject


264
265
266
# File 'lib/cocoapods/target.rb', line 264

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


96
97
98
# File 'lib/cocoapods/target.rb', line 96

def uses_swift?
  false
end

#versionString

Returns The version associated with this target

Returns:

  • (String)

    The version associated with this target


90
91
92
# File 'lib/cocoapods/target.rb', line 90

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.


247
248
249
250
251
252
253
# File 'lib/cocoapods/target.rb', line 247

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