Class: Pod::Installer::ProjectCache::ProjectCacheAnalyzer

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

Overview

Analyzes the project cache and computes which pod targets need to be generated.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox, cache, build_configurations, project_object_version, podfile_plugins, pod_targets, aggregate_targets, installation_options, clean_install: false) ⇒ ProjectCacheAnalyzer

Initialize a new instance.

Parameters:

  • sandbox (Sandbox)

    @see #sandbox

  • cache (ProjectInstallationCache)

    @see #cache

  • build_configurations (Hash{String => Symbol})

    @see #build_configurations

  • project_object_version (Integer)

    @see #project_object_version

  • podfile_plugins (Hash<String, Hash>)

    @see #podfile_plugins

  • pod_targets (Array<PodTarget>)

    @see #pod_targets

  • aggregate_targets (Array<AggregateTarget>)

    @see #aggregate_targets

  • installation_options (Hash<Symbol, Object>)

    @see #installation_options

  • clean_install (Boolean) (defaults to: false)

    @see #clean_install



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cocoapods/installer/project_cache/project_cache_analyzer.rb', line 57

def initialize(sandbox, cache, build_configurations, project_object_version, podfile_plugins, pod_targets, aggregate_targets, installation_options,
               clean_install: false)
  @sandbox = sandbox
  @cache = cache
  @build_configurations = build_configurations
  @podfile_plugins = podfile_plugins
  @pod_targets = pod_targets
  @aggregate_targets = aggregate_targets
  @project_object_version = project_object_version
  @installation_options = installation_options
  @clean_install = clean_install
end

Instance Attribute Details

#aggregate_targetsArray<AggregateTarget> (readonly)

Returns The list of aggregate targets.

Returns:



35
36
37
# File 'lib/cocoapods/installer/project_cache/project_cache_analyzer.rb', line 35

def aggregate_targets
  @aggregate_targets
end

#build_configurationsHash{String => Symbol} (readonly)

Returns The hash of user build configurations.

Returns:

  • (Hash{String => Symbol})

    The hash of user build configurations.



19
20
21
# File 'lib/cocoapods/installer/project_cache/project_cache_analyzer.rb', line 19

def build_configurations
  @build_configurations
end

#cacheProjectInstallationCache (readonly)

Returns The cache of targets that were previously installed.

Returns:



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

def cache
  @cache
end

#clean_installBoolean (readonly)

Returns Flag indicating if we want to ignore the cache and force a clean installation.

Returns:

  • (Boolean)

    Flag indicating if we want to ignore the cache and force a clean installation.



43
44
45
# File 'lib/cocoapods/installer/project_cache/project_cache_analyzer.rb', line 43

def clean_install
  @clean_install
end

#installation_optionsHash<Symbol, Object> (readonly)

Returns Hash of installation options.

Returns:

  • (Hash<Symbol, Object>)

    Hash of installation options.



39
40
41
# File 'lib/cocoapods/installer/project_cache/project_cache_analyzer.rb', line 39

def installation_options
  @installation_options
end

#pod_targetsArray<PodTarget> (readonly)

Returns The list of pod targets.

Returns:

  • (Array<PodTarget>)

    The list of pod targets.



31
32
33
# File 'lib/cocoapods/installer/project_cache/project_cache_analyzer.rb', line 31

def pod_targets
  @pod_targets
end

#podfile_pluginsHash<String, Hash> (readonly)

Returns The podfile plugins to be run for the installation.

Returns:

  • (Hash<String, Hash>)

    The podfile plugins to be run for the installation.



27
28
29
# File 'lib/cocoapods/installer/project_cache/project_cache_analyzer.rb', line 27

def podfile_plugins
  @podfile_plugins
end

#project_object_versionInteger (readonly)

Returns The object version from the user project.

Returns:

  • (Integer)

    The object version from the user project.



23
24
25
# File 'lib/cocoapods/installer/project_cache/project_cache_analyzer.rb', line 23

def project_object_version
  @project_object_version
end

#sandboxSandbox (readonly)

Returns Project sandbox.

Returns:



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

def sandbox
  @sandbox
end

Instance Method Details

#analyzeProjectCacheAnalysisResult

Returns Compares all targets stored against the cache and computes which targets need to be regenerated.

Returns:

  • (ProjectCacheAnalysisResult)

    Compares all targets stored against the cache and computes which targets need to be regenerated.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
125
126
127
128
129
130
131
132
# File 'lib/cocoapods/installer/project_cache/project_cache_analyzer.rb', line 73

def analyze
  target_by_label = Hash[(pod_targets + aggregate_targets).map { |target| [target.label, target] }]
  cache_key_by_target_label = create_cache_key_mappings(target_by_label)

  full_install_results = ProjectCacheAnalysisResult.new(pod_targets, aggregate_targets, cache_key_by_target_label,
                                                        build_configurations, project_object_version)
  if clean_install
    UI.message 'Ignoring project cache from the provided `--clean-install` flag.'
    return full_install_results
  end

  # Bail out early since these properties affect all targets and their associate projects.
  if cache.build_configurations != build_configurations ||
      cache.project_object_version != project_object_version ||
      YAMLHelper.convert(cache.podfile_plugins) != YAMLHelper.convert(podfile_plugins) ||
      YAMLHelper.convert(cache.installation_options) != YAMLHelper.convert(installation_options)
    UI.message 'Ignoring project cache due to project configuration changes.'
    return full_install_results
  end

  if project_names_changed?(pod_targets, cache)
    UI.message 'Ignoring project cache due to project name changes.'
    return full_install_results
  end

  pod_targets_to_generate = Set[]
  aggregate_targets_to_generate = Set[]
  added_targets = compute_added_targets(target_by_label, cache_key_by_target_label.keys, cache.cache_key_by_target_label.keys)
  added_pod_targets, added_aggregate_targets = added_targets.partition { |target| target.is_a?(PodTarget) }
  pod_targets_to_generate.merge(added_pod_targets)
  aggregate_targets_to_generate.merge(added_aggregate_targets)

  removed_aggregate_target_labels = compute_removed_targets(cache_key_by_target_label.keys, cache.cache_key_by_target_label.keys)

  changed_targets = compute_changed_targets_from_cache(cache_key_by_target_label, target_by_label, cache)
  changed_pod_targets, changed_aggregate_targets = changed_targets.partition { |target| target.is_a?(PodTarget) }
  pod_targets_to_generate.merge(changed_pod_targets)
  aggregate_targets_to_generate.merge(changed_aggregate_targets)

  dirty_targets = compute_dirty_targets(pod_targets + aggregate_targets)
  dirty_pod_targets, dirty_aggregate_targets = dirty_targets.partition { |target| target.is_a?(PodTarget) }
  pod_targets_to_generate.merge(dirty_pod_targets)
  aggregate_targets_to_generate.merge(dirty_aggregate_targets)

  # Since multi xcodeproj will group targets by PodTarget#project_name into individual projects, we need to
  # append these "sibling" targets to the list of targets we need to generate before finalizing the total list,
  # otherwise we will end up with missing targets.
  #
  sibling_pod_targets = compute_sibling_pod_targets(pod_targets, pod_targets_to_generate)
  pod_targets_to_generate.merge(sibling_pod_targets)

  # We either return the full list of aggregate targets or none since the aggregate targets go into the
  # Pods.xcodeproj and so we need to regenerate all aggregate targets when regenerating Pods.xcodeproj.
  total_aggregate_targets_to_generate = unless aggregate_targets_to_generate.empty? && removed_aggregate_target_labels.empty?
                                          aggregate_targets
                                        end

  ProjectCacheAnalysisResult.new(pod_targets_to_generate.to_a, total_aggregate_targets_to_generate,
                                 cache_key_by_target_label, build_configurations, project_object_version)
end