Class: Pod::Installer::Xcode::PodTargetDependencyInstaller

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

Overview

Wires up the dependencies between targets from the target installation results

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox, pod_target_installation_results, metadata_cache) ⇒ PodTargetDependencyInstaller

Initialize a new instance.

Parameters:

  • sandbox (Sandbox)

    @see #sandbox

  • pod_target_installation_results (TargetInstallationResults)

    @see #pod_target_installation_results

  • metadata_cache (ProjectMetadataCache)

    @see #metadata_cache


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

def initialize(sandbox, pod_target_installation_results, )
  @sandbox = sandbox
  @pod_target_installation_results = pod_target_installation_results
  @metadata_cache = 
end

Instance Attribute Details

#metadata_cacheProjectMetadataCache (readonly)

Returns The metadata cache for targets.

Returns:

  • (ProjectMetadataCache)

    The metadata cache for targets.


19
20
21
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_dependency_installer.rb', line 19

def 
  @metadata_cache
end

#pod_target_installation_resultsTargetInstallationResults (readonly)

Returns The target installation results for pod targets.

Returns:

  • (TargetInstallationResults)

    The target installation results for pod targets.


15
16
17
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_dependency_installer.rb', line 15

def pod_target_installation_results
  @pod_target_installation_results
end

#sandboxSandbox (readonly)

Returns The sandbox used for this installation.

Returns:

  • (Sandbox)

    The sandbox used for this installation.


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

def sandbox
  @sandbox
end

Instance Method Details

#add_framework_file_reference_to_native_target(native_target, pod_target, dependent_target, frameworks_group) ⇒ Object (private)


198
199
200
201
202
203
204
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_dependency_installer.rb', line 198

def add_framework_file_reference_to_native_target(native_target, pod_target, dependent_target, frameworks_group)
  if pod_target.should_build? && pod_target.build_as_dynamic? && dependent_target.should_build?
    product_ref = frameworks_group.files.find { |f| f.path == dependent_target.product_name } ||
        frameworks_group.new_product_ref_for_target(dependent_target.product_basename, dependent_target.product_type)
    native_target.frameworks_build_phase.add_file_reference(product_ref, true)
  end
end

#install!Object


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_dependency_installer.rb', line 33

def install!
  # Wire up pod targets
  pod_target_installation_results.values.each do |pod_target_installation_result|
    pod_target = pod_target_installation_result.target
    native_target = pod_target_installation_result.native_target
    project = native_target.project
    frameworks_group = project.frameworks_group

    # First, wire up all resource bundles.
    wire_resource_bundle_targets(pod_target_installation_result.resource_bundle_targets,
                                 native_target, pod_target)
    # Wire up all dependencies to this pod target, if any.
    wire_target_dependencies(pod_target, native_target, project, pod_target_installation_results,
                             , frameworks_group)

    # Wire up test native targets.
    unless pod_target_installation_result.test_native_targets.empty?
      wire_test_native_targets(pod_target, pod_target_installation_result, pod_target_installation_results,
                               project, frameworks_group, )
    end

    # Wire up app native targets.
    unless pod_target_installation_result.app_native_targets.empty?
      wire_app_native_targets(pod_target, pod_target_installation_result, pod_target_installation_results,
                              project, frameworks_group, )
    end
  end
end

#wire_app_native_targets(pod_target, installation_result, pod_target_installation_results, project, frameworks_group, metadata_cache) ⇒ Object (private)


165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_dependency_installer.rb', line 165

def wire_app_native_targets(pod_target, installation_result, pod_target_installation_results, project, frameworks_group, )
  installation_result.app_specs_by_native_target.each do |app_native_target, app_spec|
    resource_bundle_native_targets = installation_result.app_resource_bundle_targets[app_spec.name] || []
    resource_bundle_native_targets.each do |app_resource_bundle_target|
      app_native_target.add_dependency(app_resource_bundle_target)
    end

    app_dependent_targets = pod_target.app_dependent_targets_by_spec_name.fetch(app_spec.name, []).unshift(pod_target).uniq
    app_dependent_targets.each do |app_dependent_target|
      is_local = sandbox.local?(app_dependent_target.pod_name)
      if dependency_installation_result = pod_target_installation_results[app_dependent_target.name]
        resource_bundle_native_targets = dependency_installation_result.app_resource_bundle_targets[app_spec.name]
        unless resource_bundle_native_targets.nil?
          resource_bundle_native_targets.each do |app_resource_bundle_target|
            app_native_target.add_dependency(app_resource_bundle_target)
          end
        end
        dependency_project = dependency_installation_result.native_target.project
        if dependency_project != project
          project.add_pod_subproject(dependency_project, is_local)
        end
        app_native_target.add_dependency(dependency_installation_result.native_target)
        add_framework_file_reference_to_native_target(app_native_target, pod_target, app_dependent_target, frameworks_group)
      else
        # Hit the cache
        cached_dependency = .[app_dependent_target.label]
        project.add_cached_pod_subproject(sandbox, cached_dependency, is_local)
        Project.add_cached_dependency(sandbox, app_native_target, cached_dependency)
      end
    end
  end
end

#wire_resource_bundle_targets(resource_bundle_targets, native_target, pod_target) ⇒ Object (private)


64
65
66
67
68
69
70
71
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_dependency_installer.rb', line 64

def wire_resource_bundle_targets(resource_bundle_targets, native_target, pod_target)
  resource_bundle_targets.each do |resource_bundle_target|
    native_target.add_dependency(resource_bundle_target)
    if pod_target.build_as_dynamic_framework? && pod_target.should_build?
      native_target.add_resources([resource_bundle_target.product_reference])
    end
  end
end

#wire_target_dependencies(pod_target, native_target, project, pod_target_installation_results, metadata_cache, frameworks_group) ⇒ Object (private)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_dependency_installer.rb', line 73

def wire_target_dependencies(pod_target, native_target, project,
                             pod_target_installation_results, , frameworks_group)
  dependent_targets = pod_target.dependent_targets
  dependent_targets.each do |dependent_target|
    is_local = sandbox.local?(dependent_target.pod_name)
    if installation_result = pod_target_installation_results[dependent_target.name]
      dependent_project = installation_result.native_target.project
      if dependent_project != project
        project.add_pod_subproject(dependent_project, is_local)
      end
      native_target.add_dependency(installation_result.native_target)
      add_framework_file_reference_to_native_target(native_target, pod_target, dependent_target, frameworks_group)
    else
      # Hit the cache
      cached_dependency = .[dependent_target.label]
      project.add_cached_pod_subproject(sandbox, cached_dependency, is_local)
      Project.add_cached_dependency(sandbox, native_target, cached_dependency)
    end
  end
end

#wire_test_native_target_app_host(test_native_target, pod_target, pod_target_installation_results, project, metadata_cache, app_host_pod_target_label, app_host_target_label) ⇒ Object (private)


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_dependency_installer.rb', line 126

def wire_test_native_target_app_host(test_native_target, pod_target, pod_target_installation_results, project, , app_host_pod_target_label, app_host_target_label)
  if dependency_installation_result = pod_target_installation_results[app_host_pod_target_label]
    unless app_native_target = dependency_installation_result.app_host_target_labelled(app_host_target_label)
      raise Informative, "Did not find target with label #{app_host_target_label} in the set of targets installed for #{app_host_pod_target_label}."
    end

    dependent_test_project = app_native_target.project
    if dependent_test_project != project
      project.add_subproject_reference(dependent_test_project, project.dependencies_group)
    end

    app_host_target_names = app_native_target.resolved_build_setting('PRODUCT_NAME', true)
    test_native_target.build_configurations.each do |configuration|
      app_host_target_name = app_host_target_names[configuration.name] || target.name
      case test_native_target.symbol_type
      when :unit_test_bundle
        test_host = "$(BUILT_PRODUCTS_DIR)/#{app_host_target_name}.app/"
        test_host << 'Contents/MacOS/' if pod_target.platform == :osx
        test_host << app_host_target_name.to_s
        configuration.build_settings['BUNDLE_LOADER'] = '$(TEST_HOST)'
        configuration.build_settings['TEST_HOST'] = test_host
      when :ui_test_bundle
        configuration.build_settings['TEST_TARGET_NAME'] = app_host_target_name
      end
    end
    target_attributes = project.root_object.attributes['TargetAttributes'] || {}
    target_attributes[test_native_target.uuid.to_s] = { 'TestTargetID' => app_native_target.uuid.to_s }
    project.root_object.attributes['TargetAttributes'] = target_attributes
    test_native_target.add_dependency(app_native_target)
  elsif cached_dependency = .[app_host_target_label]
    # Hit the cache
    project.add_cached_subproject_reference(sandbox, cached_dependency, project.dependencies_group)
    Project.add_cached_dependency(sandbox, test_native_target, cached_dependency)
  else
    raise "Expected to either have an installation or cache result for #{app_host_target_label} (from pod #{app_host_pod_target_label}) " \
      "for target #{test_native_target.name} in project #{project.project_name}"
  end
end

#wire_test_native_targets(pod_target, installation_result, pod_target_installation_results, project, frameworks_group, metadata_cache) ⇒ Object (private)


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_dependency_installer.rb', line 94

def wire_test_native_targets(pod_target, installation_result, pod_target_installation_results, project, frameworks_group, )
  installation_result.test_specs_by_native_target.each do |test_native_target, test_spec|
    resource_bundle_native_targets = installation_result.test_resource_bundle_targets[test_spec.name] || []
    resource_bundle_native_targets.each do |test_resource_bundle_target|
      test_native_target.add_dependency(test_resource_bundle_target)
    end

    test_dependent_targets = pod_target.test_dependent_targets_by_spec_name.fetch(test_spec.name, []).+([pod_target]).uniq
    test_dependent_targets.each do |test_dependent_target|
      is_local = sandbox.local?(test_dependent_target.pod_name)
      if dependency_installation_result = pod_target_installation_results[test_dependent_target.name]
        dependent_test_project = dependency_installation_result.native_target.project
        if dependent_test_project != project
          project.add_pod_subproject(dependent_test_project, is_local)
        end
        test_native_target.add_dependency(dependency_installation_result.native_target)
        add_framework_file_reference_to_native_target(test_native_target, pod_target, test_dependent_target, frameworks_group)
      else
        # Hit the cache
        cached_dependency = .[test_dependent_target.label]
        project.add_cached_pod_subproject(sandbox, cached_dependency, is_local)
        Project.add_cached_dependency(sandbox, test_native_target, cached_dependency)
      end
    end

    if app_host_target_label = pod_target.app_host_target_label(test_spec)
      app_host_pod_target_label, app_host_target_label = *app_host_target_label
      wire_test_native_target_app_host(test_native_target, pod_target, pod_target_installation_results, project, , app_host_pod_target_label, app_host_target_label)
    end
  end
end