Changeset 109

Show
Ignore:
Timestamp:
02/06/2007 00:26:58 (22 months ago)
Author:
why
Message:
  • ext/hpricot_scan/hpricot_scan.java.rl: check this out! ola bini contributed a scanner that generates Java and IT WORKS.
  • Rakefile: now producing hpricot-0.5-jruby.gem, sooo slickkkk.
Location:
trunk
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Rakefile

    r102 r109  
    1010REV = `svn info`[/Revision: (\d+)/, 1] rescue nil 
    1111VERS = ENV['VERSION'] || "0.4" + (REV ? ".#{REV}" : "") 
    12 CLEAN.include ['ext/hpricot_scan/*.{bundle,so,obj,pdb,lib,def,exp}', 'ext/hpricot_scan/Makefile',  
     12PKG = "#{NAME}-#{VERS}" 
     13BIN = "*.{bundle,jar,so,obj,pdb,lib,def,exp}" 
     14CLEAN.include ["ext/hpricot_scan/#{BIN}", "lib/#{BIN}", 'ext/hpricot_scan/Makefile',  
    1315               '**/.*.sw?', '*.gem', '.config'] 
    1416RDOC_OPTS = ['--quiet', '--title', 'The Hpricot Reference', '--main', 'README', '--inline-source'] 
     17PKG_FILES = %w(CHANGELOG COPYING README Rakefile) + 
     18      Dir.glob("{bin,doc,test,lib,extras}/**/*") +  
     19      Dir.glob("ext/**/*.{h,java,c,rb,rl}") +  
     20      %w[ext/hpricot_scan/hpricot_scan.c] # needed because it's generated later 
     21SPEC = 
     22  Gem::Specification.new do |s| 
     23    s.name = NAME 
     24    s.version = VERS 
     25    s.platform = Gem::Platform::RUBY 
     26    s.has_rdoc = true 
     27    s.rdoc_options += RDOC_OPTS 
     28    s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"] 
     29    s.summary = "a swift, liberal HTML parser with a fantastic library" 
     30    s.description = s.summary 
     31    s.author = "why the lucky stiff" 
     32    s.email = 'why@ruby-lang.org' 
     33    s.homepage = 'http://code.whytheluckystiff.net/hpricot/' 
     34    s.files = PKG_FILES 
     35    s.require_path = "lib" 
     36    s.extensions = FileList["ext/**/extconf.rb"].to_a 
     37    s.bindir = "bin" 
     38  end 
    1539 
    1640desc "Does a full compile, test run" 
    1741task :default => [:compile, :test] 
    1842 
    19 desc "Compiles all extensions" 
    20 task :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 
    28 end 
    29 task :hpricot_scan => [:ragel] 
    30  
    3143desc "Packages up Hpricot." 
    3244task :package => [:clean, :ragel] 
    3345 
    3446desc "Releases packages for all Hpricot packages and platforms." 
    35 task :release => [:package, :rubygems_win32] 
     47task :release => [:package, :package_win32, :package_jruby] 
    3648 
    3749desc "Run all the tests" 
     
    4961end 
    5062 
    51 spec = 
    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  
    76 Rake::GemPackageTask.new(spec) do |p| 
     63Rake::GemPackageTask.new(SPEC) do |p| 
    7764    p.need_tar = true 
    78     p.gem_spec = spec 
     65    p.gem_spec = SPEC 
    7966end 
    8067 
     
    9582end 
    9683 
     84desc "Compiles the Ruby extension" 
     85task :compile => [:hpricot_scan] do 
     86  if Dir.glob(File.join("lib","hpricot_scan.*")).length == 0 
     87    STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 
     88    STDERR.puts "Gem actually failed to build.  Your system is" 
     89    STDERR.puts "NOT configured properly to build hpricot." 
     90    STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 
     91    exit(1) 
     92  end 
     93end 
     94task :hpricot_scan => [:ragel] 
     95 
    9796desc "Builds just the #{extension} extension" 
    9897task extension.to_sym => ["#{ext}/Makefile", ext_so ] 
     
    109108end 
    110109 
    111 desc "Generates the scanner code with Ragel." 
     110desc "Generates the C scanner code with Ragel." 
    112111task :ragel do 
    113112  sh %{ragel ext/hpricot_scan/hpricot_scan.rl | rlcodegen -G2 -o ext/hpricot_scan/hpricot_scan.c} 
    114113end 
    115114 
    116 PKG_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  
    123 Win32Spec = 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" 
    141 end 
     115desc "Generates the Java scanner code with Ragel." 
     116task :ragel_java do 
     117  sh %{ragel -J ext/hpricot_scan/hpricot_scan.java.rl | rlcodegen -o  ext/hpricot_scan/HpricotScanService.java} 
     118end 
     119 
     120### Win32 Packages ### 
     121 
     122Win32Spec = SPEC.dup 
     123Win32Spec.platform = Gem::Platform::WIN32 
     124Win32Spec.files = PKG_FILES + ['lib/hpricot_scan.so'] 
     125Win32Spec.extensions = [] 
    142126   
    143 WIN32_PKG_DIR = "hpricot-" + VERS 
    144  
     127WIN32_PKG_DIR = "#{PKG}-win32" 
     128 
     129desc "Package up the Win32 distribution." 
    145130file WIN32_PKG_DIR => [:package] do 
    146   sh "tar zxf pkg/#{WIN32_PKG_DIR}.tgz" 
     131  sh "tar zxf pkg/#{PKG}.tgz" 
     132  mv PKG, WIN32_PKG_DIR 
    147133end 
    148134 
     
    155141 
    156142desc "Build the binary RubyGems package for win32" 
    157 task :rubygems_win32 => ["hpricot_scan_win32"] do 
     143task :package_win32 => ["hpricot_scan_win32"] do 
    158144  Dir.chdir("#{WIN32_PKG_DIR}") do 
    159145    Gem::Builder.new(Win32Spec).build 
    160146    verbose(true) { 
    161       mv Dir["*.gem"].first, "../pkg/hpricot-#{VERS}-mswin32.gem" 
     147      mv Dir["*.gem"].first, "../pkg/#{WIN32_PKG_DIR}.gem" 
    162148    } 
    163149  end 
     
    165151 
    166152CLEAN.include WIN32_PKG_DIR 
     153 
     154### JRuby Packages ### 
     155 
     156compile_java = proc do 
     157  sh %{javac -classpath $JRUBY_HOME/lib/jruby.jar HpricotScanService.java} 
     158  sh %{jar cf hpricot_scan.jar HpricotScanService.class} 
     159end 
     160 
     161desc "Compiles the JRuby extension" 
     162task :hpricot_scan_java => [:ragel_java] do 
     163  Dir.chdir("ext/hpricot_scan", &compile_java) 
     164end 
     165 
     166JRubySpec = SPEC.dup 
     167JRubySpec.platform = Gem::Platform::RUBY 
     168JRubySpec.files = PKG_FILES + ['lib/hpricot_scan.jar'] 
     169JRubySpec.extensions = [] 
     170 
     171JRUBY_PKG_DIR = "#{PKG}-jruby" 
     172 
     173desc "Package up the JRuby distribution." 
     174file JRUBY_PKG_DIR => [:ragel_java, :package] do 
     175  sh "tar zxf pkg/#{PKG}.tgz" 
     176  mv PKG, JRUBY_PKG_DIR 
     177end 
     178 
     179desc "Cross-compile the hpricot_scan extension for JRuby" 
     180file "hpricot_scan_jruby" => [JRUBY_PKG_DIR] do 
     181  Dir.chdir("#{JRUBY_PKG_DIR}/ext/hpricot_scan", &compile_java) 
     182  mv "#{JRUBY_PKG_DIR}/ext/hpricot_scan/hpricot_scan.jar", "#{JRUBY_PKG_DIR}/lib" 
     183end 
     184 
     185desc "Build the RubyGems package for JRuby" 
     186task :package_jruby => ["hpricot_scan_jruby"] do 
     187  Dir.chdir("#{JRUBY_PKG_DIR}") do 
     188    Gem::Builder.new(JRubySpec).build 
     189    verbose(true) { 
     190      mv Dir["*.gem"].first, "../pkg/#{JRUBY_PKG_DIR}.gem" 
     191    } 
     192  end 
     193end 
     194 
     195CLEAN.include JRUBY_PKG_DIR 
    167196 
    168197task :install do