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) rm "#{release_path}/bin/quandl" cp resource("pkg/quandl"), "#{release_path}/bin/quandl" kbytes = %x{ du -ks #{release_path} | cut -f 1 }.strip.rstrip num_files = %x{ find #{release_path} | wc -l }.strip.rstrip 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 } 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 } mkdir_p "#{pkg_path}/quandl-toolbelt.pkg/Scripts" cp resource("pkg/postinstall"), "#{pkg_path}/quandl-toolbelt.pkg/Scripts/postinstall" chmod 0755, "#{pkg_path}/quandl-toolbelt.pkg/Scripts/postinstall" sh %{ mkbom -s #{release_path} #{pkg_path}/quandl-toolbelt.pkg/Bom } Dir.chdir(release_path) do sh %{ pax -wz -x cpio . > #{pkg_path}/quandl-toolbelt.pkg/Payload } end # 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 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 protected 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 end def cleanup end end