root / tags / 0.4 / Rakefile

Revision 30, 4.5 kB (checked in by why, 2 years ago)
  • Rakefile: make gems off the REVISION number by default.
  • lib/hpricot/tag.rb: make sure the script tag (and other PCDATA wrappers) don't get output as empty elements.
Line 
1require 'rake'
2require 'rake/clean'
3require 'rake/gempackagetask'
4require 'rake/rdoctask'
5require 'rake/testtask'
6require 'fileutils'
7include FileUtils
8
9NAME = "hpricot"
10REV = File.read(".svn/entries")[/committed-rev="(\d+)"/, 1] rescue nil
11VERS = "0.3" + (REV ? ".#{REV}" : "")
12CLEAN.include ['ext/hpricot_scan/*.{bundle,so,obj,pdb,lib,def,exp}', 'ext/hpricot_scan/Makefile',
13               '**/.*.sw?', '*.gem', '.config']
14
15desc "Does a full compile, test run"
16task :default => [:compile, :test]
17
18desc "Compiles all extensions"
19task :compile => [:hpricot_scan] do
20  if Dir.glob(File.join("lib","hpricot_scan.*")).length == 0
21    STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
22    STDERR.puts "Gem actually failed to build.  Your system is"
23    STDERR.puts "NOT configured properly to build hpricot."
24    STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
25    exit(1)
26  end
27end
28task :hpricot_scan => [:ragel]
29
30desc "Packages up Hpricot."
31task :package => [:clean, :ragel]
32
33desc "Run all the tests"
34Rake::TestTask.new do |t|
35    t.libs << "test"
36    t.test_files = FileList['test/test_*.rb']
37    t.verbose = true
38end
39
40spec =
41    Gem::Specification.new do |s|
42        s.name = NAME
43        s.version = VERS
44        s.platform = Gem::Platform::RUBY
45        s.has_rdoc = false
46        s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
47        s.summary = "a swift, liberal HTML parser with a fantastic library"
48        s.description = s.summary
49        s.author = "why the lucky stiff"
50        s.email = 'why@ruby-lang.org'
51        s.homepage = 'http://code.whytheluckystiff.net/hpricot/'
52
53        s.files = %w(COPYING README Rakefile) +
54          Dir.glob("{bin,doc,test,lib,extras}/**/*") +
55          Dir.glob("ext/**/*.{h,c,rb,rl}") +
56          %w[ext/hpricot_scan/hpricot_scan.c] # needed because it's generated later
57       
58        s.require_path = "lib"
59        #s.autorequire = "hpricot"  # no no no this is tHe 3v1l
60        s.extensions = FileList["ext/**/extconf.rb"].to_a
61        s.bindir = "bin"
62    end
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 "Builds just the #{extension} extension"
86task extension.to_sym => ["#{ext}/Makefile", ext_so ]
87
88file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
89  Dir.chdir(ext) do ruby "extconf.rb" end
90end
91
92file ext_so => ext_files do
93  Dir.chdir(ext) do
94    sh(PLATFORM =~ /win32/ ? 'nmake' : 'make')
95  end
96  cp ext_so, "lib"
97end
98
99desc "Generates the scanner code with Ragel."
100task :ragel do
101  sh %{ragel ext/hpricot_scan/hpricot_scan.rl | rlcodegen -G2 -o ext/hpricot_scan/hpricot_scan.c}
102end
103
104PKG_FILES = FileList[
105  "test/**/*.{rb,html,xhtml}",
106  "lib/**/*.rb",
107  "ext/**/*.{c,rb,h,rl}",
108  "CHANGELOG", "README", "Rakefile", "COPYING",
109  "extras/**/*", "lib/hpricot_scan.so"]
110
111Win32Spec = Gem::Specification.new do |s|
112  s.name = NAME
113  s.version = VERS
114  s.platform = Gem::Platform::WIN32
115  s.has_rdoc = false
116  s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
117  s.summary = "a swift, liberal HTML parser with a fantastic library"
118  s.description = s.summary
119  s.author = "why the lucky stiff"
120  s.email = 'why@ruby-lang.org'
121  s.homepage = 'http://code.whytheluckystiff.net/hpricot/'
122
123  s.files = PKG_FILES
124
125  s.require_path = "lib"
126  #s.autorequire = "hpricot"  # no no no this is tHe 3v1l
127  s.extensions = []
128  s.bindir = "bin"
129end
130 
131WIN32_PKG_DIR = "hpricot-" + VERS
132
133file WIN32_PKG_DIR => [:package] do
134  sh "tar zxf pkg/#{WIN32_PKG_DIR}.tgz"
135end
136
137desc "Cross-compile the hpricot_scan extension for win32"
138file "hpricot_scan_win32" => [WIN32_PKG_DIR] do
139  cp "extras/mingw-rbconfig.rb", "#{WIN32_PKG_DIR}/ext/hpricot_scan/rbconfig.rb"
140  sh "cd #{WIN32_PKG_DIR}/ext/hpricot_scan/ && ruby -I. extconf.rb && make"
141  mv "#{WIN32_PKG_DIR}/ext/hpricot_scan/hpricot_scan.so", "#{WIN32_PKG_DIR}/lib"
142end
143
144desc "Build the binary RubyGems package for win32"
145task :rubygems_win32 => ["hpricot_scan_win32"] do
146  Dir.chdir("#{WIN32_PKG_DIR}") do
147    Gem::Builder.new(Win32Spec).build
148    verbose(true) {
149      mv Dir["*.gem"].first, "../pkg/hpricot-#{VERS}-mswin32.gem"
150    }
151  end
152end
153
154CLEAN.include WIN32_PKG_DIR
155
156task :install do
157  sh %{rake package}
158  sh %{sudo gem install pkg/#{NAME}-#{VERS}}
159end
160
161task :uninstall => [:clean] do
162  sh %{sudo gem uninstall #{NAME}}
163end
Note: See TracBrowser for help on using the browser.