From 553c9a77c3526702276eb2aed330df0fe763dda6 Mon Sep 17 00:00:00 2001 From: Luis Lavena Date: Sun, 26 Sep 2010 17:14:52 -0300 Subject: [PATCH] Inject 1.8/1.9 pure-ruby entry point during xcompile The original problem of .so files not included in the final gemspec is because rake-compiler put files in lib_dir/X.Y/extension while the pure-ruby entry point was looking for lib_dir/XY/extension --- tasks/compile.rake | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tasks/compile.rake b/tasks/compile.rake index 5e65e86..eb6b3b0 100644 --- a/tasks/compile.rake +++ b/tasks/compile.rake @@ -21,6 +21,11 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext| ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60'] ext.cross_config_options << "--with-mysql-include=#{mysql_lib}/include" ext.cross_config_options << "--with-mysql-lib=#{mysql_lib}/lib/opt" + + # inject 1.8/1.9 pure-ruby entry point when cross compiling only + ext.cross_compiling do |spec| + spec.files << 'lib/mysql2/mysql2.rb' + end end ext.lib_dir = File.join 'lib', 'mysql2' @@ -30,25 +35,16 @@ Rake::ExtensionTask.new("mysql2", gemspec) do |ext| end Rake::Task[:spec].prerequisites << :compile -namespace :cross do - task :file_list do - gemspec.extensions = [] - gemspec.files += Dir["lib/#{gemspec.name}/#{gemspec.name}.rb"] - gemspec.files += Dir["lib/#{gemspec.name}/1.{8,9}/#{gemspec.name}.so"] - # gemspec.files += Dir["ext/mysql2/*.dll"] - end -end - -file 'lib/mysql2/mysql2.rb' do +file 'lib/mysql2/mysql2.rb' do |t| name = gemspec.name - File.open("lib/#{name}/#{name}.rb", 'wb') do |f| + File.open(t.name, 'wb') do |f| f.write <<-eoruby -require "#{name}/\#{RUBY_VERSION.sub(/\\.\\d+$/, '')}/#{name}" +RUBY_VERSION =~ /(\\d+.\\d+)/ +require "#{name}/\#{$1}/#{name}" eoruby end end if Rake::Task.task_defined?(:cross) Rake::Task[:cross].prerequisites << "lib/mysql2/mysql2.rb" - Rake::Task[:cross].prerequisites << "cross:file_list" end