require 'rubygems' load 'tasks/redis.rake' load 'installer/utils/nix_installation.rake' require 'bundler' Bundler.setup(:default, :development, :test) require 'yaml' $:.unshift File.join(File.dirname(__FILE__),'lib') require 'rhoconnect' include Rake::DSL task :default => 'spec:all' task :spec => 'spec:spec' begin require 'rspec/core/rake_task' require 'rcov/rcovtask' TYPES = { :spec => 'spec/*_spec.rb', :perf => 'spec/perf/*_spec.rb', :server => 'spec/server/*_spec.rb', :api => 'spec/api/**/*_spec.rb', :bulk => 'spec/bulk_data/*_spec.rb', :jobs => 'spec/jobs/*_spec.rb', :stats => 'spec/stats/*_spec.rb', :ping => 'spec/ping/*_spec.rb', :generator => 'spec/generator/*_spec.rb', :bench => 'bench/spec/*_spec.rb' } TYPES.each do |type,files| desc "Run specs in #{files}" RSpec::Core::RakeTask.new("spec:#{type}") do |t| t.rspec_opts = ["-b", "-c", "-fd"] t.pattern = FileList[TYPES[type]] t.rcov = false end end desc "Run specs in spec/**/*_spec.rb " RSpec::Core::RakeTask.new('spec:all') do |t| t.rspec_opts = ["-b", "-c", "-fd"] t.pattern = FileList[TYPES.values] unless RUBY_VERSION =~ /1.9/ # FIXME: code coverage not working for Ruby 1.9 !!! Use CoverMe instead. t.rcov = true t.rcov_opts = ['--exclude', 'spec/*,gems/*,apps/*,bench/spec/*,json/*'] end end desc "Run doc generator - dumps out doc/protocol.html" RSpec::Core::RakeTask.new('doc') do |t| t.pattern = FileList['spec/doc/*_spec.rb'] t.rcov = false end rescue LoadError => e puts "rspec / rcov not available. Install with: " puts "gem install rspec rcov\n\n" end # desc "Build rhoconnect gem" # task :gem => [ 'spec:all', 'clobber_spec:all', :gemspec, :build ] desc "Run benchmark scripts" task :bench do login = ask "login: " password = ask "password: " prefix = 'bench/scripts/' suffix = '_script.rb' list = ask "scripts(default is '*'): " file_list = list.empty? ? FileList[prefix+'*'+suffix] : FileList[prefix+list+suffix] file_list.each do |script| sh "bench/bench start #{script} #{login} #{password}" end end def ask(msg) print msg STDIN.gets.chomp end Bundler::GemHelper.install_tasks require 'rhoconnect/version' desc "Build archive rhoconnect-#{Rhoconnect::VERSION}.tar.gz into the pkg directory" task :archive do `mkdir -p pkg` `git archive --format=tar --prefix=rhoconnect-#{Rhoconnect::VERSION}/ HEAD | gzip > pkg/rhoconnect-#{Rhoconnect::VERSION}.tar.gz` end # Debian and RPM package building tasks def build_pkg(dist, arch, deps) start_dir = `pwd`.strip workspace = "#{start_dir}/pkg/workspace" version = Rhoconnect::VERSION description = '"Rhoconnect production environment"' post_install = "#{workspace}/unix-like/post-install.sh" prefix = "/opt/rhoconnect/installer" gem_name = "rhoconnect-#{version}.gem" pre_install = "#{workspace}/unix-like/pre_install.sh" post_install = "#{workspace}/unix-like/post_install.sh" pre_uninstall = "#{workspace}/unix-like/pre_uninstall.sh" post_uninstall = "#{workspace}/unix-like/post_uninstall.sh" Dir.mkdir("#{workspace}") Dir.mkdir("#{workspace}/unix-like") # Copy all necessary Files into the workspace system("cp install.sh Gemfile Gemfile.lock #{workspace}") system("cp -r installer/unix-like/* #{workspace}/unix-like") system("cp pkg/#{gem_name} #{workspace}") # cd into the pkg dir so that fpm will create the package into the pkg dir. Dir.chdir("./pkg") # Construct fpm command fpm_cmd = "fpm -s dir -t #{dist} -n rhoconnect -v #{version} -a #{arch} -C #{workspace} " + "--pre-install #{pre_install} --post-install #{post_install} " + "--pre-uninstall #{pre_uninstall} --post-uninstall #{post_uninstall} " + "--prefix #{prefix} --description #{description}" # Add the list of dependencies to the fpm call deps.each do |dep| fpm_cmd << " -d '#{dep}'" end #do # Create the package system(fpm_cmd) # Leave no trace... system("rm -rf #{workspace}") Dir.chdir(start_dir) end #build_pkg desc "Build Debian DEB rhoconnect-#{Rhoconnect::VERSION}_all.deb package into the pkg directory" task "build:deb" => :build do deps = [ "wget (>= 1.0)", "make (>= 3.0)", "patch (>= 2.0)", "build-essential (>= 0)", "zlib1g (>= 1.2.3)", "zlib1g-dev (>= 1.2.3)", "libssl0.9.8 (>= 0)", "libssl-dev (>= 0.9.8)", "libcurl4-openssl-dev (>= 0)", "libreadline5 (>= 0)", "libreadline5-dev (>= 0)", # "libreadline6 (>= 0)", "libreadline6-dev (>= 0)", "libsqlite3-0 (>= 3.6.22-1)", "libsqlite3-dev (>= 3.6.22-1)" ] build_pkg "deb", "all", deps end #build:deb desc "Build Red Hat RPM rhoconnect-#{Rhoconnect::VERSION}.noarch.rpm package into the pkg directory" task "build:rpm" => :build do deps = [ "wget >= 1.0", "make >= 3.0", "patch >= 2.0", "gcc-c++ >= 4.1.2", "zlib >= 1.2.3", "zlib-devel >= 1.2.3", "curl >= 7.15.5", "curl-devel >= 7.15.5", "pcre >= 6.6", "pcre-devel >= 6.6", "openssl >= 0.9.8e", "openssl-devel >= 0.9.8e", "readline-devel >= 5.1", "readline-devel >= 5.1" ] build_pkg "rpm", "noarch", deps end #build:rpm