LoginSignup
17
6

More than 5 years have passed since last update.

Carthage の update を速くする

Posted at

Carthage、iOS アプリの Build が早くなるのは良いんだけど、update が遅い…。

また、落としてきたバイナリがうまく使えないこともあり、毎回 --no-use-binaries をつけている、フルコンパイルすこぶる遅い、そんな経験ありませんか。

$ carthage update --platform ios --no-use-binaries

だと、毎回ビルドが走ってすこぶる遅いため、変更があったライブラリだけ雑に上げる rake タスクを作りました。

$ rake carthage:update

すると、適当にチェックして、更新がありそうなライブラリだけ update のオプションとして実行します。

require 'pathname'
PROJECT_ROOT = Pathname(__FILE__).parent

namespace 'carthage' do
  def update_libs(libs, no_use_binaries: true)
    command = 'carthage update --platform ios'.split(' ') + libs
    command << '--no-use-binaries' if no_use_binaries
    puts command.flatten.join(' ')
    system(*command)
  end

  desc "minimal update"
  task :update do
    puts "Checking: carthage outdated"
    outdated = `carthage outdated`

    targets = outdated.split("\n").
      select {|l| l.include?(' "') }.
      map    {|l| l.split(' ').first }

    libs = outdated.split("\n").
      select {|l| l.match(/\s(Cloning|Fetching)/) }.
      map {|l| l.split(' ').last }

    installed_libs = Pathname.glob(PROJECT_ROOT + 'Carthage/Build/iOS/*.framework').
      map {|path| path.basename('.framework').to_s }

    targets = (targets + libs - installed_libs).uniq
    if targets.empty?
      puts "Maybe all libs are newest"
    else
      puts "Install: #{targets.join(" ")}"
      update_libs targets
    end
  end
end
17
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
6