Class: Pod::Installer::Migrator

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

Overview

Migrates installations performed by previous versions of CocoaPods.

Migration Steps collapse

Private helpers collapse

Class Method Summary collapse

Class Method Details

.delete(path) ⇒ void

This method returns an undefined value.

Deletes a path, including non empty directories, printing an UI message.



132
133
134
135
136
137
# File 'lib/cocoapods/installer/migrator.rb', line 132

def delete(path)
  return unless path.exist?
  UI.message "- Deleting #{UI.path(path)}" do
    FileUtils.rm_rf(path)
  end
end

.installation_minor?(target_version, sandbox) ⇒ void

This method returns an undefined value.

Check whether a migration is required

Parameters:

  • target_version (#to_s)

    See Version#new.

  • sandbox (Sandbox)

    The sandbox



87
88
89
# File 'lib/cocoapods/installer/migrator.rb', line 87

def installation_minor?(target_version, sandbox)
  sandbox.manifest.cocoapods_version < Version.new(target_version)
end

.make_path(path) ⇒ void

This method returns an undefined value.

Makes a path creating any intermediate directory and printing an UI message.



99
100
101
102
103
104
# File 'lib/cocoapods/installer/migrator.rb', line 99

def make_path(path)
  return if path.exist?
  UI.message "- Making path #{UI.path(path)}" do
    path.mkpath
  end
end

.migrate(sandbox) ⇒ Object

Performs the migration.

Parameters:

  • sandbox (Sandbox)

    The sandbox which should be migrated.



14
15
16
17
18
19
# File 'lib/cocoapods/installer/migrator.rb', line 14

def migrate(sandbox)
  if sandbox.manifest
    migrate_to_0_34(sandbox) if installation_minor?('0.34', sandbox)
    migrate_to_0_36(sandbox) if installation_minor?('0.36', sandbox)
  end
end

.migrate_to_0_34(sandbox) ⇒ Object

Migrates from CocoaPods versions previous to 0.34.

Parameters:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cocoapods/installer/migrator.rb', line 27

def migrate_to_0_34(sandbox)
  UI.message('Migrating to CocoaPods 0.34') do
    delete(sandbox.root + 'Headers')
    make_path(sandbox.headers_root)

    sandbox.root.children.each do |child|
      relative = child.relative_path_from(sandbox.root)
      case relative.to_s
      when 'Manifest.lock', 'Pods.xcodeproj', 'Headers',
        'Target Support Files', 'Local Podspecs'
        next
      when 'BuildHeaders', 'PublicHeaders'
        delete(child)
      else
        if child.directory? && child.extname != '.xcodeproj'
          next
        else
          delete(child)
        end
      end
    end
  end

  delete(Pathname(File.join(ENV['HOME'], 'Library/Caches/CocoaPods/Git')))
end

.migrate_to_0_36(sandbox) ⇒ Object

Migrates from CocoaPods versions prior to 0.36.

Parameters:



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cocoapods/installer/migrator.rb', line 57

def migrate_to_0_36(sandbox)
  UI.message('Migrating to CocoaPods 0.36') do
    move(sandbox.root + 'Headers/Build', sandbox.root + 'Headers/Private')

    lockfile = sandbox.manifest.to_hash
    sandbox.specifications_root.children.each do |child|
      next unless child.basename.to_s =~ /\.podspec$/
      spec = Specification.from_file(child)
      child.delete
      child = Pathname("#{child}.json")
      File.open(child, 'w') { |f| f.write spec.to_pretty_json }
      lockfile['SPEC CHECKSUMS'][spec.name] = Specification.from_file(child).checksum
    end
    sandbox.manifest = Lockfile.new(lockfile)
    sandbox.manifest.write_to_disk(sandbox.manifest_path)
  end
end

.move(source, destination) ⇒ void

This method returns an undefined value.

Moves a path to another one printing an UI message.



116
117
118
119
120
121
122
# File 'lib/cocoapods/installer/migrator.rb', line 116

def move(source, destination)
  return unless source.exist?
  make_path(destination.dirname)
  UI.message "- Moving #{UI.path(source)} to #{UI.path(destination)}" do
    FileUtils.mv(source.to_s, destination.to_s)
  end
end