Class: PodPrebuild::BaseCacheValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-binary-cache/cache/validator_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BaseCacheValidator

Returns a new instance of BaseCacheValidator.



6
7
8
9
10
11
12
# File 'lib/cocoapods-binary-cache/cache/validator_base.rb', line 6

def initialize(options)
  @podfile = options[:podfile]
  @pod_lockfile = options[:pod_lockfile] && PodPrebuild::Lockfile.new(options[:pod_lockfile])
  @prebuilt_lockfile = options[:prebuilt_lockfile] && PodPrebuild::Lockfile.new(options[:prebuilt_lockfile])
  @validate_prebuilt_settings = options[:validate_prebuilt_settings]
  @generated_framework_path = options[:generated_framework_path]
end

Instance Attribute Details

#generated_framework_pathObject (readonly)

Returns the value of attribute generated_framework_path.



4
5
6
# File 'lib/cocoapods-binary-cache/cache/validator_base.rb', line 4

def generated_framework_path
  @generated_framework_path
end

#pod_lockfileObject (readonly)

Returns the value of attribute pod_lockfile.



3
4
5
# File 'lib/cocoapods-binary-cache/cache/validator_base.rb', line 3

def pod_lockfile
  @pod_lockfile
end

#podfileObject (readonly)

Returns the value of attribute podfile.



3
4
5
# File 'lib/cocoapods-binary-cache/cache/validator_base.rb', line 3

def podfile
  @podfile
end

#prebuilt_lockfileObject (readonly)

Returns the value of attribute prebuilt_lockfile.



3
4
5
# File 'lib/cocoapods-binary-cache/cache/validator_base.rb', line 3

def prebuilt_lockfile
  @prebuilt_lockfile
end

#validate_prebuilt_settingsObject (readonly)

Returns the value of attribute validate_prebuilt_settings.



4
5
6
# File 'lib/cocoapods-binary-cache/cache/validator_base.rb', line 4

def validate_prebuilt_settings
  @validate_prebuilt_settings
end

Instance Method Details

#changes_of_prebuilt_lockfile_vs_podfileObject



18
19
20
21
22
# File 'lib/cocoapods-binary-cache/cache/validator_base.rb', line 18

def changes_of_prebuilt_lockfile_vs_podfile
  @changes_of_prebuilt_lockfile_vs_podfile ||= Pod::Installer::Analyzer::SpecsState.new(
    @prebuilt_lockfile.lockfile.detect_changes_with_podfile(@podfile)
  )
end

#incompatible_build_settings(name) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cocoapods-binary-cache/cache/validator_base.rb', line 80

def incompatible_build_settings(name)
  settings_diff = {}
  prebuilt_build_settings = read_prebuilt_build_settings(name)
  validate_prebuilt_settings&.(name)&.each do |key, value|
    prebuilt_value = prebuilt_build_settings[key]
    unless prebuilt_value.nil? || value == prebuilt_value
      settings_diff[key] = { :current => value, :prebuilt => prebuilt_value }
    end
  end
  settings_diff
end

#read_prebuilt_build_settings(name) ⇒ Object



73
74
75
76
77
78
# File 'lib/cocoapods-binary-cache/cache/validator_base.rb', line 73

def read_prebuilt_build_settings(name)
  return {} if generated_framework_path.nil?

   = PodPrebuild::.in_dir(generated_framework_path + name)
  .build_settings
end

#validateObject

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/cocoapods-binary-cache/cache/validator_base.rb', line 14

def validate(*)
  raise NotImplementedError
end

#validate_pods(options) ⇒ Object



31
32
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
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cocoapods-binary-cache/cache/validator_base.rb', line 31

def validate_pods(options)
  pods = options[:pods]
  subspec_pods = options[:subspec_pods]
  prebuilt_pods = options[:prebuilt_pods]

  missed = {}
  hit = Set.new

  check_pod = lambda do |name|
    version = pods[name]
    prebuilt_version = prebuilt_pods[name]
    result = false
    if prebuilt_version.nil?
      missed[name] = "Not available (#{version})"
    elsif prebuilt_version != version
      missed[name] = "Outdated: (prebuilt: #{prebuilt_version}) vs (#{version})"
    else
      settings_diff = incompatible_build_settings(name)
      if settings_diff.empty?
        hit << name
        result = true
      else
        missed[name] = "Incompatible build settings: #{settings_diff}"
      end
    end
    result
  end

  subspec_pods.each do |parent, children|
    missed_children = children.reject { |child| check_pod.call(child) }
    if missed_children.empty?
      hit << parent
    else
      missed[parent] = "Subspec pods were missed: #{missed_children}"
    end
  end

  non_subspec_pods = pods.reject { |pod| subspec_pods.include?(pod) }
  non_subspec_pods.each { |pod, _| check_pod.call(pod) }
  PodPrebuild::CacheValidationResult.new(missed, hit)
end

#validate_with_podfileObject



24
25
26
27
28
29
# File 'lib/cocoapods-binary-cache/cache/validator_base.rb', line 24

def validate_with_podfile
  changes = changes_of_prebuilt_lockfile_vs_podfile
  missed = changes.added.map { |pod| [pod, "Added from Podfile"] }.to_h
  missed.merge!(changes.changed.map { |pod| [pod, "Updated from Podfile"] }.to_h)
  PodPrebuild::CacheValidationResult.new(missed, changes.unchanged)
end