root / tags / 0.5 / Rakefile

Revision 102, 4.9 kB (checked in by why, 22 months ago)
  • Rakefile: generate RDoc with the README at front.
  • README: a bit more initial comments.
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.4" + (REV ? ".#{REV}" : "")
12CLEAN.include ['ext/hpricot_scan/*.{bundle,so,obj,pdb,lib,def,exp}', 'ext/hpricot_scan/Makefile',
13               '**/.*.sw?', '*.gem', '.config']
14RDOC_OPTS = ['--quiet', '--title', 'The Hpricot Reference', '--main', 'README', '--inline-source']
15
16desc "Does a full compile, test run"
17task :default => [:compile, :test]
18
19desc "Compiles all extensions"
20task :compile => [:hpricot_scan] do
21  if Dir.glob(File.join("lib","hpricot_scan.*")).length == 0
22    STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
23    STDERR.puts "Gem actually failed to build.  Your system is"
24    STDERR.puts "NOT configured properly to build hpricot."
25    STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
26    exit(1)
27  end
28end
29task :hpricot_scan => [:ragel]
30
31desc "Packages up Hpricot."
32task :package => [:clean, :ragel]
33
34desc "Releases packages for all Hpricot packages and platforms."
35task :release => [:package, :rubygems_win32]
36
37desc "Run all the tests"
38Rake::TestTask.new do |t|
39    t.libs << "test"
40    t.test_files = FileList['test/test_*.rb']
41    t.verbose = true
42end
43
44Rake::RDocTask.new do |rdoc|
45    rdoc.rdoc_dir = 'doc/rdoc'
46    rdoc.options += RDOC_OPTS
47    rdoc.main = "README"
48    rdoc.rdoc_files.add ['README', 'CHANGELOG', 'COPYING', 'lib/**/*.rb']
49end
50
51spec =
52    Gem::Specification.new do |s|
53        s.name = NAME
54        s.version = VERS
55        s.platform = Gem::Platform::RUBY
56        s.has_rdoc = true
57        s.rdoc_options += RDOC_OPTS
58        s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
59        s.summary = "a swift, liberal HTML parser with a fantastic library"
60        s.description = s.summary
61        s.author = "why the lucky stiff"
62        s.email = 'why@ruby-lang.org'
63        s.homepage = 'http://code.whytheluckystiff.net/hpricot/'
64
65        s.files = %w(COPYING README Rakefile) +
66          Dir.glob("{bin,doc,test,lib,extras}/**/*") +
67          Dir.glob("ext/**/*.{h,c,rb,rl}") +
68          %w[ext/hpricot_scan/hpricot_scan.c] # needed because it's generated later
69       
70        s.require_path = "lib"
71        #s.autorequire = "hpricot"  # no no no this is tHe 3v1l
72        s.extensions = FileList["ext/**/extconf.rb"].to_a
73        s.bindir = "bin"
74    end
75
76Rake::GemPackageTask.new(spec) do |p|
77    p.need_tar = true
78    p.gem_spec = spec
79end
80
81extension = "hpricot_scan"
82ext = "ext/hpricot_scan"
83ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
84ext_files = FileList[
85  "#{ext}/*.c",
86  "#{ext}/*.h",
87  "#{ext}/*.rl",
88  "#{ext}/extconf.rb",
89  "#{ext}/Makefile",
90  "lib"
91]
92
93task "lib" do
94  directory "lib"
95end
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  cp ext_so, "lib"
109end
110
111desc "Generates the scanner code with Ragel."
112task :ragel do
113  sh %{ragel ext/hpricot_scan/hpricot_scan.rl | rlcodegen -G2 -o ext/hpricot_scan/hpricot_scan.c}
114end
115
116PKG_FILES = FileList[
117  "test/**/*.{rb,html,xhtml}",
118  "lib/**/*.rb",
119  "ext/**/*.{c,rb,h,rl}",
120  "CHANGELOG", "README", "Rakefile", "COPYING",
121  "extras/**/*", "lib/hpricot_scan.so"]
122
123Win32Spec = Gem::Specification.new do |s|
124  s.name = NAME
125  s.version = VERS
126  s.platform = Gem::Platform::WIN32
127  s.has_rdoc = false
128  s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
129  s.summary = "a swift, liberal HTML parser with a fantastic library"
130  s.description = s.summary
131  s.author = "why the lucky stiff"
132  s.email = 'why@ruby-lang.org'
133  s.homepage = 'http://code.whytheluckystiff.net/hpricot/'
134
135  s.files = PKG_FILES
136
137  s.require_path = "lib"
138  #s.autorequire = "hpricot"  # no no no this is tHe 3v1l
139  s.extensions = []
140  s.bindir = "bin"
141end
142 
143WIN32_PKG_DIR = "hpricot-" + VERS
144
145file WIN32_PKG_DIR => [:package] do
146  sh "tar zxf pkg/#{WIN32_PKG_DIR}.tgz"
147end
148
149desc "Cross-compile the hpricot_scan extension for win32"
150file "hpricot_scan_win32" => [WIN32_PKG_DIR] do
151  cp "extras/mingw-rbconfig.rb", "#{WIN32_PKG_DIR}/ext/hpricot_scan/rbconfig.rb"
152  sh "cd #{WIN32_PKG_DIR}/ext/hpricot_scan/ && ruby -I. extconf.rb && make"
153  mv "#{WIN32_PKG_DIR}/ext/hpricot_scan/hpricot_scan.so", "#{WIN32_PKG_DIR}/lib"
154end
155
156desc "Build the binary RubyGems package for win32"
157task :rubygems_win32 => ["hpricot_scan_win32"] do
158  Dir.chdir("#{WIN32_PKG_DIR}") do
159    Gem::Builder.new(Win32Spec).build
160    verbose(true) {
161      mv Dir["*.gem"].first, "../pkg/hpricot-#{VERS}-mswin32.gem"
162    }
163  end
164end
165
166CLEAN.include WIN32_PKG_DIR
167
168task :install do
169  sh %{rake package}
170  sh %{sudo gem install pkg/#{NAME}-#{VERS}}
171end
172
173task :uninstall => [:clean] do
174  sh %{sudo gem uninstall #{NAME}}
175end
Note: See TracBrowser for help on using the browser.