Thrift-1286: Modernize the Thrift Ruby Library Dev Environment
Client: Ruby
Patch: jfarrell

Updates to ruby build process with the following changes:
 - Removes dependency on echoe for spec generation
 - Adds gemfile for bulider and uses thrift.gemspec for dependency management.
 - Adds checks in configure for builder and only calls if available (make check-local on ci servers)
 - Adds checks in configure for Ruby and rake (bundler as well but this is optional for check-local and auto dependency management)
 - Still allows for rake to do its thing if all dependencies are in place
 - Removed Manifest and setup.rb
 - Adds a install task which will generate a gem and then install that gem to locally configured ruby path (no more prefix or destdir with this client)



git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1163341 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/rb/Rakefile b/lib/rb/Rakefile
index 06189eb..8004733 100644
--- a/lib/rb/Rakefile
+++ b/lib/rb/Rakefile
@@ -19,35 +19,28 @@
 
 require 'rubygems'
 require 'rake'
-require 'rspec/core/rake_task'
+require 'rake/clean'
+require 'spec/rake/spectask'
 
 THRIFT = '../../compiler/cpp/thrift'
 
 task :default => [:spec]
-
 task :spec => [:'gen-rb', :realspec]
 
-RSpec::Core::RakeTask.new(:realspec) do |t|
-  t.rspec_opts = ['--color']
+Spec::Rake::SpecTask.new(:realspec) do |t|
+  t.spec_files = FileList['spec/**/*_spec.rb']
+  t.spec_opts = ['--color']
 end
 
-RSpec::Core::RakeTask.new(:'spec:rcov') do |t|
-  t.rspec_opts = ['--color']
+Spec::Rake::SpecTask.new(:'spec:rcov') do |t|
+  t.spec_files = FileList['spec/**/*_spec.rb']
+  t.spec_opts = ['--color']
   t.rcov = true
   t.rcov_opts = ['--exclude', '^spec,/gems/']
 end
 
-desc 'Run the compiler tests (requires full thrift checkout)'
-task :test do
-  # ensure this is a full thrift checkout and not a tarball of the ruby libs
-  cmd = 'head -1 ../../README 2>/dev/null | grep Thrift >/dev/null 2>/dev/null'
-  system(cmd) or fail "rake test requires a full thrift checkout"
-  sh 'make', '-C', File.dirname(__FILE__) + "/../../test/rb", "check"
-end
-
 desc 'Compile the .thrift files for the specs'
 task :'gen-rb' => [:'gen-rb:spec', :'gen-rb:benchmark', :'gen-rb:debug_proto']
-
 namespace :'gen-rb' do
   task :'spec' do
     dir = File.dirname(__FILE__) + '/spec'
@@ -60,44 +53,52 @@
   end
   
   task :'debug_proto' do
-    sh "mkdir", "-p", "debug_proto_test"
-    sh THRIFT, '--gen', 'rb', "-o", "debug_proto_test", "../../test/DebugProtoTest.thrift"
+    sh "mkdir", "-p", "test/debug_proto"
+    sh THRIFT, '--gen', 'rb', "-o", "test/debug_proto", "../../test/DebugProtoTest.thrift"
   end
 end
 
+desc "Build the native library"
+task :build_ext => :spec do
+   Dir::chdir(File::dirname('ext/extconf.rb')) do
+      unless sh "ruby #{File::basename('ext/extconf.rb')}"
+        $stderr.puts "Failed to run extconf"
+          break
+      end
+      unless sh "make"
+        $stderr.puts "make failed"
+        break
+      end
+    end
+end
+
+desc 'Run the compiler tests (requires full thrift checkout)'
+task :test do
+  # ensure this is a full thrift checkout and not a tarball of the ruby libs
+  cmd = 'head -1 ../../README 2>/dev/null | grep Thrift >/dev/null 2>/dev/null'
+  system(cmd) or fail "rake test requires a full thrift checkout"
+  sh 'make', '-C', File.dirname(__FILE__) + "/../../test/rb", "check"
+end
+
 desc 'Run benchmarking of NonblockingServer'
 task :benchmark do
   ruby 'benchmark/benchmark.rb'
 end
 
-
-begin
-  require 'echoe'
-
-  Echoe.new('thrift') do |p|
-    p.author = ['Thrift Developers']
-    p.email = ['dev@thrift.apache.org']
-    p.summary = "Ruby bindings for the Apache Thrift RPC system"
-    p.url = "http://thrift.apache.org"
-    p.include_rakefile = true
-    p.version = "0.8.0-dev"
-    p.rubygems_version = ">= 1.2.0"
+desc 'Generate and install the thrift gem'
+task :install => [:spec, :build_ext] do
+  unless sh 'gem', 'build', 'thrift.gemspec'
+    $stderr.puts "Failed to build thrift gem"
+    break
   end
-
-  task :install => [:check_site_lib]
-
-  require 'rbconfig'
-  task :check_site_lib do
-    if File.exist?(File.join(Config::CONFIG['sitelibdir'], 'thrift.rb'))
-      fail "thrift is already installed in site_ruby"
-    end
-  end
-rescue LoadError
-  [:install, :package].each do |t|
-    desc "Stub for #{t}"
-    task t do
-      fail "The Echoe gem is required for this task"
-    end
+  unless sh 'gem', 'install', 'thrift-*.gem'
+    $stderr.puts "Failed to install thrift gem"
+    break
   end
 end
 
+CLEAN.include [ 'ext/*.{o,bundle,so,dll}', 'mkmf.log', 'ext/mkmf.log', 'ext/Makefile', 
+  'Gemfile.lock', '.bundle', 
+  'spec/gen-rb', 'test', 'benchmark/gen-rb',
+  'pkg', 'thrift-*.gem'
+]