Class: Pod::Command::Check

Inherits:
Pod::Command show all
Defined in:
lib/pod/command/check.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Check

Returns a new instance of Check.



27
28
29
30
31
# File 'lib/pod/command/check.rb', line 27

def initialize(argv)
  @check_command_verbose = argv.flag?('verbose')
  @check_command_ignore_dev_pods = argv.flag?('ignore-dev-pods')
  super
end

Class Method Details

.optionsObject



20
21
22
23
24
25
# File 'lib/pod/command/check.rb', line 20

def self.options
  [
    ['--verbose', 'Show change details.'],
    ['--ignore-dev-pods', 'Ignores updates to development pods.']
  ].concat(super)
end

Instance Method Details

#added_result(spec_name) ⇒ Object



170
171
172
173
174
175
176
# File 'lib/pod/command/check.rb', line 170

def added_result(spec_name)
  if @check_command_verbose
    "#{spec_name} newly added"
  else
    "+#{spec_name}"
  end
end

#changed_development_result(spec_name, newer_files) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/pod/command/check.rb', line 157

def changed_development_result(spec_name, newer_files)
  if @check_command_verbose
     number_files_not_shown = newer_files.length - 2
     newer_files = newer_files[0..1]
     if number_files_not_shown > 0
       newer_files.push("and #{number_files_not_shown} other#{'s' if number_files_not_shown > 1}")
     end
    "#{spec_name} (#{newer_files.join(', ')})"
  else
    "~#{spec_name}"
  end
end

#changed_result(spec_name, manifest_version, locked_version) ⇒ Object



149
150
151
152
153
154
155
# File 'lib/pod/command/check.rb', line 149

def changed_result(spec_name, manifest_version, locked_version)
  if @check_command_verbose
    "#{spec_name} #{manifest_version} -> #{locked_version}"
  else
    "~#{spec_name}"
  end
end

#check_manifests(config) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/pod/command/check.rb', line 44

def check_manifests(config)
  # Bail if the first time
  return true unless config.sandbox.manifest

  root_lockfile = config.lockfile.defined_in_file
  pods_manifest = config.sandbox.manifest_path

  File.read(root_lockfile) == File.read(pods_manifest)
end

#find_development_pods(podfile) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/pod/command/check.rb', line 54

def find_development_pods(podfile)
  development_pods = {}
  podfile.dependencies.each do |dependency|
    if dependency.local?
      development_pods[dependency.name] = dependency.external_source.clone
      development_pods[dependency.name][:path] = File.absolute_path(development_pods[dependency.name][:path])
    end
  end
  development_pods
end

#find_differences(config, development_pods) ⇒ Object



65
66
67
68
69
70
71
72
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
# File 'lib/pod/command/check.rb', line 65

def find_differences(config, development_pods)
  all_pod_names = config.lockfile.pod_names
  all_pod_names.concat development_pods.keys

  all_pod_names.sort.uniq.map do |spec_name|
    locked_version = config.lockfile.version(spec_name)

    # If no manifest, assume Pod hasn't been installed
    if config.sandbox.manifest
      manifest_version = config.sandbox.manifest.version(spec_name)
    else
      manifest_version = nil
    end

    # If this Pod is installed
    if manifest_version
      # If this is a development pod do a modified time check
      if development_pods[spec_name] != nil
        next if @check_command_ignore_dev_pods
        newer_files = get_files_newer_than_lockfile_for_podspec(config, development_pods[spec_name])
        if newer_files.any?
          changed_development_result(spec_name, newer_files)
        end
      # Otherwise just compare versions
      elsif locked_version != manifest_version
        changed_result(spec_name, manifest_version, locked_version)
      end

    # If this Pod is not installed
    else
      added_result(spec_name)
    end
  end.compact
end

#get_files_for_podspec(podspec_file) ⇒ Object

Returns an array of all files pointed to by the podspec



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/pod/command/check.rb', line 112

def get_files_for_podspec(podspec_file)
  podspec_file = get_podspec_for_file_or_path(podspec_file)

  development_pod_dir = File.dirname(podspec_file)
  spec = Specification.from_file(podspec_file)

  # Gather all the dependencies used by the spec, across all platforms, and including subspecs.
  all_files = [spec, spec.subspecs].flatten.map { |a_spec|
    a_spec.available_platforms.map { |platform|
      accessor = Sandbox::FileAccessor.new(Sandbox::PathList.new(Pathname.new(development_pod_dir)), a_spec.consumer(platform))
      [
          accessor.vendored_frameworks,
          accessor.vendored_libraries,
          accessor.resource_bundle_files,
          accessor.license,
          accessor.prefix_header,
          accessor.preserve_paths,
          accessor.readme,
          accessor.resources,
          accessor.source_files
      ].compact
    }
  }.flatten

  # Include the podspec files as well
  all_files.push(podspec_file)
end

#get_files_newer_than_lockfile_for_podspec(config, development_pod) ⇒ Object



100
101
102
103
104
105
106
107
108
109
# File 'lib/pod/command/check.rb', line 100

def get_files_newer_than_lockfile_for_podspec(config, development_pod)
  files_for_podspec = get_files_for_podspec(development_pod[:path])

  lockfile_mtime = File.mtime(config.lockfile.defined_in_file)
  podspec_file = get_podspec_for_file_or_path(development_pod[:path])
  podspec_dir = Pathname.new(File.dirname(podspec_file))
  files_for_podspec
      .select {|f| File.mtime(f) >= lockfile_mtime}
      .map {|f| Pathname.new(f).relative_path_from(podspec_dir).to_s}
end

#get_podspec_for_file_or_path(podspec_file_or_path) ⇒ Object



140
141
142
143
144
145
146
147
# File 'lib/pod/command/check.rb', line 140

def get_podspec_for_file_or_path(podspec_file_or_path)
  if File.basename(podspec_file_or_path).include?('.podspec')
    podspec_file_or_path
  else
    glob_pattern = podspec_file_or_path + '/*.podspec{,.json}'
    Pathname.glob(glob_pattern).first
  end
end

Raises:

  • (Informative)


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/pod/command/check.rb', line 178

def print_results(results, same_manifests)
  return UI.puts "The Podfile's dependencies are satisfied" if results.empty? && same_manifests

  unless same_manifests
    raise Informative, 'The Podfile.lock does not match the Pods/Manifest.lock.'
  end

  if @check_command_verbose
    UI.puts results.join("\n")
  else
    UI.puts results.join(', ')
  end

  raise Informative, "`pod install` will install #{results.length} Pod#{'s' if results.length > 1}."
end

#runObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/pod/command/check.rb', line 33

def run
  unless config.lockfile
    raise Informative, 'Missing Podfile.lock!'
  end

  development_pods = find_development_pods(config.podfile)
  results = find_differences(config, development_pods)
  has_same_manifests = check_manifests(config)
  print_results(results, has_same_manifests)
end