require "erb" class Tasks::Toolbelt::Build::Darwin < Tasks::Toolbelt CERTIFICATE_ID = ENV['CERTIFICATE_ID'] || "3PNTC7FC9Q" around_ensure :cleanup def call clean # compile build Tasks::Toolbelt::Build::Tarball.execute(options) create_release add_quandl_executable generate_distribution generate_package_info generate_postinstall generate_bom add_payload add_ruby package_and_sign end def kbytes @kbytes ||= %x{ du -ks #{release_path} | cut -f 1 }.strip.rstrip end def num_files @num_files ||= %x{ find #{release_path} | wc -l }.strip.rstrip end private def create_release # create releases dir and move quandl into it mv release_path, "#{pkg_releases_path}/#{timestamp}" mkdir_p release_path mv pkg_releases_path, "#{release_path}/releases" end def add_quandl_executable mkdir_p "#{release_path}/bin" cp resource("pkg/quandl"), "#{release_path}/bin/quandl" end def generate_distribution mkdir_p "#{pkg_path}/Resources" mkdir_p "#{pkg_path}/quandl-toolbelt.pkg" dist = File.read(resource("pkg/Distribution.erb")) dist = ERB.new(dist).result(binding) File.open("#{pkg_path}/Distribution", "w") { |f| f.puts dist } end def generate_package_info dist = File.read(resource("pkg/PackageInfo.erb")) dist = ERB.new(dist).result(binding) File.open("#{pkg_path}/quandl-toolbelt.pkg/PackageInfo", "w") { |f| f.puts dist } end def generate_postinstall file = File.read(resource("pkg/postinstall.erb")) file = ERB.new(file).result(binding) mkdir_p "#{pkg_path}/quandl-toolbelt.pkg/Scripts" File.open("#{pkg_path}/quandl-toolbelt.pkg/Scripts/postinstall", "w") { |f| f.puts file } chmod 0755, "#{pkg_path}/quandl-toolbelt.pkg/Scripts/postinstall" end def generate_bom sh %{ mkbom -s #{release_path} #{pkg_path}/quandl-toolbelt.pkg/Bom } end def add_payload Dir.chdir(release_path) do sh %{ pax -wz -x cpio . > #{pkg_path}/quandl-toolbelt.pkg/Payload } end end def add_ruby # download, compile, and build ruby pkg unless already done Tasks::Toolbelt::Build::Ruby.execute unless File.exists?(File.join(build_path, 'ruby.pkg')) # include ruby.pkg Dir.chdir(tmp_path) do cp ruby_pkg_path, "ruby-package.pkg" sh %{ pkgutil --expand ruby-package.pkg ruby.pkg } mv "ruby.pkg", "#{pkg_path}/ruby.pkg" end end def package_and_sign sh %{ pkgutil --flatten #{pkg_path} #{build_path}/quandl-toolbelt-unsigned.pkg } sh %{ productsign --sign #{CERTIFICATE_ID} #{build_path}/quandl-toolbelt-unsigned.pkg #{build_path}/quandl-toolbelt.pkg } end def clean rm "#{build_path}/quandl-toolbelt.pkg" if File.exists?("#{build_path}/quandl-toolbelt.pkg") rm_rf tmp_path mkdir_p tmp_path rm_rf pkg_path mkdir_p pkg_path rm_rf pkg_releases_path mkdir_p pkg_releases_path end def cleanup end end