require 'rubygems' require 'bundler' require 'zip/zip' Bundler::GemHelper.install_tasks task :default => :build # common methods for package build scripts require 'fileutils' require "erb" def version require project_root_path('lib/td/version') TreasureData::TOOLBELT_VERSION end def project_root_path(path) "#{PROJECT_ROOT}/#{path}" end PROJECT_ROOT = File.expand_path(File.dirname(__FILE__)) USE_GEMS = ["#{PROJECT_ROOT}/pkg/td-#{version}.gem"] def install_use_gems(target_dir) unless ENV['GEM_HOME'].to_s.empty? puts "**" puts "** WARNING" puts "**" puts "** GEM_HOME is already set. Created package might be broken." puts "** RVM surely breaks the package. Use rbenv instead." puts "**" end require 'rubygems/gem_runner' require 'rubygems/rdoc' # avoid `Gem.finish_resolve` raises error # system(env, cmd) doesn't work with ruby 1.8 ENV['GEM_HOME'] = target_dir ENV['GEM_PATH'] = '' USE_GEMS.each {|gem| begin # this is a hack to have the dependency handling for the 'td' gem # pick up a local gem for 'td-client' so as to be able to build # and test the 'toolbelt' package without publishing the 'td-client' # gem on rubygems.com unless ENV['TD_TOOLBELT_LOCAL_CLIENT_GEM'].nil? unless File.exists? ENV['TD_TOOLBELT_LOCAL_CLIENT_GEM'] raise "Cannot find gem file with path #{ENV['TD_TOOLBELT_LOCAL_CLIENT_GEM']}" end puts "Copy local gem #{ENV['TD_TOOLBELT_LOCAL_CLIENT_GEM']} to #{Dir.pwd}" FileUtils.cp File.expand_path(ENV['TD_TOOLBELT_LOCAL_CLIENT_GEM']), Dir.pwd end Gem::GemRunner.new.run ["install", gem, "--no-rdoc", "--no-ri"] rescue Gem::SystemExitException => e unless e.exit_code.zero? raise e end end } FileUtils.mv Dir.glob("#{target_dir}/gems/*"), target_dir FileUtils.rm_f Dir.glob("#{target_dir}/*.gem") %W(bin cache doc gems specifications build_info).each { |dir| FileUtils.remove_dir("#{target_dir}/#{dir}", true) } end def resource_path(path) project_root_path("dist/resources/#{path}") end def install_resource(resource_name, target_path, mode) FileUtils.mkdir_p File.dirname(target_path) FileUtils.cp resource_path(resource_name), target_path File.chmod(mode, target_path) end def install_erb_resource(resource_name, target_path, mode, variables) FileUtils.mkdir_p File.dirname(target_path) erb_raw = File.read resource_path(resource_name) ctx = Object.new variables.each_pair {|k,v| # ctx.define_singleton_method(k) { v } doesn't work with ruby 1.8 (class<