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.



239
240
241
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 239

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.



248
249
250
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 248

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
# 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, target.product_basename)
  native_target.product_reference.name = 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.



108
109
110
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 108

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.



220
221
222
223
224
225
226
227
228
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 220

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



140
141
142
143
144
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 140

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.



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

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.



102
103
104
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 102

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.



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

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})


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

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.



75
76
77
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 75

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.



114
115
116
# File 'lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb', line 114

def support_files_temp_dir
  sandbox.target_support_files_dir('generated_files_tmp')
end