2
# Some parts of this Rakefile where taken from Jim Weirich's Rakefile for
3
# Rake. Other parts where taken from the David Heinemeier Hansson's Rails
4
# Rakefile. Both are under MIT-LICENSE. Thanks to both for their excellent
8
require 'rake/testtask'
9
require 'rake/rdoctask'
11
require 'ferret_version'
15
require 'rake/gempackagetask'
20
CURRENT_VERSION = Ferret::VERSION
22
PKG_VERSION = ENV['REL']
24
PKG_VERSION = CURRENT_VERSION
32
EXT_SRC = FileList["../c/src/*.[c]", "../c/include/*.h",
33
"../c/lib/libstemmer_c/src_c/*.[ch]",
34
"../c/lib/libstemmer_c/runtime/*.[ch]",
35
"../c/lib/libstemmer_c/libstemmer/*.[ch]",
36
"../c/lib/libstemmer_c/include/libstemmer.h"]
37
EXT_SRC.exclude('../**/ind.[ch]')
39
EXT_SRC_DEST = EXT_SRC.map {|fn| File.join("ext", File.basename(fn))}
40
SRC = (FileList["ext/*.[ch]"] + EXT_SRC_DEST).uniq
42
CLEAN.include(FileList['**/*.o', '**/*.obj', 'InstalledFiles',
43
'.config', 'ext/cferret.c'])
44
CLOBBER.include(FileList['**/*.so'], 'ext/Makefile', EXT_SRC_DEST)
45
POLISH = Rake::FileList.new.include(FileList['**/*.so'], 'ext/Makefile')
47
desc "Clean specifically for the release."
48
task :polish => [:clean] do
49
POLISH.each { |fn| rm_r fn rescue nil }
52
desc "Run tests with Valgrind"
54
sh "valgrind --gen-suppressions=yes --suppressions=ferret_valgrind.supp " +
55
"--leak-check=yes --show-reachable=yes -v ruby test/test_all.rb"
56
#sh "valgrind --suppressions=ferret_valgrind.supp " +
57
# "--leak-check=yes --show-reachable=yes -v ruby test/unit/index/tc_index_reader.rb"
58
#valgrind --gen-suppressions=yes --suppressions=ferret_valgrind.supp --leak-check=yes --show-reachable=yes -v ruby test/test_all.rb
61
task :default => :test_all
62
#task :default => :ext do
63
# sh "ruby test/unit/index/tc_index.rb"
67
task :test_all => [ :test_units ]
69
desc "Generate API documentation"
70
task :doc => [ :appdoc ]
72
desc "run unit tests in test/unit"
73
Rake::TestTask.new("test_units" => :ext) do |t|
75
t.pattern = 'test/unit/t[cs]_*.rb'
76
#t.pattern = 'test/unit/search/tc_index_searcher.rb'
80
desc "Generate documentation for the application"
81
rd = Rake::RDocTask.new("appdoc") do |rdoc|
82
rdoc.rdoc_dir = 'doc/api'
83
rdoc.title = "Ferret Search Library Documentation"
84
rdoc.options << '--line-numbers'
85
rdoc.options << '--inline-source'
86
rdoc.options << '--charset=utf-8'
87
rdoc.rdoc_files.include('README')
88
rdoc.rdoc_files.include('TODO')
89
rdoc.rdoc_files.include('TUTORIAL')
90
rdoc.rdoc_files.include('MIT-LICENSE')
91
rdoc.rdoc_files.include('lib/**/*.rb')
92
rdoc.rdoc_files.include('ext/r_*.c')
93
rdoc.rdoc_files.include('ext/ferret.c')
97
dest_fn = File.join("ext", File.basename(fn))
98
file dest_fn => fn do |t|
100
raise "copy for release" if ENV["REL"]
101
ln_s File.join("..", fn), dest_fn
102
rescue Exception => e
103
cp File.expand_path(fn), dest_fn
107
# flatten the directory structure for lib_stemmer
108
open(dest_fn) do |in_f|
109
open(dest_fn + ".out", "w") do |out_f|
110
in_f.each {|line| out_f.write(line.sub(/(#include ["<])[.a-z_\/]*\//) {"#{$1}"})}
113
mv dest_fn + ".out", dest_fn
116
end if File.exists?("../c")
118
desc "Build the extension"
119
task :ext => ["ext/#{EXT}"] + SRC do
120
rm_f 'ext/mem_pool.*'
124
file "ext/#{EXT}" => ["ext/Makefile"] do
125
cp "ext/inc/lang.h", "ext/lang.h"
126
cp "ext/inc/threading.h", "ext/threading.h"
128
if (/mswin/ =~ RUBY_PLATFORM) and ENV['make'].nil?
131
rescue Exception => e
133
puts "**********************************************************************"
134
puts "You may need to call VCVARS32.BAT to set the environment variables."
135
puts ' "f:\Program Files\Microsoft Visual Studio\VC98\Bin\VCVARS32.BAT"'
136
puts "**********************************************************************"
146
file "ext/lang.h" => ["ext/inc/lang.h"] do
148
cp "ext/inc/lang.h", "ext/lang.h"
151
file "ext/threading.h" => ["ext/inc/threading.h"] do
152
rm_f "ext/threading.h"
153
cp "ext/inc/threading.h", "ext/threading.h"
156
file "ext/Makefile" => SRC do
162
# Make Parsers ---------------------------------------------------------------
164
RACC_SRC = FileList["lib/**/*.y"]
165
RACC_OUT = RACC_SRC.collect { |fn| fn.sub(/\.y$/, '.tab.rb') }
167
task :parsers => RACC_OUT
168
rule(/\.tab\.rb$/ => [proc {|tn| tn.sub(/\.tab\.rb$/, '.y')}]) do |t|
169
sh "racc #{t.source}"
172
# Create Packages ------------------------------------------------------------
174
PKG_FILES = FileList[
184
'rake_utils/**/*.rb',
187
PKG_FILES.exclude('**/*.o')
188
PKG_FILES.exclude('**/Makefile')
189
PKG_FILES.exclude('ext/ferret_ext.so')
193
puts "Package Target requires RubyGEMs"
195
spec = Gem::Specification.new do |s|
197
#### Basic information.
199
s.version = PKG_VERSION
200
s.summary = "Ruby indexing library."
201
s.description = <<-EOF
202
Ferret is a port of the Java Lucene project. It is a powerful
203
indexing and search library.
206
#### Dependencies and requirements.
207
s.add_dependency('rake')
208
s.files = PKG_FILES.to_a
209
s.extensions << "ext/extconf.rb"
210
s.require_path = 'lib'
211
s.autorequire = 'ferret'
213
s.executables = ['ferret-browser']
214
s.default_executable = 'ferret-browser'
216
#### Author and project details.
217
s.author = "David Balmain"
218
s.email = "dbalmain@gmail.com"
219
s.homepage = "http://ferret.davebalmain.com/trac"
220
s.rubyforge_project = "ferret"
223
s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
225
'--title' << 'Ferret -- Ruby Indexer' <<
226
'--main' << 'README' << '--line-numbers' <<
229
if RUBY_PLATFORM =~ /mswin/
230
s.files = PKG_FILES.to_a + ["ext/#{EXT}"]
232
s.platform = Gem::Platform::WIN32
236
package_task = Rake::GemPackageTask.new(spec) do |pkg|
237
unless RUBY_PLATFORM =~ /mswin/
244
# Support Tasks ------------------------------------------------------
246
desc "Look for TODO and FIXME tags in the code"
248
FileList['**/*.rb'].egrep /#.*(FIXME|TODO|TBD)/
250
# --------------------------------------------------------------------
253
desc "Make a new release"
262
announce "**************************************************************"
263
announce "* Release #{PKG_VERSION} Complete."
264
announce "* Packages ready to upload."
265
announce "**************************************************************"
269
# Validate that everything is ready to go for a release.
272
announce "**************************************************************"
273
announce "* Making RubyGem Release #{PKG_VERSION}"
274
announce "* (current version #{CURRENT_VERSION})"
275
announce "**************************************************************"
278
# Is a release number supplied?
280
fail "Usage: rake release REL=x.y.z [REUSE=tag_suffix]"
283
# Is the release different than the current release.
285
if PKG_VERSION == CURRENT_VERSION && ! ENV['REUSE']
286
fail "Current version is #{PKG_VERSION}, must specify REUSE=tag_suffix to reuse version"
289
# Are all source files checked in?
290
data = `svn -q --ignore-externals status`
292
fail "'svn -q status' is not clean ... do you have unchecked-in files?"
295
announce "No outstanding checkins found ... OK"
299
open(fn) do |ferret_in|
300
open(fn + ".new", "w") do |ferret_out|
301
ferret_in.each do |line|
302
if line =~ /^ VERSION\s*=\s*/
303
ferret_out.puts " VERSION = '#{PKG_VERSION}'"
313
task :update_version => [:prerelease] do
314
if PKG_VERSION == CURRENT_VERSION
315
announce "No version change ... skipping version update"
317
announce "Updating Ferret version to #{PKG_VERSION}"
318
reversion("lib/ferret_version.rb")
320
announce "Release Task Testing, skipping commiting of new version"
322
sh %{svn ci -m "Updated to version #{PKG_VERSION}" lib/ferret_version.rb}
327
desc "Tag all the SVN files with the latest release number (REL=x.y.z)"
328
task :tag => [:prerelease] do
329
reltag = "REL-#{PKG_VERSION}"
330
reltag << ENV['REUSE'] if ENV['REUSE']
331
announce "Tagging SVN with [#{reltag}]"
333
announce "Release Task Testing, skipping SVN tagging. Would do the following;"
334
announce %{svn copy -m "creating release #{reltag}" svn://www.davebalmain.com/ferret/trunk svn://www.davebalmain.com/ferret/tags/#{reltag}}
336
sh %{svn copy -m "creating release #{reltag}" svn://www.davebalmain.com/ferret/trunk svn://www.davebalmain.com/ferret/tags/#{reltag}}