| 1 | require 'rake' |
|---|
| 2 | require 'rake/clean' |
|---|
| 3 | require 'rake/gempackagetask' |
|---|
| 4 | require 'rake/rdoctask' |
|---|
| 5 | require 'rake/testtask' |
|---|
| 6 | require 'fileutils' |
|---|
| 7 | include FileUtils |
|---|
| 8 | |
|---|
| 9 | NAME = "hpricot" |
|---|
| 10 | REV = File.read(".svn/entries")[/committed-rev="(\d+)"/, 1] rescue nil |
|---|
| 11 | VERS = "0.3" + (REV ? ".#{REV}" : "") |
|---|
| 12 | CLEAN.include ['ext/hpricot_scan/*.{bundle,so,obj,pdb,lib,def,exp}', 'ext/hpricot_scan/Makefile', |
|---|
| 13 | '**/.*.sw?', '*.gem', '.config'] |
|---|
| 14 | |
|---|
| 15 | desc "Does a full compile, test run" |
|---|
| 16 | task :default => [:compile, :test] |
|---|
| 17 | |
|---|
| 18 | desc "Compiles all extensions" |
|---|
| 19 | task :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 |
|---|
| 27 | end |
|---|
| 28 | task :hpricot_scan => [:ragel] |
|---|
| 29 | |
|---|
| 30 | desc "Packages up Hpricot." |
|---|
| 31 | task :package => [:clean, :ragel] |
|---|
| 32 | |
|---|
| 33 | desc "Run all the tests" |
|---|
| 34 | Rake::TestTask.new do |t| |
|---|
| 35 | t.libs << "test" |
|---|
| 36 | t.test_files = FileList['test/test_*.rb'] |
|---|
| 37 | t.verbose = true |
|---|
| 38 | end |
|---|
| 39 | |
|---|
| 40 | spec = |
|---|
| 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 | |
|---|
| 64 | Rake::GemPackageTask.new(spec) do |p| |
|---|
| 65 | p.need_tar = true |
|---|
| 66 | p.gem_spec = spec |
|---|
| 67 | end |
|---|
| 68 | |
|---|
| 69 | extension = "hpricot_scan" |
|---|
| 70 | ext = "ext/hpricot_scan" |
|---|
| 71 | ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}" |
|---|
| 72 | ext_files = FileList[ |
|---|
| 73 | "#{ext}/*.c", |
|---|
| 74 | "#{ext}/*.h", |
|---|
| 75 | "#{ext}/*.rl", |
|---|
| 76 | "#{ext}/extconf.rb", |
|---|
| 77 | "#{ext}/Makefile", |
|---|
| 78 | "lib" |
|---|
| 79 | ] |
|---|
| 80 | |
|---|
| 81 | task "lib" do |
|---|
| 82 | directory "lib" |
|---|
| 83 | end |
|---|
| 84 | |
|---|
| 85 | desc "Builds just the #{extension} extension" |
|---|
| 86 | task extension.to_sym => ["#{ext}/Makefile", ext_so ] |
|---|
| 87 | |
|---|
| 88 | file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do |
|---|
| 89 | Dir.chdir(ext) do ruby "extconf.rb" end |
|---|
| 90 | end |
|---|
| 91 | |
|---|
| 92 | file ext_so => ext_files do |
|---|
| 93 | Dir.chdir(ext) do |
|---|
| 94 | sh(PLATFORM =~ /win32/ ? 'nmake' : 'make') |
|---|
| 95 | end |
|---|
| 96 | cp ext_so, "lib" |
|---|
| 97 | end |
|---|
| 98 | |
|---|
| 99 | desc "Generates the scanner code with Ragel." |
|---|
| 100 | task :ragel do |
|---|
| 101 | sh %{ragel ext/hpricot_scan/hpricot_scan.rl | rlcodegen -G2 -o ext/hpricot_scan/hpricot_scan.c} |
|---|
| 102 | end |
|---|
| 103 | |
|---|
| 104 | PKG_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 | |
|---|
| 111 | Win32Spec = 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" |
|---|
| 129 | end |
|---|
| 130 | |
|---|
| 131 | WIN32_PKG_DIR = "hpricot-" + VERS |
|---|
| 132 | |
|---|
| 133 | file WIN32_PKG_DIR => [:package] do |
|---|
| 134 | sh "tar zxf pkg/#{WIN32_PKG_DIR}.tgz" |
|---|
| 135 | end |
|---|
| 136 | |
|---|
| 137 | desc "Cross-compile the hpricot_scan extension for win32" |
|---|
| 138 | file "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" |
|---|
| 142 | end |
|---|
| 143 | |
|---|
| 144 | desc "Build the binary RubyGems package for win32" |
|---|
| 145 | task :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 |
|---|
| 152 | end |
|---|
| 153 | |
|---|
| 154 | CLEAN.include WIN32_PKG_DIR |
|---|
| 155 | |
|---|
| 156 | task :install do |
|---|
| 157 | sh %{rake package} |
|---|
| 158 | sh %{sudo gem install pkg/#{NAME}-#{VERS}} |
|---|
| 159 | end |
|---|
| 160 | |
|---|
| 161 | task :uninstall => [:clean] do |
|---|
| 162 | sh %{sudo gem uninstall #{NAME}} |
|---|
| 163 | end |
|---|