$:.unshift "lib" if File.directory? "lib"
require 'rake/testtask'

desc "Run the functional and unit tests."
Rake::TestTask.new(:test) do |t|
  t.test_files = FileList['test/test*.rb']
  t.verbose = true
end

require 'rcov/rcovtask'
desc "Run rcov."
Rcov::RcovTask.new do |t|
  t.test_files = FileList['test/test_*.rb'].to_a.reject{|x| /test_functional/ =~ x}
  t.verbose = true
end

desc "Save current coverage state for later comparisons."
Rcov::RcovTask.new(:rcovsave) do |t|
  t.rcov_opts << "--save"
  t.test_files = FileList['test/test_*.rb'].to_a.reject{|x| /test_functional/ =~ x}
  t.verbose = true
end

task :default => :test

# {{{ Package tasks

require 'fastri/version'

PKG_REVISION = ".1"
PKG_FILES = FileList[
"bin/fri", "bin/qri", "bin/fastri-server", "bin/ri-emacs",
"lib/**/*.rb", "CHANGES",
"COPYING", "LEGAL", "LICENSE", "Rakefile", "README.*", "test/*.rb",
"setup.rb", "pre-install.rb", 
]

require 'rake/gempackagetask'
Spec = Gem::Specification.new do |s|
  s.name = "fastri"
  s.version = FastRI::FASTRI_VERSION + PKG_REVISION
  s.summary = "RI docs across machines, faster and smarter than ri."
  s.description = <<EOF
FastRI is an alternative to the ri command-line tool. It is *much* faster, and
also allows you to offer RI lookup services over DRb. FastRI is smarter than
ri, and can find classes anywhere in the hierarchy without specifying the
"full path". FastRI can perform fast full-text searches. It also knows about
gems, and can tell you e.g. which extensions to a core class were added by a
specific gem.
EOF
  s.files = PKG_FILES.to_a
  s.require_path = 'lib'
  s.author = "Mauricio Fernandez"
  s.email = "mfp@acm.org"
  s.homepage = "http://eigenclass.org/hiki/fastri"
  s.bindir = "bin"
  s.executables = %w[fri qri fastri-server ri-emacs]
  s.has_rdoc = true
  #s.extra_rdoc_files = %w[]
  s.rdoc_options << "--title" << 'FastRI: better, faster ri'
  s.test_files = Dir["test/test_*.rb"]
  s.post_install_message = <<EOF

A small note about RubyGems + FastRI
====================================
RubyGems adds a noticeable overhead to fri, making it run slower than if you
installed it directly from the tarball with setup.rb.

Compare the execution time when installed with RubyGems:
  $ time fri -f plain String > /dev/null

  real	0m0.385s
  user	0m0.244s
  sys	0m0.036s

to the time fri actually takes to run, without the overhead introduced by 
RubyGems:
  $ time ruby bin/fri -f plain String > /dev/null

  real	0m0.088s
  user	0m0.040s
  sys	0m0.008s

If you care about those extra 300ms (and there are situations where they will
matter, e.g. when using fri for method completion), get FastRI from the
tarballs.

EOF
end

task :gem => [:test]
Rake::GemPackageTask.new(Spec) do |p|
  p.need_tar = true
end

file "bin/qri" => %w[bin/fri] do
  cp "bin/fri", "bin/qri"
end

task :gem => ["bin/qri"]

# vim: set sw=2 ft=ruby:
