From 9d4f025692e1668d6566725ecc91ec9d0036f9e9 Mon Sep 17 00:00:00 2001 From: macournoyer Date: Sat, 5 Sep 2009 20:35:30 -0400 Subject: [PATCH] Replace custom extension tasks w/ rake-compiler --- Rakefile | 14 +++++++++++++- tasks/deploy.rake | 7 ++----- tasks/ext.rake | 42 ------------------------------------------ tasks/gem.rake | 42 ++++++++---------------------------------- 4 files changed, 23 insertions(+), 82 deletions(-) delete mode 100644 tasks/ext.rake diff --git a/Rakefile b/Rakefile index 8dee7698..88aa9c97 100644 --- a/Rakefile +++ b/Rakefile @@ -4,12 +4,24 @@ SUDO = (WIN ? "" : "sudo") require 'rake' require 'rake/clean' +require 'rake/extensiontask' # from rake-compiler gem $: << File.join(File.dirname(__FILE__), 'lib') require 'thin' +# Load tasks in tasks/ Dir['tasks/**/*.rake'].each { |rake| load rake } task :default => :spec -ext_task :thin_parser \ No newline at end of file +Rake::ExtensionTask.new('thin_parser', Thin::GemSpec) + +desc "Compile the Ragel state machines" +task :ragel do + Dir.chdir 'ext/thin_parser' do + target = "parser.c" + File.unlink target if File.exist? target + sh "ragel parser.rl | rlgen-cd -G2 -o #{target}" + raise "Failed to compile Ragel state machine" unless File.exist? target + end +end diff --git a/tasks/deploy.rake b/tasks/deploy.rake index 70cd7f85..68da6d6c 100644 --- a/tasks/deploy.rake +++ b/tasks/deploy.rake @@ -1,14 +1,11 @@ namespace :deploy do task :site => %w(site:upload rdoc:upload) - desc 'Deploy on code.macournoyer.com' - task :alpha => %w(gem:upload deploy:site) - desc 'Deploy on rubyforge' - task :public => %w(gem:upload_rubyforge deploy:site) + task :gem => %w(gem:upload_rubyforge deploy:site) end desc 'Deploy on all servers' -task :deploy => %w(deploy:alpha deploy:public) +task :deploy => "deploy:gem" def upload(file, to, options={}) sh %{ssh macournoyer@code.macournoyer.com "rm -rf code.macournoyer.com/#{to}"} if options[:replace] diff --git a/tasks/ext.rake b/tasks/ext.rake deleted file mode 100644 index 3c03e832..00000000 --- a/tasks/ext.rake +++ /dev/null @@ -1,42 +0,0 @@ -CLEAN.include %w(**/*.{o,bundle,jar,so,obj,pdb,lib,def,exp,log} ext/*/Makefile ext/*/conftest.dSYM) - -def ext_task(name) - ext_dir = "ext/#{name}" - ext_bundle = "#{ext_dir}/#{name}.#{Config::CONFIG['DLEXT']}" - ext_files = FileList[ - "#{ext_dir}/*.c", - "#{ext_dir}/*.h", - "#{ext_dir}/*.rl", - "#{ext_dir}/extconf.rb", - "#{ext_dir}/Makefile", - "lib" - ] - - task "compile:#{name}" => ["#{ext_dir}/Makefile", ext_bundle] - task :compile => "compile:#{name}" - - file "#{ext_dir}/Makefile" => ["#{ext_dir}/extconf.rb"] do - cd(ext_dir) { ruby "extconf.rb" } - end - - file ext_bundle => ext_files do - cd ext_dir do - sh(WIN ? 'nmake' : 'make') - end - cp ext_bundle, 'lib/' - end -end - -desc "Compile the Ragel state machines" -task :ragel do - Dir.chdir 'ext/thin_parser' do - target = "parser.c" - File.unlink target if File.exist? target - sh "ragel parser.rl | rlgen-cd -G2 -o #{target}" - raise "Failed to compile Ragel state machine" unless File.exist? target - end -end - -desc "Compile the extensions" -task :compile -task :package => :compile diff --git a/tasks/gem.rake b/tasks/gem.rake index a42f21ad..479d6c68 100644 --- a/tasks/gem.rake +++ b/tasks/gem.rake @@ -5,7 +5,7 @@ WIN_SUFFIX = ENV['WIN_SUFFIX'] || 'i386-mswin32' task :clean => :clobber_package -spec = Gem::Specification.new do |s| +Thin::GemSpec = Gem::Specification.new do |s| s.name = Thin::NAME s.version = Thin::VERSION::STRING s.platform = WIN ? Gem::Platform::CURRENT : Gem::Platform::RUBY @@ -40,8 +40,8 @@ spec = Gem::Specification.new do |s| s.bindir = "bin" end -Rake::GemPackageTask.new(spec) do |p| - p.gem_spec = spec +Rake::GemPackageTask.new(Thin::GemSpec) do |p| + p.gem_spec = Thin::GemSpec end task :tag_warn do @@ -61,48 +61,22 @@ task :gem => :tag_warn namespace :gem do desc "Update the gemspec for GitHub's gem server" task :github do - File.open("thin.gemspec", 'w') { |f| f << YAML.dump(spec) } - end - - desc 'Upload gem to code.macournoyer.com' - task :upload => :gem do - upload "pkg/#{spec.full_name}.gem", 'gems' - system 'ssh macournoyer@code.macournoyer.com "cd code.macournoyer.com && gem generate_index"' + File.open("thin.gemspec", 'w') { |f| f << YAML.dump(Thin::GemSpec) } end namespace :upload do desc 'Upload the precompiled win32 gem to code.macournoyer.com' task :win do - upload "pkg/#{spec.full_name}-#{WIN_SUFFIX}.gem", 'gems' + upload "pkg/#{Thin::GemSpec.full_name}-#{WIN_SUFFIX}.gem", 'gems' system 'ssh macournoyer@code.macournoyer.com "cd code.macournoyer.com && gem generate_index"' end desc 'Upload gems (ruby & win32) to rubyforge.org' task :rubyforge => :gem do sh 'rubyforge login' - sh "rubyforge add_release thin thin #{Thin::VERSION::STRING} pkg/#{spec.full_name}.gem" - sh "rubyforge add_file thin thin #{Thin::VERSION::STRING} pkg/#{spec.full_name}.gem" - sh "rubyforge add_file thin thin #{Thin::VERSION::STRING} pkg/#{spec.full_name}-#{WIN_SUFFIX}.gem" - end - end - - desc 'Download the Windows gem from Kevin repo' - task 'download:win' => 'pkg' do - cd 'pkg' do - `wget http://rubygems.bantamtech.com/ruby18/gems/#{spec.full_name}-#{WIN_SUFFIX}.gem` + sh "rubyforge add_release thin thin #{Thin::VERSION::STRING} pkg/#{Thin::GemSpec.full_name}.gem" + sh "rubyforge add_file thin thin #{Thin::VERSION::STRING} pkg/#{Thin::GemSpec.full_name}.gem" + sh "rubyforge add_file thin thin #{Thin::VERSION::STRING} pkg/#{Thin::GemSpec.full_name}-#{WIN_SUFFIX}.gem" end end end - -task :install => [:clobber, :compile, :package] do - sh "#{SUDO} #{gem} install pkg/#{spec.full_name}.gem" -end - -task :uninstall => :clean do - sh "#{SUDO} #{gem} uninstall -v #{Thin::VERSION::STRING} -x #{Thin::NAME}" -end - - -def gem - RUBY_1_9 ? 'gem19' : 'gem' -end \ No newline at end of file