Class: Pod::Installer::TargetInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/installer/target_installer.rb

Overview

Controller class responsible of creating and configuring the static library target in Pods project. It also creates the support file needed by the target.

Direct Known Subclasses

AggregateTargetInstaller, PodTargetInstaller

Installation steps collapse

Private helpers. collapse

Instance Attribute Summary collapse

Installation steps collapse

Private helpers. collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox, target) ⇒ TargetInstaller

Returns a new instance of TargetInstaller

Parameters:

  • project (Project)

    @see project

  • target (Target)

    @see target



20
21
22
23
# File 'lib/cocoapods/installer/target_installer.rb', line 20

def initialize(sandbox, target)
  @sandbox = sandbox
  @target = target
end

Instance Attribute Details

#native_targetPBXNativeTarget (readonly, private)

Note:

Generated by the #add_target step.

Returns the target generated by the installation process.

Returns:

  • (PBXNativeTarget)

    the target generated by the installation process.



177
178
179
# File 'lib/cocoapods/installer/target_installer.rb', line 177

def native_target
  @native_target
end

#sandboxSandbox (readonly)

Returns sandbox the sandbox where the support files should be generated.

Returns:

  • (Sandbox)

    sandbox the sandbox where the support files should be generated.



11
12
13
# File 'lib/cocoapods/installer/target_installer.rb', line 11

def sandbox
  @sandbox
end

#support_files_groupPBXGroup (readonly, private)

Returns the group where the file references to the support files should be stored.

Returns:

  • (PBXGroup)

    the group where the file references to the support files should be stored.



194
195
196
# File 'lib/cocoapods/installer/target_installer.rb', line 194

def support_files_group
  @support_files_group
end

#targetTarget (readonly)

Returns The library whose target needs to be generated.

Returns:

  • (Target)

    The library whose target needs to be generated.



15
16
17
# File 'lib/cocoapods/installer/target_installer.rb', line 15

def target
  @target
end

Instance Method Details

#add_file_to_support_group(path) ⇒ PBXFileReference (private)

Adds a reference to the given file in the support group of this target.

Parameters:

  • path (Pathname)

    The path of the file to which the reference should be added.

Returns:

  • (PBXFileReference)

    the file reference of the added file.



203
204
205
# File 'lib/cocoapods/installer/target_installer.rb', line 203

def add_file_to_support_group(path)
  support_files_group.new_file(path)
end

#add_targetvoid (private)

Note:

The PODS_HEADERS_SEARCH_PATHS overrides the xcconfig.

This method returns an undefined value.

Adds the target for the library to the Pods project with the appropriate build configurations.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cocoapods/installer/target_installer.rb', line 38

def add_target
  product_type = target.product_type
  name = target.label
  platform = target.platform.name
  language = target.uses_swift? ? :swift : :objc
  @native_target = project.new_target(product_type, name, platform, deployment_target, nil, language)

  product_name = target.product_name
  product = @native_target.product_reference
  product.name = product_name

  target.user_build_configurations.each do |bc_name, type|
    @native_target.add_build_configuration(bc_name, type)
  end

  @native_target.build_configurations.each do |configuration|
    configuration.build_settings.merge!(custom_build_settings)
  end

  target.native_target = @native_target
end

#create_dummy_sourcevoid (private)

This method returns an undefined value.

Generates a dummy source file for each target so libraries that contain only categories build.



164
165
166
167
168
169
170
# File 'lib/cocoapods/installer/target_installer.rb', line 164

def create_dummy_source
  path = target.dummy_source_path
  generator = Generator::DummySource.new(target.label)
  generator.save_as(path)
  file_reference = add_file_to_support_group(path)
  native_target.source_build_phase.add_file_reference(file_reference)
end

#create_info_plist_filevoid (private)

This method returns an undefined value.

Creates the Info.plist file which sets public framework attributes



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/cocoapods/installer/target_installer.rb', line 97

def create_info_plist_file
  path = target.info_plist_path
  UI.message "- Generating Info.plist file at #{UI.path(path)}" do
    generator = Generator::InfoPlistFile.new(target)
    generator.save_as(path)
    add_file_to_support_group(path)

    native_target.build_configurations.each do |c|
      relative_path = path.relative_path_from(sandbox.root)
      c.build_settings['INFOPLIST_FILE'] = relative_path.to_s
    end
  end
end

#create_module_mapvoid (private)

This method returns an undefined value.

Creates the module map file which ensures that the umbrella header is recognized with a customized path



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/cocoapods/installer/target_installer.rb', line 119

def create_module_map
  path = target.module_map_path
  UI.message "- Generating module map file at #{UI.path(path)}" do
    generator = Generator::ModuleMap.new(target)
    yield generator if block_given?
    generator.save_as(path)
    add_file_to_support_group(path)

    native_target.build_configurations.each do |c|
      relative_path = path.relative_path_from(sandbox.root)
      c.build_settings['MODULEMAP_FILE'] = relative_path.to_s
    end
  end
end

#create_support_files_dirObject (private)

Creates the directory where to store the support files of the target.



89
90
91
# File 'lib/cocoapods/installer/target_installer.rb', line 89

def create_support_files_dir
  target.support_files_dir.mkdir
end

#create_umbrella_headerObject (private)

Generates a header which ensures that all header files are exported in the module map



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/cocoapods/installer/target_installer.rb', line 140

def create_umbrella_header
  path = target.umbrella_header_path
  UI.message "- Generating umbrella header at #{UI.path(path)}" do
    generator = Generator::UmbrellaHeader.new(target)
    yield generator if block_given?
    generator.save_as(path)

    # Add the file to the support group and the native target,
    # so it will been added to the header build phase
    file_ref = add_file_to_support_group(path)
    native_target.add_file_references([file_ref])

    # Make the umbrella header public
    build_file = native_target.headers_build_phase.build_file(file_ref)
    build_file.settings ||= {}
    build_file.settings['ATTRIBUTES'] = ['Public']
  end
end

#custom_build_settingsHash{String => String} (private)

Returns the customized build settings which are overridden in the build settings of the user target.

Returns:

  • (Hash{String => String})


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cocoapods/installer/target_installer.rb', line 71

def custom_build_settings
  settings = {}

  unless target.archs.empty?
    settings['ARCHS'] = target.archs
  end

  if target.requires_frameworks?
    settings['PRODUCT_NAME'] = target.product_module_name
  else
    settings.merge!('OTHER_LDFLAGS' => '', 'OTHER_LIBTOOLFLAGS' => '')
  end

  settings
end

#deployment_targetString (private)

Returns The deployment target.

Returns:

  • (String)

    The deployment target.



62
63
64
# File 'lib/cocoapods/installer/target_installer.rb', line 62

def deployment_target
  target.platform.deployment_target.to_s
end

#projectProject (private)

Returns the Pods project of the sandbox.

Returns:

  • (Project)

    the Pods project of the sandbox.



187
188
189
# File 'lib/cocoapods/installer/target_installer.rb', line 187

def project
  sandbox.project
end