# -*- ruby -*- require 'rubygems' require 'rake' require 'rake/contrib/sshpublisher' require 'rake/gempackagetask' require 'rake/rdoctask' require 'rake/testtask' require 'rbconfig' ## # hoe - a tool to help rake # # Hoe is a simple rake/rubygems helper for project Rakefiles. It # generates all the usual tasks for projects including rdoc generation, # testing, packaging, and deployment. # # == Using Hoe # # === Basics # # Use this as a minimal starting point: # # require 'hoe' # # Hoe.new("project_name", '1.0.0') do |p| # p.rubyforge_name = "rf_project" # # add other details here # end # # # add other tasks here # # === Tasks Provided: # # * audit - Run ZenTest against the package # * clean - Clean up all the extras # * debug_gem - Show information about the gem # * default - Run the default tasks # * docs - Build the docs HTML Files # * install - Install the package. Uses PREFIX and RUBYLIB # * multi - Run the test suite using multiruby # * package - Build all the packages # * publish_docs - Publish RDoc to RubyForge # * release - Package and upload the release to RubyForge # * test - Run the test suite. Use FILTER to add to the command line. # * uninstall - Uninstall the package. # * upload - Upload RDoc to RubyForge # # === Attributes # # The attributes that you can provide inside the new block above are: # # ==== Mandatory (or damn good to set) # # * author - The author of the package. (can be array of authors) # * description - A description of the project. # * email - The author's email address. # * name - The name of the release. # * summary - A short summary of the project. # * url - The url of the project. # * version - The version. Don't hardcode! use a constant in the project. # # ==== Optional # # * clean_globs - An array of file patterns to delete on clean. # * extra_deps - An array of rubygem dependencies. # * rubyforge_name - The name of the rubyforge project. [default: name.downcase] # # === Environment Variables # # * PREFIX - Used to specify a custom install location (for rake install). # * RUBY_FLAGS - Used to specify flags to ruby [has smart default]. # * RUBY_DEBUG - Used to add extra flags to RUBY_FLAGS. # * FILTER - Used to add flags to test_unit (e.g., -n test_borked) class Hoe VERSION = '1.0.4' rubyprefix = Config::CONFIG['prefix'] sitelibdir = Config::CONFIG['sitelibdir'] PREFIX = ENV['PREFIX'] || rubyprefix RUBYLIB = if PREFIX == rubyprefix then sitelibdir else File.join(PREFIX, sitelibdir[rubyprefix.size..-1]) end RUBY_DEBUG = ENV['RUBY_DEBUG'] RUBY_FLAGS = ENV['RUBY_FLAGS'] || "-w -I#{%w(lib bin test).join(File::PATH_SEPARATOR)}" + (RUBY_DEBUG ? " #{RUBY_DEBUG}" : '') FILTER = ENV['FILTER'] # for tests (eg FILTER="-n test_blah") attr_accessor :author, :bin_files, :clean_globs, :description, :email, :extra_deps, :lib_files, :name, :rubyforge_name, :spec, :summary, :test_files, :url, :version def initialize(name, version) self.name = name self.version = version # Defaults self.rubyforge_name = name.downcase self.url = "http://www.zenspider.com/ZSS/Products/#{name}/" self.author = "Ryan Davis" self.email = "ryand-ruby@zenspider.com" self.clean_globs = %w(diff diff.txt demo.rb ri *.gem **/*~) self.description = "#{author} is too lazy to write a description" self.summary = "#{author} is too lazy to write a summary" self.extra_deps = [] if name == 'hoe' then extra_deps << ['rake'] extra_deps << ['rubyforge'] else extra_deps << ['hoe'] end yield self if block_given? define_tasks end def define_tasks desc 'Run the default tasks' task :default => :test desc 'Run the test suite. Use FILTER to add to the command line.' task :test do run_tests end desc 'Run the test suite using multiruby' task :multi do run_tests :multi end ############################################################ # Packaging and Installing self.spec = Gem::Specification.new do |s| s.name = name s.version = version s.summary = summary case author when Array s.authors = author else s.author = author end s.email = email s.homepage = url s.rubyforge_project = rubyforge_name s.description = description extra_deps.each do |dep| s.add_dependency(*dep) end s.files = File.read("Manifest.txt").split s.executables = s.files.grep(/bin/) { |f| File.basename(f) } s.bindir = "bin" s.require_paths = Dir['{lib,test}'] s.has_rdoc = true s.test_suite_file = "test/test_all.rb" if test ?f, "test/test_all.rb" end desc 'Show information about the gem.' task :debug_gem do puts spec.to_ruby end self.lib_files = spec.files.grep(/^lib/) self.bin_files = spec.files.grep(/^bin/) self.test_files = %w(test/test_sexp_processor.rb) # for ruby_to_c's tests. Rake::GemPackageTask.new spec do |pkg| pkg.need_tar = true end desc 'Install the package. Uses PREFIX and RUBYLIB' task :install do [ [lib_files + test_files, RUBYLIB, 0444], [bin_files, file.join(PREFIX, 'bin'), 0555] ].each do |files, dest, mode| FileUtils.mkdir_p dest unless test ?d, dest files.each do |file| install file, dest, :mode => mode end end end desc 'Uninstall the package.' task :uninstall do Dir.chdir RUBYLIB do rm_f((lib_files + test_files).map { |f| File.basename f }) end Dir.chdir File.join(PREFIX, 'bin') do rm_f bin_files.map { |f| File.basename f } end end desc 'Package and upload the release to rubyforge.' task :release => [:clean, :package] do |t| v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z" abort "Versions don't match #{v} vs #{version}" if v != version require 'rubyforge' pkg = "pkg/#{name}-#{version}" if $DEBUG then puts "release_id = rf.add_release #{rubyforge_name.inspect}, #{name.inspect}, #{version.inspect}, \"#{pkg}.tgz\"" puts "rf.add_file #{rubyforge_name.inspect}, #{name.inspect}, release_id, \"#{pkg}.gem\"" end rf = RubyForge.new puts "Logging in" rf.login puts "Releasing #{name} v. #{version} tarball" release_id = rf.add_release rubyforge_name, name, version, "#{pkg}.tgz" if release_id then puts " release_id = #{release_id.inspect}" puts "Releasing #{name} v. #{version} gem" rf.add_file rubyforge_name, name, release_id, "#{pkg}.gem" else abort "Couldn't get release_id" end end ############################################################ # Doco Rake::RDocTask.new(:docs) do |rd| rd.main = "README.txt" rd.options << '-d' if `which dot` =~ /\/dot/ and RUBY_PLATFORM !~ /win32/ rd.rdoc_dir = 'doc' rd.rdoc_files.push(*spec.files.grep(/^(lib|bin)|txt$/)) end desc "Generate ri locally for testing" task :ridocs => :clean do sh %q{ rdoc --ri -o ri . } end desc 'Publish RDoc to RubyForge' task :publish_docs => [:clean, :docs] do config = YAML.load(File.read(File.expand_path("~/.rubyforge/config.yml"))) user = "#{config["username"]}@rubyforge.org" project = "/var/www/gforge-projects/#{rubyforge_name}" project += "/#{name}" if rubyforge_name != name local_dir = 'doc' pub = Rake::SshDirPublisher.new user, project, local_dir if rubyforge_name != name then def pub.upload begin super rescue # project directory probably doesn't exist, transfer as a whole sh %{scp -qr #{local_dir} #{host}:#{remote_dir}} end end end pub.upload end ############################################################ # Misc/Maintenance: desc 'Run ZenTest against the package' task :audit do libs = %w(lib test).join(File::PATH_SEPARATOR) sh "zentest -I=#{libs} #{spec.files.grep(/^(lib|test)/).join(' ')}" end desc 'Clean up all the extras' task :clean => [ :clobber_docs, :clobber_package ] do clean_globs.each do |pattern| files = Dir[pattern] rm_rf files unless files.empty? end end end # end define def run_tests(multi=false) msg = multi ? :sh : :ruby cmd = if test ?f, 'test/test_all.rb' then "#{RUBY_FLAGS} test/test_all.rb #{FILTER}" else tests = (Dir.glob("test/**/test_*.rb") + ['test/unit']).map { |f| "require \"#{f}\"" } "#{RUBY_FLAGS} -e '#{tests.join("; ")}' #{FILTER}" end cmd = "multiruby #{cmd}" if multi send msg, cmd end end class ::Rake::SshDirPublisher # :nodoc: attr_reader :host, :remote_dir, :local_dir end