Class: Pod::Installer::Xcode::PodsProjectGenerator::AggregateTargetInstaller

Inherits:
TargetInstaller
  • Object
show all
Defined in:
lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb

Overview

Creates the targets which aggregate the Pods libraries in the Pods project and the relative support files.

Instance Attribute Summary collapse

Attributes inherited from TargetInstaller

#project, #sandbox, #support_files_group

Instance Method Summary collapse

Methods inherited from TargetInstaller

#add_file_to_support_group, #add_target, #clean_support_files_temp_dir, #create_dummy_source, #create_info_plist_file, #create_module_map, #create_support_files_dir, #create_umbrella_header, #deployment_target, #initialize, #support_files_temp_dir

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

This class inherits a constructor from Pod::Installer::Xcode::PodsProjectGenerator::TargetInstaller

Instance Attribute Details

#targetAggregateTarget (readonly)

Returns @see TargetInstaller#target.

Returns:



11
12
13
# File 'lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb', line 11

def target
  @target
end

Instance Method Details

#create_acknowledgementsvoid (private)

This method returns an undefined value.

Generates the acknowledgement files (markdown and plist) for the target.



176
177
178
179
180
181
182
183
184
185
# File 'lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb', line 176

def create_acknowledgements
  basepath = target.acknowledgements_basepath
  Generator::Acknowledgements.generators.each do |generator_class|
    path = generator_class.path_from_basepath(basepath)
    file_accessors = target.pod_targets.map(&:file_accessors).flatten
    generator = generator_class.new(file_accessors)
    update_changed_file(generator, path)
    add_file_to_support_group(path)
  end
end

#create_bridge_support_file(native_target) ⇒ void (private)

Note:

The bridge support metadata is added to the resources of the target because it is needed for environments interpreted at runtime.

This method returns an undefined value.

Generates the bridge support metadata if requested by the Podfile.

Parameters:

  • native_target (PBXNativeTarget)

    the native target to add the bridge support file into.



131
132
133
134
135
136
137
138
139
# File 'lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb', line 131

def create_bridge_support_file(native_target)
  if target.podfile.generate_bridge_support?
    path = target.bridge_support_path
    headers = native_target.headers_build_phase.files.map { |bf| sandbox.root + bf.file_ref.path }
    generator = Generator::BridgeSupport.new(headers)
    update_changed_file(generator, path)
    add_file_to_support_group(path)
  end
end

#create_copy_resources_scriptvoid (private)

Note:

The bridge support file needs to be created before the prefix header, otherwise it will not be added to the resources script.

This method returns an undefined value.

Creates a script that copies the resources to the bundle of the client target.



149
150
151
152
153
154
# File 'lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb', line 149

def create_copy_resources_script
  path = target.copy_resources_script_path
  generator = Generator::CopyResourcesScript.new(target.resource_paths_by_config, target.platform)
  update_changed_file(generator, path)
  add_file_to_support_group(path)
end

#create_embed_frameworks_scriptvoid (private)

Note:

We can't use Xcode default link libraries phase, because we need to ensure that we only copy the frameworks which are relevant for the current build configuration.

This method returns an undefined value.

Creates a script that embeds the frameworks to the bundle of the client target.



165
166
167
168
169
170
# File 'lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb', line 165

def create_embed_frameworks_script
  path = target.embed_frameworks_script_path
  generator = Generator::EmbedFrameworksScript.new(target.framework_paths_by_config, target.xcframeworks_by_config)
  update_changed_file(generator, path)
  add_file_to_support_group(path)
end

#create_support_files_groupvoid (private)

This method returns an undefined value.

Creates the group that holds the references to the support files generated by this installer.



94
95
96
97
98
99
# File 'lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb', line 94

def create_support_files_group
  parent = project.support_files_group
  name = target.name
  dir = target.support_files_dir
  @support_files_group = parent.new_group(name, dir)
end

#create_xcconfig_file(native_target) ⇒ void (private)

This method returns an undefined value.

Generates the contents of the xcconfig file and saves it to disk.

Parameters:

  • native_target (PBXNativeTarget)

    the native target to link the module map file into.



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb', line 108

def create_xcconfig_file(native_target)
  native_target.build_configurations.each do |configuration|
    next unless target.user_build_configurations.key?(configuration.name)
    path = target.xcconfig_path(configuration.name)
    build_settings = target.build_settings(configuration.name)
    update_changed_file(build_settings, path)
    target.xcconfigs[configuration.name] = build_settings.xcconfig
    xcconfig_file_ref = add_file_to_support_group(path)
    configuration.base_configuration_reference = xcconfig_file_ref
  end
end

#custom_build_settingsObject (private)

Ensure that vendored static frameworks and libraries are not linked twice to the aggregate target, which shares the xcconfig of the user target.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb', line 61

def custom_build_settings
  settings = {
    'CODE_SIGN_IDENTITY[sdk=appletvos*]' => '',
    'CODE_SIGN_IDENTITY[sdk=iphoneos*]'  => '',
    'CODE_SIGN_IDENTITY[sdk=watchos*]'   => '',
    'MACH_O_TYPE'                        => 'staticlib',
    'OTHER_LDFLAGS'                      => '',
    'OTHER_LIBTOOLFLAGS'                 => '',
    'PODS_ROOT'                          => '$(SRCROOT)',
    'PRODUCT_BUNDLE_IDENTIFIER'          => 'org.cocoapods.${PRODUCT_NAME:rfc1034identifier}',
    'SKIP_INSTALL'                       => 'YES',

    # Needed to ensure that static libraries won't try to embed the swift stdlib,
    # since there's no where to embed in for a static library.
    # Not necessary for dynamic frameworks either, since the aggregate targets are never shipped
    # on their own, and are always further embedded into an app target.
    'ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES' => 'NO',
  }
  super.merge(settings)
end

#embed_frameworks_script_required?Boolean (private)

Returns whether this target requires an Embed Frameworks script phase.

Returns:

  • (Boolean)

    whether this target requires an Embed Frameworks script phase



84
85
86
87
# File 'lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb', line 84

def embed_frameworks_script_required?
  includes_dynamic_xcframeworks = target.xcframeworks_by_config.values.flatten.map(&:build_type).any?(&:dynamic_framework?)
  (target.includes_frameworks? || includes_dynamic_xcframeworks) && !target.requires_host_target?
end

#install!TargetInstallationResult

Creates the target in the Pods project and the relative support files.

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb', line 17

def install!
  UI.message "- Installing target `#{target.name}` #{target.platform}" do
    native_target = add_target
    create_support_files_dir
    create_support_files_group
    create_xcconfig_file(native_target)
    if target.build_as_framework?
      create_info_plist_file(target.info_plist_path, native_target, target.version, target.platform)
      create_module_map(native_target)
      create_umbrella_header(native_target)
    elsif target.uses_swift?
      create_module_map(native_target)
      create_umbrella_header(native_target)
    end
    # Because embedded targets live in their host target, CocoaPods
    # copies all of the embedded target's pod_targets to its host
    # targets. Having this script for the embedded target would
    # cause an App Store rejection because frameworks cannot be
    # embedded in embedded targets.
    #
    create_embed_frameworks_script if embed_frameworks_script_required?
    create_bridge_support_file(native_target)
    create_copy_resources_script if target.includes_resources?
    create_acknowledgements
    create_dummy_source(native_target)
    clean_support_files_temp_dir
    TargetInstallationResult.new(target, native_target)
  end
end

#target_definitionTargetDefinition (private)

Returns the target definition of the library.

Returns:

  • (TargetDefinition)

    the target definition of the library.



53
54
55
# File 'lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb', line 53

def target_definition
  target.target_definition
end