Sha256: 4078f0acc081c5489573bf9483b7b2e044870ceaa00b779d13534bca07da3f57

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

require_relative "base"
require_relative "../helper/zip"

module PodPrebuild
  class CacheFetcher < CommandExecutor
    def initialize(options)
      super(options)
      @cache_branch = options[:cache_branch]
    end

    def run
      Pod::UI.step("Fetching cache") do
        fetch_cache(@config.cache_repo, @cache_branch, @config.cache_path)
        unzip_cache
      end
    end

    private

    def fetch_cache(repo, branch, dest_dir)
      Pod::UI.puts "Fetching cache from #{repo} (branch: #{branch})".green
      if Dir.exist?(dest_dir + "/.git")
        git("fetch origin #{branch}")
        git("checkout -f FETCH_HEAD", ignore_output: true)
        git("branch -D #{branch}", ignore_output: true, can_fail: true)
        git("checkout -b #{branch}")
      else
        FileUtils.rm_rf(dest_dir)
        git_clone("--depth=1 --branch=#{branch} #{repo} #{dest_dir}")
      end
    end

    def unzip_cache
      Pod::UI.puts "Unzipping cache: #{@config.cache_path} -> #{@config.prebuild_sandbox_path}".green
      FileUtils.rm_rf(@config.prebuild_sandbox_path)
      FileUtils.mkdir_p(@config.prebuild_sandbox_path)

      if File.exist?(@config.manifest_path(in_cache: true))
        FileUtils.cp(
          @config.manifest_path(in_cache: true),
          @config.manifest_path
        )
      end
      Dir[@config.generated_frameworks_dir(in_cache: true) + "/*.zip"].each do |path|
        ZipUtils.unzip(path, to_dir: @config.generated_frameworks_dir)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cocoapods-binary-cache-0.1.9 lib/command/executor/fetcher.rb
cocoapods-binary-cache-0.1.8 lib/command/executor/fetcher.rb
cocoapods-binary-cache-0.1.7 lib/command/executor/fetcher.rb