Class: Pod::Installer::ProjectCache::TargetCacheKey

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

Overview

Uniquely identifies a Target.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, key_hash) ⇒ TargetCacheKey

Initialize a new instance.

Parameters:

  • type (Symbol)

    @see #type

  • key_hash (Hash{String => Object})

    @see #key_hash



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

def initialize(type, key_hash)
  @type = type
  @key_hash = key_hash
end

Instance Attribute Details

#key_hashHash{String => Object} (readonly)

Returns The hash containing key-value pairs that identify the target.

Returns:

  • (Hash{String => Object})

    The hash containing key-value pairs that identify the target.



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

def key_hash
  @key_hash
end

#typeSymbol (readonly)

Returns The type of target. Either aggregate or pod target.

Returns:

  • (Symbol)

    The type of target. Either aggregate or pod target.



14
15
16
# File 'lib/cocoapods/installer/project_cache/target_cache_key.rb', line 14

def type
  @type
end

Class Method Details

.from_aggregate_target(aggregate_target) ⇒ TargetCacheKey

Construct a TargetCacheKey instance from an AggregateTarget.

Parameters:

  • aggregate_target (AggregateTarget)

    The aggregate target used to construct a TargetCacheKey object.

Returns:



126
127
128
129
130
131
132
133
# File 'lib/cocoapods/installer/project_cache/target_cache_key.rb', line 126

def self.from_aggregate_target(aggregate_target)
  build_settings = {}
  aggregate_target.user_build_configurations.keys.each do |configuration|
    build_settings[configuration] = Digest::MD5.hexdigest(aggregate_target.build_settings(configuration).xcconfig.to_s)
  end

  TargetCacheKey.new(:aggregate, 'BUILD_SETTINGS_CHECKSUM' => build_settings)
end

.from_cache_hash(key_hash) ⇒ TargetCacheKey

Creates a TargetCacheKey instance from the given hash.

Parameters:

  • key_hash (Hash{String => Object})

    The hash used to construct a TargetCacheKey object.

Returns:



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cocoapods/installer/project_cache/target_cache_key.rb', line 74

def self.from_cache_hash(key_hash)
  cache_hash = key_hash.dup
  if files = cache_hash['FILES']
    cache_hash['FILES'] = files.sort_by(&:downcase)
  end
  if specs = cache_hash['SPECS']
    cache_hash['SPECS'] = specs.sort_by(&:downcase)
  end
  type = cache_hash['CHECKSUM'] ? :pod_target : :aggregate
  TargetCacheKey.new(type, cache_hash)
end

.from_pod_target(pod_target, is_local_pod: false, checkout_options: nil) ⇒ TargetCacheKey

Constructs a TargetCacheKey instance from a PodTarget.

Parameters:

  • pod_target (PodTarget)

    The pod target used to construct a TargetCacheKey object.

  • is_local_pod (Bool) (defaults to: false)

    Used to also include its local files in the cache key.

  • checkout_options (Hash) (defaults to: nil)

    The checkout options for this pod target.

Returns:



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/cocoapods/installer/project_cache/target_cache_key.rb', line 99

def self.from_pod_target(pod_target, is_local_pod: false, checkout_options: nil)
  build_settings = {}
  build_settings[pod_target.label.to_s] = Digest::MD5.hexdigest(pod_target.build_settings.xcconfig.to_s)
  pod_target.test_spec_build_settings.each do |name, settings|
    build_settings[name] = Digest::MD5.hexdigest(settings.xcconfig.to_s)
  end
  pod_target.app_spec_build_settings.each do |name, settings|
    build_settings[name] = Digest::MD5.hexdigest(settings.xcconfig.to_s)
  end

  contents = {
    'CHECKSUM' => pod_target.root_spec.checksum,
    'SPECS' => pod_target.specs.map(&:to_s).sort_by(&:downcase),
    'BUILD_SETTINGS_CHECKSUM' => build_settings,
  }
  contents['FILES'] = pod_target.all_files.sort_by(&:downcase) if is_local_pod
  contents['CHECKOUT_OPTIONS'] = checkout_options if checkout_options
  TargetCacheKey.new(:pod_target, contents)
end

Instance Method Details

#key_difference(other) ⇒ Symbol

Equality function used to compare TargetCacheKey objects to each other.

Parameters:

Returns:

  • (Symbol)

    The difference between this and another TargetCacheKey object. # Symbol :none means no difference.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cocoapods/installer/project_cache/target_cache_key.rb', line 39

def key_difference(other)
  if other.type != type
    :project
  else
    case type
    when :pod_target
      return :project if (other.key_hash.keys - key_hash.keys).any?
      return :project if other.key_hash['CHECKSUM'] != key_hash['CHECKSUM']
      return :project if other.key_hash['SPECS'] != key_hash['SPECS']
      return :project if other.key_hash['FILES'] != key_hash['FILES']
    end

    this_build_settings = key_hash['BUILD_SETTINGS_CHECKSUM']
    other_build_settings = other.key_hash['BUILD_SETTINGS_CHECKSUM']
    return :project if this_build_settings != other_build_settings

    this_checkout_options = key_hash['CHECKOUT_OPTIONS']
    other_checkout_options = other.key_hash['CHECKOUT_OPTIONS']
    return :project if this_checkout_options != other_checkout_options

    :none
  end
end

#to_hObject



63
64
65
# File 'lib/cocoapods/installer/project_cache/target_cache_key.rb', line 63

def to_h
  key_hash
end