Skip to content

Instantly share code, notes, and snippets.

@leoMehlig
Last active June 2, 2016 17:48
Show Gist options
  • Select an option

  • Save leoMehlig/524947ddc77676eb3b1e7b2a7d534a54 to your computer and use it in GitHub Desktop.

Select an option

Save leoMehlig/524947ddc77676eb3b1e7b2a7d534a54 to your computer and use it in GitHub Desktop.
A ruby script that updates Carthage dependencies and only builds new ones
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
if ARGV.first && ARGV.first.length > 0
path = Pathname.new(ARGV.first).realpath()
args = ARGV.drop(1).join(" ")
else
path = Pathname.pwd()
args = ARGV.join(" ")
end
puts path
resolved_path = path + "Cartfile.resolved"
resolved_old_path = path + "Cartfile.resolved.old"
if File.exists?(resolved_old_path)
puts "Carfile.resolved.old already exists. Using that one."
end
if File.exists?(resolved_path)
FileUtils.cp(resolved_path, resolved_old_path)
end
puts "Fetching dependencies"
puts `carthage update --project-directory #{path} --no-build --no-checkout #{args}`
puts "Comparing dependencies"
if File.exists?(resolved_old_path)
old_deps = IO.readlines(resolved_old_path)
else
old_deps = []
end
need_build = []
File.new(resolved_path).each do |line|
need_build.push(line) unless old_deps.any? { |old| line == old }
end
puts "#{need_build.length()} need to be (re)build."
need_build.each {|d|
puts d
}
deps = need_build.map { |d| /(?:^(?:git|github)\s\".+?\/(.+?)\")/.match(d)[1] }
puts "Building #{deps.join(", ")}..." unless deps.empty?
puts `carthage update #{deps.join(" ")} #{args}` unless deps.empty?
puts "Deleting Carthage.resolved.old file"
if File.exists?(resolved_old_path)
FileUtils.rm resolved_old_path
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment