require 'ftools' LIB_WINDOWS = ['rubyrunnative__x86-mswin32.so','rubyrunnative__.so'] LIB_LINUX = ['rubyrunnative__x86-linux.so','rubyrunnative__.so'] LIB_OSX_X86 = ['rubyrunnative__x86-darwin.bundle','rubyrunnative__.bundle'] LIB_OSX_PPC = ['rubyrunnative__ppc-darwin.bundle','rubyrunnative__.bundle'] FOLDER_EXT = 'ext' FOLDER_LIB = 'lib' FOLDER_RUBYRUN = 'rubyrun' FOLDER_BIN = 'bin' task :default do copied = false $:.each {|path| begin if path.downcase.include?('site') File.copy(File.join('..',FOLDER_LIB,FOLDER_RUBYRUN,'rubyrun.rb'),path) File.copy(File.join('..',FOLDER_LIB,FOLDER_RUBYRUN,'rubyrun.rb'),File.join(path,'ubyrun.rb')) copied = true end rescue end break if copied } unless copied $:.reverse.each {|path| next if (path == '.' || path == '..') begin File.copy(File.join('..',FOLDER_LIB,FOLDER_RUBYRUN,'rubyrun.rb'),path) File.copy(File.join('..',FOLDER_LIB,FOLDER_RUBYRUN,'rubyrun.rb'),File.join(path,'ubyrun.rb')) copied = true rescue end break if copied } end unless copied raise IOError.new("Unable to copy rubyrun.rb to Ruby path. Make sure Gem process has write permission in one of the following directories:\n#{$:.reverse.delete_if {|p| p == '.' || p == '..'}.join("\n")}") end Dir.chdir(File.join('..',FOLDER_EXT)) case RUBY_PLATFORM when /mswin/ just_compiled? ? deploy_compiled_native(LIB_WINDOWS) : (deploy_precompiled_native(LIB_WINDOWS) if valid_lib?(LIB_WINDOWS)) when /linux/ just_compiled? ? deploy_compiled_native(LIB_LINUX) : (deploy_precompiled_native(LIB_LINUX) if valid_lib?(LIB_LINUX)) when /darwin8/ if just_compiled? deploy_compiled_native(LIB_OSX_PPC) else if valid_lib?(LIB_OSX_PPC) deploy_precompiled_native(LIB_OSX_PPC) elsif valid_lib?(LIB_OSX_X86) deploy_precompiled_native(LIB_OSX_X86) end end when /darwin9/ if just_compiled? deploy_compiled_native(LIB_OSX_X86) else if valid_lib?(LIB_OSX_X86) deploy_precompiled_native(LIB_OSX_X86) elsif valid_lib?(LIB_OSX_PPC) deploy_precompiled_native(LIB_OSX_PPC) end end end Dir.chdir(File.join('..',FOLDER_BIN)) end def just_compiled? !Dir.glob('../rubyrunnative__.*').empty? end def valid_lib?(lib_name) FileUtils.mv(lib_name.first,lib_name.last) system("ruby #{File.join('..',FOLDER_BIN,'rubyrun_native_test__.rb')}") end def deploy_compiled_native(lib_name) FileUtils.rm_rf(File.join('..',"#{lib_name.last}")) if File.exists?(File.join('..',"#{lib_name.last}")) if RUBY_PLATFORM =~ /mswin/ system("mt.exe -manifest #{lib_name.last}.manifest -outputresource:#{lib_name.last};2") end FileUtils.mv(lib_name.last, File.join('..',FOLDER_LIB,FOLDER_RUBYRUN)) end def deploy_precompiled_native(lib_name) FileUtils.mv(lib_name.last,File.join('..',FOLDER_LIB,FOLDER_RUBYRUN)) end