1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
|
require 'rake'
require 'rake/clean'
#require 'rake/gempackagetask'
require 'rubygems/package_task'
#require 'rake/rdoctask'
require 'rdoc/task'
require 'rake/testtask'
$:. << 'lib'
require 'ferret/version'
def say(msg='')
STDERR.puts msg
end
def prompt(msg)
STDERR.print "#{msg} [Yna]: "
while true
case STDIN.gets.chomp!
when /^(y(es)?)?$/i then return true
when /^no?$/i then return false
when /^a(bort)?$/i then fail('aborted')
else
STDERR.print "Sorry, I don't understand. Please type y, n or a: "
end
end
end
windows = (RUBY_PLATFORM =~ /win32|cygwin/) rescue nil
SUDO = windows ? "" : "sudo "
task :default => 'test:unit'
#task :default => :build do
# sh "ruby test/unit/index/tc_index.rb"
#end
BZLIB_SRC = FileList["../c/lib/bzlib/*.h"] +
FileList["../c/lib/bzlib/*.c"].map do |fn|
fn.gsub(%r{/([^/]*.c)}, '/BZ_\1')
end
##############################################################################
# Building
##############################################################################
task :build => 'build:compile'
namespace :build do
EXT = "ferret_ext.so"
# Note: libstemmer.[h] is necessary so that the file isn't included when it
# doesn't exist. It needs to have one regular expression element.
EXT_SRC = FileList["../c/src/*.[ch]", "../c/include/*.h",
"../c/lib/bzlib/*.[ch]",
"../c/lib/libstemmer_c/src_c/*.[ch]",
"../c/lib/libstemmer_c/runtime/*.[ch]",
"../c/lib/libstemmer_c/libstemmer/*.[ch]",
"../c/lib/libstemmer_c/include/libstemmer.[h]"]
EXT_SRC.exclude('../c/**/ind.[ch]',
'../c/**/symbol.[ch]',
'../c/include/threading.h',
'../c/include/scanner.h',
'../c/include/internal.h',
'../c/src/lang.c',
'../c/include/lang.h')
EXT_SRC_MAP = {}
EXT_SRC_DEST = EXT_SRC.map do |fn|
ext_fn = File.join("ext", File.basename(fn))
if fn =~ /.c$/ and fn =~ /(bzlib|stemmer)/
prefix = $1.upcase
ext_fn.gsub!(/ext\//, "ext/#{prefix}_")
end
EXT_SRC_MAP[fn] = ext_fn
end
SRC = FileList["ext/*.[ch]", EXT_SRC_DEST, 'ext/internal.h'].uniq
CLEAN.include ['**/*.o', '**/*.obj', '.config', 'ext/cferret.c']
CLOBBER.include ['doc/api', 'ext/*.so', 'ext/Makefile',
'ext/internal.h', EXT_SRC_DEST]
# The following block creates file tasks for all of the c files. They
# belong in the ../c directory in source the working copy and they need
# to be linked to in the ext directory
EXT_SRC.each do |fn|
dest_fn = EXT_SRC_MAP[fn]
# prepend lib files to avoid conflicts
file dest_fn => fn do |t|
ln_sf File.expand_path(fn), File.expand_path(dest_fn)
if fn =~ /stemmer/
# flatten the directory structure for lib_stemmer
open(dest_fn) do |in_f|
open(dest_fn + ".out", "w") do |out_f|
in_f.each do |line|
out_f.write(line.sub(/(#include ["<])[.a-z_\/]*\//, '\1'))
end
end
end
mv dest_fn + ".out", dest_fn
end
end
end if File.exists?("../c")
file 'ext/internal.h' => '../c/include/internal.h' do
File.open('ext/internal.h', 'w') do |f|
File.readlines('../c/include/internal.h').each do |l|
next if l =~ /ALLOC/ and l !~ /ZERO|MP_/
f.puts(l)
end
end
end
desc "Build the extension (ferret_ext.so). You'll need a C compiler and Make."
task :compile => ["ext/#{EXT}"] + SRC
file "ext/#{EXT}" => "ext/Makefile" do
cd "ext"
if windows and ENV['make'].nil?
begin
sh "nmake"
rescue Exception => e
path = ':\Program Files\Microsoft Visual Studio\VC98\Bin\VCVARS32.BAT'
if File.exists? "f#{path}"
sh "f#{path}"
elsif File.exists? "c#{path}"
sh "c#{path}"
else
say
say "***************************************************************"
say "You need to have Visual C++ 6 to build Ferret on Windows."
say "If you have it installed, you may need to run;"
say ' C:\Program Files\Microsoft Visual Studio\VC98\Bin\VCVARS32.BAT'
say "***************************************************************"
say
raise e
end
sh "nmake"
end
else
sh "make"
end
cd ".."
end
file "ext/Makefile" => SRC do
cd "ext"
ruby "extconf.rb"
cd ".."
end
end
##############################################################################
# Testing
##############################################################################
task :test => 'test:units'
namespace :test do
desc "Run tests with Valgrind"
task :valgrind do
sh "valgrind --suppressions=ferret_valgrind.supp " +
"--leak-check=yes --show-reachable=yes " +
"-v ruby test/unit/index/tc_index_reader.rb"
end
desc "Run all tests"
task :all => [ :units ]
desc "run unit tests in test/unit"
Rake::TestTask.new("units" => :build) do |t|
t.libs << "test/unit"
t.pattern = 'test/unit/t[cs]_*.rb'
t.verbose = true
end
task :unit => :units
desc "run tests using locally installed gem"
Rake::TestTask.new("installed") do |t|
t.libs << "test/unit"
t.ruby_opts << '-rtest/test_installed'
t.pattern = 'test/unit/t[cs]_*.rb'
t.verbose = true
end
end
##############################################################################
# Documentation
##############################################################################
desc "Generate API documentation"
task :doc => 'doc:rdoc'
namespace :doc do
if allison = Gem.cache.find_name('allison').last
allison_template = File.join(allison.full_gem_path, 'lib/allison.rb')
end
desc "Generate documentation for the application"
$rd = Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'doc/api'
rdoc.title = "Ferret Search Library Documentation"
rdoc.options << '--line-numbers'
rdoc.options << '--inline-source'
rdoc.options << '--charset=utf-8'
rdoc.template = allison_template if allison_template
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('TODO')
rdoc.rdoc_files.include('TUTORIAL')
rdoc.rdoc_files.include('MIT-LICENSE')
rdoc.rdoc_files.include('lib/**/*.rb')
rdoc.rdoc_files.include('ext/r_*.c')
rdoc.rdoc_files.include('ext/ferret.c')
end
desc "Look for TODO and FIXME tags in the code"
task :todo do
FileList['**/*.rb', 'ext/*.[ch]'].egrep /[#*].*(FIXME|TODO|TBD)/i
end
end
##############################################################################
# Packaging and Installing
##############################################################################
PKG_FILES = FileList[
'setup.rb',
'[-A-Z]*',
'lib/**/*.rb',
'lib/**/*.rhtml',
'lib/**/*.css',
'lib/**/*.js',
'test/**/*.rb',
'test/**/wordfile',
'rake_utils/**/*.rb',
'Rakefile',
SRC
]
spec = Gem::Specification.new do |s|
#### Basic information.
s.name = 'ferret'
s.version = Ferret::VERSION
s.summary = "Ruby indexing library."
s.description = "Ferret is a super fast, highly configurable search library."
#### Dependencies and requirements.
s.add_development_dependency('rake')
s.files = PKG_FILES.to_a
s.extensions << "ext/extconf.rb"
s.require_path = 'lib'
s.bindir = 'bin'
s.executables = ['ferret-browser']
s.default_executable = 'ferret-browser'
#### Author and project details.
s.author = "David Balmain"
s.email = "dbalmain@gmail.com"
#s.homepage = "http://ferret.davebalmain.com/trac"
s.homepage = "http://github.com/jkraemer/ferret"
s.rubyforge_project = "ferret"
s.has_rdoc = true
s.extra_rdoc_files = $rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
s.rdoc_options <<
'--title' << 'Ferret -- Ruby Search Library' <<
'--main' << 'README' << '--line-numbers' <<
'TUTORIAL' << 'TODO'
key_file = File.expand_path('~/.gem/gem-private_key.pem')
key_file = nil unless File.exists?(key_file)
cert_file = File.expand_path('~/.gem/gem-public_cert.pem')
cert_file = nil unless File.exists?(cert_file)
if key_file and cert_file
s.signing_key = key_file
s.cert_chain = cert_file
end
if windows
s.files = PKG_FILES.to_a + ["ext/#{EXT}"]
s.extensions.clear
s.platform = Gem::Platform::WIN32
else
s.platform = Gem::Platform::RUBY
end
end
package_task = Gem::PackageTask.new(spec) do |pkg|
unless windows
pkg.need_zip = true
pkg.need_tar = true
end
end
desc "Run :gem and install the resulting gem"
task :install => :gem do
sh "#{SUDO}gem install pkg/ferret-#{Ferret::VERSION}.gem --no-rdoc --no-ri -l"
end
desc "Run :clobber and uninstall the .gem"
task :uninstall => :clobber do
sh "#{SUDO}gem uninstall ferret"
end
desc "Same as :install but you must be rootgem"
task :root_install => :gem do
sh "gem install pkg/ferret-#{Ferret::VERSION}.gem --no-rdoc --no-ri -l"
end
desc "Same as :uninstall but you must be root"
task :root_uninstall => :clobber do
sh "gem uninstall ferret"
end
def list_changes_since_last_release
tag_listing = `svn list svn://davebalmain.com/ferret/tags`
last_tag = tag_listing.split("\n").last
log = `svn log --stop-on-copy svn://davebalmain.com/ferret/tags/#{last_tag}`
first_log = log.split(/-------+/)[-2]
last_revision = /^r(\d+)\s+\|/.match(first_log)[1]
`svn log .. -rHEAD:#{last_revision}`
end
desc "List changes since last release"
task :changes do
puts list_changes_since_last_release
end
if ENV['FERRET_DEV']
##############################################################################
# Releasing
##############################################################################
desc "Generate and upload a new release"
task :release => 'release:release'
namespace :release do
task :release => [:status_check, 'test:all', :package, :tag] do
say
say "**************************************************************"
say "* Release #{Ferret::VERSION} Complete."
say "* Packages ready to upload."
say "**************************************************************"
say
reversion("lib/ferret/version.rb")
end
# Validate that everything is ready to go for a release.
task :status_check do
# Are all source files checked in?
unless `svn -q --ignore-externals status` =~ /^$/
fail "'svn -q status' is not clean ... do you have unchecked-in files?"
end
say "No outstanding checkins found ... OK"
end
def reversion(fn)
new_version = nil
begin
print "Ferret is currently at #{Ferret::VERSION}. What version now? "
new_version = STDIN.gets.chomp!
end until prompt("Change to version #{new_version}?")
if ENV['RELTEST']
say "Would change the version in lib/ferret/version.rb from"
say " #{Ferret::VERSION} => #{new_version}"
say "and then commit the changes with the command"
say " svn ci -m \"Updated to version #{new_version}\" " +
"lib/ferret/version.rb"
else
open(fn) do |ferret_in|
open(fn + ".new", "w") do |ferret_out|
ferret_in.each do |line|
if line =~ /^ VERSION\s*=\s*/
ferret_out.puts " VERSION = '#{new_version}'"
else
ferret_out.puts line
end
end
end
end
mv fn + ".new", fn
sh %{svn ci -m "Updated to version #{new_version}" lib/ferret/version.rb}
end
end
# Tag all the SVN files with the latest release number
task :tag => :status_check do
reltag = "REL-#{Ferret::VERSION}"
say "Tagging SVN with [#{reltag}]"
if ENV['RELTEST']
say "Release Task Testing, skipping SVN tagging. Would do;"
say %{svn copy -m "creating release #{reltag}" svn://www.davebalmain.com/ferret/trunk svn://www.davebalmain.com/ferret/tags/#{reltag}}
else
sh %{svn copy -m "creating release #{reltag}" svn://www.davebalmain.com/ferret/trunk svn://www.davebalmain.com/ferret/tags/#{reltag}}
end
end
end
##############################################################################
# Publishing
##############################################################################
namespace :publish do
PUBLISH_PROMPT = <<-EOF
Make sure you updated RELEASE_NOTES and RELEASE_CHANGES and that the
package exists. Are you sure you want to continue?
EOF
desc "Publish gem on rubyforge for download. Will only do the linux version"
task :release do
exit unless prompt(PUBLISH_PROMPT)
require 'rubyforge'
require 'rake/contrib/rubyforgepublisher'
version = Ferret::VERSION
packages = %w(gem tgz zip).map {|ext| "pkg/ferret-#{version}.#{ext}"}
rubyforge = RubyForge.new
rubyforge.login
rubyforge.add_release('ferret', 'ferret',
"ferret-#{version}", *packages)
end
desc "Publish the documentation"
task :docs => 'doc:rdoc' do
sh %{rsync -rzv --delete -e 'ssh -p 8900' doc/api/ davebalmain.com:/var/www/ferret/api}
end
desc "Publish the documentation and release"
task :all => [:doc, :release]
end
end
#
# In case I ever need to add another racc parser, here's how
#
# # Make Parsers ---------------------------------------------------------------
#
# RACC_SRC = FileList["lib/**/*.y"]
#
# task :parsers => RACC_OUT
# rule(/\.tab\.rb$/ => [proc {|tn| tn.sub(/\.tab\.rb$/, '.y')}]) do |t|
# sh "racc #{t.source}"
# end
|