class Pod::Target

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.

Constants

DEFAULT_BUILD_CONFIGURATIONS
DEFAULT_NAME
DEFAULT_VERSION

Attributes

application_extension_api_only[R]

@return [Boolean] whether the target can be linked to app extensions only.

archs[R]

@return [Array<String>] The value for the ARCHS build setting.

build_library_for_distribution[R]

@return [Boolean] whether the target must be compiled with Swift’s library evolution support, necessary for XCFrameworks.

build_settings[R]

@return [BuildSettings] the build settings for this target.

build_type[R]

@return [BuildType] the build type for this target.

platform[R]

@return [Platform] the platform of this target.

sandbox[R]

@return [Sandbox] The sandbox where the Pods should be installed.

user_build_configurations[R]

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

Public Class Methods

new(sandbox, build_type, user_build_configurations, archs, platform) click to toggle source

Initialize a new target

@param [Sandbox] sandbox @see sandbox @param [BuildType] build_type @see build_type @param [Hash{String=>Symbol}] user_build_configurations @see user_build_configurations @param [Array<String>] archs @see archs @param [Platform] platform @see platform

# 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
output_extension_for_resource(input_extension) click to toggle source

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

@param [String] input_extension

The input extension to map to.

@return [String] The output extension.

# 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) click to toggle source
# 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

Public Instance Methods

bridge_support_path() click to toggle source

@return [Pathname] the absolute path of the bridge support file.

# File lib/cocoapods/target.rb, line 285
def bridge_support_path
  support_files_dir + "#{label}.bridgesupport"
end
build_as_dynamic?() click to toggle source

@return [Boolean] whether the target is built dynamically

# File lib/cocoapods/target.rb, line 99
def build_as_dynamic?
  build_type.dynamic?
end
build_as_dynamic_framework?() click to toggle source

@return [Boolean] whether the target is built as a dynamic framework

# File lib/cocoapods/target.rb, line 105
def build_as_dynamic_framework?
  build_type.dynamic_framework?
end
build_as_dynamic_library?() click to toggle source

@return [Boolean] whether the target is built as a dynamic library

# File lib/cocoapods/target.rb, line 111
def build_as_dynamic_library?
  build_type.dynamic_library?
end
build_as_framework?() click to toggle source

@return [Boolean] whether the target is built as a framework

# File lib/cocoapods/target.rb, line 117
def build_as_framework?
  build_type.framework?
end
build_as_library?() click to toggle source

@return [Boolean] whether the target is built as a library

# File lib/cocoapods/target.rb, line 123
def build_as_library?
  build_type.library?
end
build_as_static?() click to toggle source

@return [Boolean] whether the target is built statically

# File lib/cocoapods/target.rb, line 129
def build_as_static?
  build_type.static?
end
build_as_static_framework?() click to toggle source

@return [Boolean] whether the target is built as a static framework

# File lib/cocoapods/target.rb, line 135
def build_as_static_framework?
  build_type.static_framework?
end
build_as_static_library?() click to toggle source

@return [Boolean] whether the target is built as a static library

# File lib/cocoapods/target.rb, line 141
def build_as_static_library?
  build_type.static_library?
end
dummy_source_path() click to toggle source

@return [Pathname] the path of the dummy source generated by CocoaPods

# File lib/cocoapods/target.rb, line 303
def dummy_source_path
  support_files_dir + "#{label}-dummy.m"
end
framework_name() click to toggle source

@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.
# File lib/cocoapods/target.rb, line 188
def framework_name
  "#{product_module_name}.framework"
end
info_plist_entries() click to toggle source

@return [Hash] additional entries for the generated Info.plist

# File lib/cocoapods/target.rb, line 297
def info_plist_entries
  {}
end
info_plist_path() click to toggle source

@return [Pathname] the absolute path of the Info.plist file.

# File lib/cocoapods/target.rb, line 291
def info_plist_path
  support_files_dir + "#{label}-Info.plist"
end
inspect() click to toggle source

@return [String] A string suitable for debugging.

# File lib/cocoapods/target.rb, line 210
def inspect
  "#<#{self.class} name=#{name}>"
end
label() click to toggle source

@return [String] the label for the target.

# File lib/cocoapods/target.rb, line 81
def label
  DEFAULT_NAME
end
mark_application_extension_api_only() click to toggle source

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

# File lib/cocoapods/target.rb, line 310
def mark_application_extension_api_only
  @application_extension_api_only = true
end
mark_build_library_for_distribution() click to toggle source

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

# File lib/cocoapods/target.rb, line 318
def mark_build_library_for_distribution
  @build_library_for_distribution = true
end
module_map_path() click to toggle source

@return [Pathname] the absolute path of the LLVM module map file that

defines the module structure for the compiler.
# File lib/cocoapods/target.rb, line 268
def module_map_path
  module_map_path_to_write
end
module_map_path_to_write() click to toggle source

@!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.
# File lib/cocoapods/target.rb, line 278
def module_map_path_to_write
  basename = "#{label}.modulemap"
  support_files_dir + basename
end
name() click to toggle source

@return [String] the name of the library.

# File lib/cocoapods/target.rb, line 73
def name
  label
end
Also aliased as: to_s
prepare_artifacts_script_path() click to toggle source

@return [Pathname] The absolute path of the prepare artifacts script.

@deprecated

@todo Remove in 2.0

# File lib/cocoapods/target.rb, line 328
def prepare_artifacts_script_path
  support_files_dir + "#{label}-artifacts.sh"
end
product_basename() click to toggle source

@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.
# File lib/cocoapods/target.rb, line 175
def product_basename
  if build_as_framework?
    product_module_name
  else
    label
  end
end
product_module_name() click to toggle source

@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.
# File lib/cocoapods/target.rb, line 157
def product_module_name
  c99ext_identifier(label)
end
product_name() click to toggle source

@return [String] the name of the product.

# File lib/cocoapods/target.rb, line 163
def product_name
  if build_as_framework?
    framework_name
  else
    static_library_name
  end
end
product_type() click to toggle source

@return [Symbol] either :framework or :static_library, depends on

#build_as_framework?.
# File lib/cocoapods/target.rb, line 204
def product_type
  build_as_framework? ? :framework : :static_library
end
requires_frameworks?() click to toggle source

@deprecated Prefer {build_as_framework?}.

@return [Boolean] whether the generated target needs to be implemented

as a framework
# File lib/cocoapods/target.rb, line 223
def requires_frameworks?
  build_as_framework?
end
static_framework?() click to toggle source

@deprecated Prefer {build_as_static_framework?}.

@return [Boolean] Whether the target should build a static framework.

# File lib/cocoapods/target.rb, line 149
def static_framework?
  build_as_static_framework?
end
static_library_name() click to toggle source

@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.
# File lib/cocoapods/target.rb, line 197
def static_library_name
  "lib#{label}.a"
end
support_files_dir() click to toggle source

@return [Pathname] the folder where to store the support files of this

library.
# File lib/cocoapods/target.rb, line 234
def support_files_dir
  sandbox.target_support_files_dir(name)
end
to_s()
Alias for: name
umbrella_header_path() click to toggle source

@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.
# File lib/cocoapods/target.rb, line 257
def umbrella_header_path
  module_map_path.parent + "#{label}-umbrella.h"
end
umbrella_header_path_to_write() click to toggle source
# 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?() click to toggle source

@return [Boolean] Whether the target uses Swift code

# File lib/cocoapods/target.rb, line 93
def uses_swift?
  false
end
version() click to toggle source

@return [String] The version associated with this target

# File lib/cocoapods/target.rb, line 87
def version
  DEFAULT_VERSION
end
xcconfig_path(variant = nil) click to toggle source

@param [String] variant

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

@return [Pathname] the absolute path of the xcconfig file.

# 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

Private Instance Methods

c99ext_identifier(name) click to toggle source

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]

# File lib/cocoapods/target.rb, line 370
def c99ext_identifier(name)
  name.gsub(/^([0-9])/, '_\1').gsub(/[^a-zA-Z0-9_]/, '_')
end
create_build_settings() click to toggle source
# File lib/cocoapods/target.rb, line 374
def create_build_settings
  BuildSettings.new(self)
end