Class: Pod::Installer::Xcode::PodsProjectGenerator::TargetInstaller

Inherits:
Object
  • Object
show all
Includes:
TargetInstallerHelper
Defined in:
lib/cocoapods/installer/xcode/pods_project_generator/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

Private helpers. collapse

Instance Attribute Summary collapse

Installation steps collapse

Private helpers. collapse

Instance Method Summary collapse

Methods included from TargetInstallerHelper

create_info_plist_file_with_sandbox, #create_info_plist_file_with_sandbox, #create_prefix_header, create_prefix_header, update_changed_file, #update_changed_file

Constructor Details

#initialize(sandbox, project, target) ⇒ TargetInstaller

Initialize a new instance

Parameters:


35
36
37
38
39
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 35

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

Instance Attribute Details

#projectPod::Project (readonly)

Returns The project to install the target into.

Returns:

  • (Pod::Project)

    The project to install the target into.


22
23
24
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 22

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


17
18
19
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 17

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.


242
243
244
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 242

def support_files_group
  @support_files_group
end

#targetTarget (readonly)

Returns target The library whose target needs to be generated.

Returns:

  • (Target)

    target The library whose target needs to be generated.


27
28
29
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 27

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.


251
252
253
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 251

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

#add_targetPBXNativeTarget (private)

Note:

The PODS_HEADERS_SEARCH_PATHS overrides the xcconfig.

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

Returns:

  • (PBXNativeTarget)

    the native target that was added.


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 54

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

  native_target
end

#clean_support_files_temp_dirObject (private)

Remove temp file whose store .prefix/config/dummy file.


111
112
113
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 111

def clean_support_files_temp_dir
  support_files_temp_dir.rmtree if support_files_temp_dir.exist?
end

#create_dummy_source(native_target) ⇒ void (private)

This method returns an undefined value.

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

Parameters:

  • native_target (PBXNativeTarget)

    the native target to link the dummy source file into.


223
224
225
226
227
228
229
230
231
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 223

def create_dummy_source(native_target)
  path = target.dummy_source_path
  UI.message "- Generating dummy source at #{UI.path(path)}" do
    generator = Generator::DummySource.new(target.label)
    update_changed_file(generator, path)
    file_reference = add_file_to_support_group(path)
    native_target.source_build_phase.add_file_reference(file_reference)
  end
end

#create_info_plist_file(path, native_target, version, platform, bundle_package_type = :fmwk, additional_entries: {}) ⇒ void (private)

This method returns an undefined value.

Creates the Info.plist file which sets public framework attributes

Parameters:

  • path (Pathname)

    the path to save the generated Info.plist file.

  • native_target (PBXNativeTarget)

    the native target to link the generated Info.plist file into.

  • version (Version)

    the version to use for when generating this Info.plist file.

  • platform (Platform)

    the platform to use for when generating this Info.plist file.

  • bundle_package_type (Symbol) (defaults to: :fmwk)

    the CFBundlePackageType of the target this Info.plist file is for.

  • additional_entries (Hash) (defaults to: {})

    additional entries for the generated Info.plist


143
144
145
146
147
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 143

def create_info_plist_file(path, native_target, version, platform, bundle_package_type = :fmwk, additional_entries: {})
  create_info_plist_file_with_sandbox(@sandbox, path, native_target, version, platform, bundle_package_type,
                                      :additional_entries => additional_entries)
  add_file_to_support_group(path)
end

#create_module_map(native_target) ⇒ void (private)

This method returns an undefined value.

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

Parameters:

  • native_target (PBXNativeTarget)

    the native target to link the module map file into.


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 157

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

    linked_path = target.module_map_path
    if path != linked_path
      linked_path.dirname.mkpath
      source = path.relative_path_from(linked_path.dirname)
      FileUtils.ln_sf(source, linked_path)
    end

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

#create_support_files_dirObject (private)

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


105
106
107
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 105

def create_support_files_dir
  target.support_files_dir.mkpath
end

#create_umbrella_header(native_target) ⇒ void (private)

This method returns an undefined value.

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

Parameters:

  • native_target (PBXNativeTarget)

    the native target to link the umbrella header file into.


190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 190

def create_umbrella_header(native_target)
  path = target.umbrella_header_path_to_write
  UI.message "- Generating umbrella header at #{UI.path(path)}" do
    generator = Generator::UmbrellaHeader.new(target)
    yield generator if block_given?
    update_changed_file(generator, 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)
    build_file = native_target.headers_build_phase.add_file_reference(file_ref)

    linked_path = target.umbrella_header_path
    if path != linked_path
      linked_path.dirname.mkpath
      source = path.relative_path_from(linked_path.dirname)
      FileUtils.ln_sf(source, linked_path)
    end

    acl = target.build_as_framework? ? 'Public' : 'Project'
    build_file.settings ||= {}
    build_file.settings['ATTRIBUTES'] = [acl]
  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})

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 87

def custom_build_settings
  settings = {}

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

  if target.build_as_static_framework?
    settings['MACH_O_TYPE'] = 'staticlib'
  elsif target.build_as_static_library?
    settings.merge!('OTHER_LDFLAGS' => '', 'OTHER_LIBTOOLFLAGS' => '')
  end

  settings
end

#deployment_targetString (private)

Returns The deployment target.

Returns:

  • (String)

    The deployment target.


78
79
80
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 78

def deployment_target
  target.platform.deployment_target.to_s
end

#support_files_temp_dirString (private)

Returns The temp file path to store temporary files.

Returns:

  • (String)

    The temp file path to store temporary files.


117
118
119
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 117

def support_files_temp_dir
  sandbox.target_support_files_dir('generated_files_tmp')
end