~ubuntu-branches/ubuntu/wily/ruby-ferret/wily

« back to all changes in this revision

Viewing changes to Rakefile

  • Committer: Bazaar Package Importer
  • Author(s): Antonio Terceiro
  • Date: 2011-07-28 00:02:49 UTC
  • Revision ID: james.westby@ubuntu.com-20110728000249-v0443y69ftcpxwi6
Tags: upstream-0.11.6
ImportĀ upstreamĀ versionĀ 0.11.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
$:. << 'lib'
 
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
 
5
# projects.
 
6
 
 
7
require 'rake'
 
8
require 'rake/testtask'
 
9
require 'rake/rdoctask'
 
10
require 'rake/clean'
 
11
require 'ferret_version'
 
12
 
 
13
begin
 
14
  require 'rubygems'
 
15
  require 'rake/gempackagetask'
 
16
rescue Exception
 
17
  nil
 
18
end
 
19
 
 
20
CURRENT_VERSION = Ferret::VERSION
 
21
if ENV['REL']
 
22
  PKG_VERSION = ENV['REL']
 
23
else
 
24
  PKG_VERSION = CURRENT_VERSION
 
25
end
 
26
 
 
27
def announce(msg='')
 
28
  STDERR.puts msg
 
29
end
 
30
 
 
31
EXT = "ferret_ext.so"
 
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]')
 
38
 
 
39
EXT_SRC_DEST = EXT_SRC.map {|fn| File.join("ext", File.basename(fn))}
 
40
SRC = (FileList["ext/*.[ch]"] + EXT_SRC_DEST).uniq
 
41
 
 
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')
 
46
 
 
47
desc "Clean specifically for the release."
 
48
task :polish => [:clean] do
 
49
  POLISH.each { |fn| rm_r fn rescue nil }
 
50
end
 
51
 
 
52
desc "Run tests with Valgrind"
 
53
task :valgrind do
 
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
 
59
end
 
60
 
 
61
task :default => :test_all
 
62
#task :default => :ext do
 
63
#  sh "ruby test/unit/index/tc_index.rb"
 
64
#end
 
65
 
 
66
desc "Run all tests"
 
67
task :test_all => [ :test_units ]
 
68
 
 
69
desc "Generate API documentation"
 
70
task :doc => [ :appdoc ]
 
71
 
 
72
desc "run unit tests in test/unit"
 
73
Rake::TestTask.new("test_units" => :ext) do |t|
 
74
  t.libs << "test/unit"
 
75
  t.pattern = 'test/unit/t[cs]_*.rb'
 
76
  #t.pattern = 'test/unit/search/tc_index_searcher.rb'
 
77
  t.verbose = true
 
78
end
 
79
 
 
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')
 
94
end
 
95
 
 
96
EXT_SRC.each do |fn|
 
97
  dest_fn = File.join("ext", File.basename(fn))
 
98
  file dest_fn => fn do |t|
 
99
    begin
 
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
 
104
    end
 
105
 
 
106
    if fn =~ /stemmer/
 
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}"})}
 
111
        end
 
112
      end
 
113
      mv dest_fn + ".out", dest_fn
 
114
    end
 
115
  end
 
116
end if File.exists?("../c")
 
117
 
 
118
desc "Build the extension"
 
119
task :ext => ["ext/#{EXT}"] + SRC do
 
120
  rm_f 'ext/mem_pool.*'
 
121
  rm_f 'ext/defines.h'
 
122
end
 
123
 
 
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"
 
127
  cd "ext"
 
128
  if (/mswin/ =~ RUBY_PLATFORM) and ENV['make'].nil?
 
129
    begin
 
130
      sh "nmake"
 
131
    rescue Exception => e
 
132
      puts
 
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 "**********************************************************************"
 
137
      puts
 
138
      raise e
 
139
    end
 
140
  else
 
141
    sh "make"
 
142
  end
 
143
  cd ".."
 
144
end
 
145
 
 
146
file "ext/lang.h" => ["ext/inc/lang.h"] do
 
147
  rm_f "ext/lang.h"
 
148
  cp "ext/inc/lang.h", "ext/lang.h"
 
149
end
 
150
 
 
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"
 
154
end
 
155
 
 
156
file "ext/Makefile" => SRC do
 
157
  cd "ext"
 
158
  `ruby extconf.rb`
 
159
  cd ".."
 
160
end
 
161
 
 
162
# Make Parsers ---------------------------------------------------------------
 
163
 
 
164
RACC_SRC = FileList["lib/**/*.y"]
 
165
RACC_OUT = RACC_SRC.collect { |fn| fn.sub(/\.y$/, '.tab.rb') }
 
166
 
 
167
task :parsers => RACC_OUT
 
168
rule(/\.tab\.rb$/ => [proc {|tn| tn.sub(/\.tab\.rb$/, '.y')}]) do |t|
 
169
  sh "racc #{t.source}" 
 
170
end
 
171
 
 
172
# Create Packages ------------------------------------------------------------
 
173
 
 
174
PKG_FILES = FileList[
 
175
  'setup.rb',
 
176
  '[-A-Z]*',
 
177
  'ext/**/*.[ch]', 
 
178
  'lib/**/*.rb', 
 
179
  'lib/**/*.rhtml', 
 
180
  'lib/**/*.css', 
 
181
  'lib/**/*.js', 
 
182
  'test/**/*.rb',
 
183
  'test/**/wordfile',
 
184
  'rake_utils/**/*.rb',
 
185
  'Rakefile'
 
186
]
 
187
PKG_FILES.exclude('**/*.o')
 
188
PKG_FILES.exclude('**/Makefile')
 
189
PKG_FILES.exclude('ext/ferret_ext.so')
 
190
 
 
191
 
 
192
if ! defined?(Gem)
 
193
  puts "Package Target requires RubyGEMs"
 
194
else
 
195
  spec = Gem::Specification.new do |s|
 
196
    
 
197
    #### Basic information.
 
198
    s.name = 'ferret'
 
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.
 
204
    EOF
 
205
 
 
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'
 
212
    s.bindir = 'bin'
 
213
    s.executables = ['ferret-browser']
 
214
    s.default_executable = 'ferret-browser'
 
215
 
 
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"
 
221
 
 
222
    s.has_rdoc = true
 
223
    s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
 
224
    s.rdoc_options <<
 
225
      '--title' <<  'Ferret -- Ruby Indexer' <<
 
226
      '--main' << 'README' << '--line-numbers' <<
 
227
      'TUTORIAL' << 'TODO'
 
228
 
 
229
    if RUBY_PLATFORM =~ /mswin/
 
230
      s.files = PKG_FILES.to_a + ["ext/#{EXT}"]
 
231
      s.extensions.clear
 
232
      s.platform = Gem::Platform::WIN32
 
233
    end
 
234
  end
 
235
 
 
236
  package_task = Rake::GemPackageTask.new(spec) do |pkg|
 
237
    unless RUBY_PLATFORM =~ /mswin/
 
238
      pkg.need_zip = true
 
239
      pkg.need_tar = true
 
240
    end
 
241
  end
 
242
end
 
243
 
 
244
# Support Tasks ------------------------------------------------------
 
245
 
 
246
desc "Look for TODO and FIXME tags in the code"
 
247
task :todo do
 
248
  FileList['**/*.rb'].egrep /#.*(FIXME|TODO|TBD)/
 
249
end
 
250
# --------------------------------------------------------------------
 
251
# Creating a release
 
252
 
 
253
desc "Make a new release"
 
254
task :release => [
 
255
  :prerelease,
 
256
  :polish,
 
257
  :test_all,
 
258
  :update_version,
 
259
  :package,
 
260
  :tag] do
 
261
  announce 
 
262
  announce "**************************************************************"
 
263
  announce "* Release #{PKG_VERSION} Complete."
 
264
  announce "* Packages ready to upload."
 
265
  announce "**************************************************************"
 
266
  announce 
 
267
end
 
268
 
 
269
# Validate that everything is ready to go for a release.
 
270
task :prerelease do
 
271
  announce 
 
272
  announce "**************************************************************"
 
273
  announce "* Making RubyGem Release #{PKG_VERSION}"
 
274
  announce "* (current version #{CURRENT_VERSION})"
 
275
  announce "**************************************************************"
 
276
  announce  
 
277
 
 
278
  # Is a release number supplied?
 
279
  unless ENV['REL']
 
280
    fail "Usage: rake release REL=x.y.z [REUSE=tag_suffix]"
 
281
  end
 
282
 
 
283
  # Is the release different than the current release.
 
284
  # (or is REUSE set?)
 
285
  if PKG_VERSION == CURRENT_VERSION && ! ENV['REUSE']
 
286
    fail "Current version is #{PKG_VERSION}, must specify REUSE=tag_suffix to reuse version"
 
287
  end
 
288
 
 
289
  # Are all source files checked in?
 
290
  data = `svn -q --ignore-externals status`
 
291
  unless data =~ /^$/
 
292
    fail "'svn -q status' is not clean ... do you have unchecked-in files?"
 
293
  end
 
294
  
 
295
  announce "No outstanding checkins found ... OK"
 
296
end
 
297
 
 
298
def reversion(fn)
 
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}'"
 
304
        else
 
305
          ferret_out.puts line
 
306
        end
 
307
      end
 
308
    end
 
309
  end
 
310
  mv fn + ".new", fn
 
311
end
 
312
 
 
313
task :update_version => [:prerelease] do
 
314
  if PKG_VERSION == CURRENT_VERSION
 
315
    announce "No version change ... skipping version update"
 
316
  else
 
317
    announce "Updating Ferret version to #{PKG_VERSION}"
 
318
    reversion("lib/ferret_version.rb")
 
319
    if ENV['RELTEST']
 
320
      announce "Release Task Testing, skipping commiting of new version"
 
321
    else
 
322
      sh %{svn ci -m "Updated to version #{PKG_VERSION}" lib/ferret_version.rb}
 
323
    end
 
324
  end
 
325
end
 
326
 
 
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}]"
 
332
  if ENV['RELTEST']
 
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}}
 
335
  else
 
336
    sh %{svn copy -m "creating release #{reltag}" svn://www.davebalmain.com/ferret/trunk svn://www.davebalmain.com/ferret/tags/#{reltag}}
 
337
  end
 
338
end