root / tags / 0.6 / Rakefile

Revision 152, 6.0 kB (checked in by why, 18 months ago)

* Rakefile: prepping for 0.6 release.

Line 
1require 'rake'
2require 'rake/clean'
3require 'rake/gempackagetask'
4require 'rake/rdoctask'
5require 'rake/testtask'
6require 'fileutils'
7include FileUtils
8
9NAME = "hpricot"
10REV = `svn info`[/Revision: (\d+)/, 1] rescue nil
11VERS = ENV['VERSION'] || "0.6" + (REV ? ".#{REV}" : "")
12PKG = "#{NAME}-#{VERS}"
13BIN = "*.{bundle,jar,so,obj,pdb,lib,def,exp}"
14ARCHLIB = "lib/#{::Config::CONFIG['arch']}"
15CLEAN.include ["ext/hpricot_scan/#{BIN}", "lib/**/#{BIN}", 'ext/hpricot_scan/Makefile',
16               '**/.*.sw?', '*.gem', '.config']
17RDOC_OPTS = ['--quiet', '--title', 'The Hpricot Reference', '--main', 'README', '--inline-source']
18PKG_FILES = %w(CHANGELOG COPYING README Rakefile) +
19      Dir.glob("{bin,doc,test,lib,extras}/**/*") +
20      Dir.glob("ext/**/*.{h,java,c,rb,rl}") +
21      %w[ext/hpricot_scan/hpricot_scan.c] # needed because it's generated later
22SPEC =
23  Gem::Specification.new do |s|
24    s.name = NAME
25    s.version = VERS
26    s.platform = Gem::Platform::RUBY
27    s.has_rdoc = true
28    s.rdoc_options += RDOC_OPTS
29    s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
30    s.summary = "a swift, liberal HTML parser with a fantastic library"
31    s.description = s.summary
32    s.author = "why the lucky stiff"
33    s.email = 'why@ruby-lang.org'
34    s.homepage = 'http://code.whytheluckystiff.net/hpricot/'
35    s.files = PKG_FILES
36    s.require_paths = [ARCHLIB, "lib"]
37    s.extensions = FileList["ext/**/extconf.rb"].to_a
38    s.bindir = "bin"
39  end
40
41desc "Does a full compile, test run"
42task :default => [:compile, :test]
43
44desc "Packages up Hpricot."
45task :package => [:clean, :ragel]
46
47desc "Releases packages for all Hpricot packages and platforms."
48task :release => [:package, :package_win32, :package_jruby]
49
50desc "Run all the tests"
51Rake::TestTask.new do |t|
52    t.libs << "test" << ARCHLIB
53    t.test_files = FileList['test/test_*.rb']
54    t.verbose = true
55end
56
57Rake::RDocTask.new do |rdoc|
58    rdoc.rdoc_dir = 'doc/rdoc'
59    rdoc.options += RDOC_OPTS
60    rdoc.main = "README"
61    rdoc.rdoc_files.add ['README', 'CHANGELOG', 'COPYING', 'lib/**/*.rb']
62end
63
64Rake::GemPackageTask.new(SPEC) do |p|
65    p.need_tar = true
66    p.gem_spec = SPEC
67end
68
69extension = "hpricot_scan"
70ext = "ext/hpricot_scan"
71ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
72ext_files = FileList[
73  "#{ext}/*.c",
74  "#{ext}/*.h",
75  "#{ext}/*.rl",
76  "#{ext}/extconf.rb",
77  "#{ext}/Makefile",
78  "lib"
79]
80
81task "lib" do
82  directory "lib"
83end
84
85desc "Compiles the Ruby extension"
86task :compile => [:hpricot_scan] do
87  if Dir.glob(File.join(ARCHLIB,"hpricot_scan.*")).length == 0
88    STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
89    STDERR.puts "Gem actually failed to build.  Your system is"
90    STDERR.puts "NOT configured properly to build hpricot."
91    STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
92    exit(1)
93  end
94end
95task :hpricot_scan => [:ragel]
96
97desc "Builds just the #{extension} extension"
98task extension.to_sym => ["#{ext}/Makefile", ext_so ]
99
100file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
101  Dir.chdir(ext) do ruby "extconf.rb" end
102end
103
104file ext_so => ext_files do
105  Dir.chdir(ext) do
106    sh(PLATFORM =~ /win32/ ? 'nmake' : 'make')
107  end
108  mkdir_p ARCHLIB
109  cp ext_so, ARCHLIB
110end
111
112desc "returns the ragel version"
113task :ragel_version do
114  @ragel_v = `ragel -v`[/(version )(\S*)/,2].to_f
115end
116
117desc "Generates the C scanner code with Ragel."
118task :ragel => [:ragel_version] do
119  sh %{ragel ext/hpricot_scan/hpricot_scan.rl | #{@ragel_v >= 5.18 ? 'rlgen-cd' : 'rlcodegen'} -G2 -o ext/hpricot_scan/hpricot_scan.c}
120end
121
122desc "Generates the Java scanner code with Ragel."
123task :ragel_java => [:ragel_version] do
124  sh %{ragel -J ext/hpricot_scan/hpricot_scan.java.rl | #{@ragel_v >= 5.18 ? 'rlgen-java' : 'rlcodegen'} -o  ext/hpricot_scan/HpricotScanService.java}
125end
126
127### Win32 Packages ###
128
129Win32Spec = SPEC.dup
130Win32Spec.platform = Gem::Platform::WIN32
131Win32Spec.files = PKG_FILES + ["#{ARCHLIB}/hpricot_scan.so"]
132Win32Spec.extensions = []
133 
134WIN32_PKG_DIR = "#{PKG}-mswin32"
135
136desc "Package up the Win32 distribution."
137file WIN32_PKG_DIR => [:package] do
138  sh "tar zxf pkg/#{PKG}.tgz"
139  mv PKG, WIN32_PKG_DIR
140end
141
142desc "Cross-compile the hpricot_scan extension for win32"
143file "hpricot_scan_win32" => [WIN32_PKG_DIR] do
144  cp "extras/mingw-rbconfig.rb", "#{WIN32_PKG_DIR}/ext/hpricot_scan/rbconfig.rb"
145  sh "cd #{WIN32_PKG_DIR}/ext/hpricot_scan/ && ruby -I. extconf.rb && make"
146  mv "#{WIN32_PKG_DIR}/ext/hpricot_scan/hpricot_scan.so", "#{WIN32_PKG_DIR}/#{ARCHLIB}"
147end
148
149desc "Build the binary RubyGems package for win32"
150task :package_win32 => ["hpricot_scan_win32"] do
151  Dir.chdir("#{WIN32_PKG_DIR}") do
152    Gem::Builder.new(Win32Spec).build
153    verbose(true) {
154      mv Dir["*.gem"].first, "../pkg/#{WIN32_PKG_DIR}.gem"
155    }
156  end
157end
158
159CLEAN.include WIN32_PKG_DIR
160
161### JRuby Packages ###
162
163compile_java = proc do
164  sh %{javac -source 1.4 -target 1.4 -classpath $JRUBY_HOME/lib/jruby.jar HpricotScanService.java}
165  sh %{jar cf hpricot_scan.jar HpricotScanService.class}
166end
167
168desc "Compiles the JRuby extension"
169task :hpricot_scan_java => [:ragel_java] do
170  Dir.chdir("ext/hpricot_scan", &compile_java)
171end
172
173JRubySpec = SPEC.dup
174JRubySpec.platform = 'jruby'
175JRubySpec.files = PKG_FILES + ["#{ARCHLIB}/hpricot_scan.jar"]
176JRubySpec.extensions = []
177
178JRUBY_PKG_DIR = "#{PKG}-jruby"
179
180desc "Package up the JRuby distribution."
181file JRUBY_PKG_DIR => [:ragel_java, :package] do
182  sh "tar zxf pkg/#{PKG}.tgz"
183  mv PKG, JRUBY_PKG_DIR
184end
185
186desc "Cross-compile the hpricot_scan extension for JRuby"
187file "hpricot_scan_jruby" => [JRUBY_PKG_DIR] do
188  Dir.chdir("#{JRUBY_PKG_DIR}/ext/hpricot_scan", &compile_java)
189  mv "#{JRUBY_PKG_DIR}/ext/hpricot_scan/hpricot_scan.jar", "#{JRUBY_PKG_DIR}/#{ARCHLIB}"
190end
191
192desc "Build the RubyGems package for JRuby"
193task :package_jruby => ["hpricot_scan_jruby"] do
194  Dir.chdir("#{JRUBY_PKG_DIR}") do
195    Gem::Builder.new(JRubySpec).build
196    verbose(true) {
197      mv Dir["*.gem"].first, "../pkg/#{JRUBY_PKG_DIR}.gem"
198    }
199  end
200end
201
202CLEAN.include JRUBY_PKG_DIR
203
204task :install do
205  sh %{rake package}
206  sh %{sudo gem install pkg/#{NAME}-#{VERS}}
207end
208
209task :uninstall => [:clean] do
210  sh %{sudo gem uninstall #{NAME}}
211end
Note: See TracBrowser for help on using the browser.