Rakefile 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. require 'rspec/core/rake_task'
  2. require 'rake/gempackagetask'
  3. require 'rake/extensiontask'
  4. require 'rake/javaextensiontask'
  5. require 'rake/contrib/rubyforgepublisher'
  6. require 'rake/clean'
  7. require 'rake/rdoctask'
  8. require 'benchmark'
  9. CLEAN.include(
  10. "ext/mri/*.o",
  11. "ext/mri/*.bundle",
  12. "ext/mri/*.so",
  13. "ext/jruby/bcrypt_jruby/*.class"
  14. )
  15. CLOBBER.include(
  16. "ext/mri/Makefile",
  17. "doc/coverage",
  18. "pkg"
  19. )
  20. GEMSPEC = eval(File.read(File.expand_path("../bcrypt-ruby.gemspec", __FILE__)))
  21. task :default => [:compile, :spec]
  22. desc "Run all specs"
  23. RSpec::Core::RakeTask.new do |t|
  24. t.pattern = 'spec/**/*_spec.rb'
  25. t.ruby_opts = '-w'
  26. end
  27. desc "Run all specs, with coverage testing"
  28. RSpec::Core::RakeTask.new(:rcov) do |t|
  29. t.pattern = 'spec/**/*_spec.rb'
  30. t.rcov = true
  31. t.rcov_path = 'doc/coverage'
  32. t.rcov_opts = ['--exclude', 'rspec,diff-lcs,rcov,_spec,_helper']
  33. end
  34. desc 'Generate RDoc'
  35. rd = Rake::RDocTask.new do |rdoc|
  36. rdoc.rdoc_dir = 'doc/rdoc'
  37. rdoc.options += GEMSPEC.rdoc_options
  38. rdoc.template = ENV['TEMPLATE'] if ENV['TEMPLATE']
  39. rdoc.rdoc_files.include(*GEMSPEC.extra_rdoc_files)
  40. end
  41. Rake::GemPackageTask.new(GEMSPEC) do |pkg|
  42. pkg.need_zip = true
  43. pkg.need_tar = true
  44. end
  45. if RUBY_PLATFORM =~ /java/
  46. Rake::JavaExtensionTask.new('bcrypt_ext', GEMSPEC) do |ext|
  47. ext.ext_dir = 'ext/jruby'
  48. end
  49. else
  50. Rake::ExtensionTask.new("bcrypt_ext", GEMSPEC) do |ext|
  51. ext.ext_dir = 'ext/mri'
  52. ext.cross_compile = true
  53. ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60']
  54. # inject 1.8/1.9 pure-ruby entry point
  55. ext.cross_compiling do |spec|
  56. spec.files += ["lib/#{ext.name}.rb"]
  57. end
  58. end
  59. end
  60. # Entry point for fat-binary gems on win32
  61. file("lib/bcrypt_ext.rb") do |t|
  62. File.open(t.name, 'wb') do |f|
  63. f.write <<-eoruby
  64. RUBY_VERSION =~ /(\\d+.\\d+)/
  65. require "\#{$1}/#{File.basename(t.name, '.rb')}"
  66. eoruby
  67. end
  68. at_exit{ FileUtils.rm t.name if File.exists?(t.name) }
  69. end
  70. desc "Run a set of benchmarks on the compiled extension."
  71. task :benchmark do
  72. TESTS = 100
  73. TEST_PWD = "this is a test"
  74. require File.expand_path(File.join(File.dirname(__FILE__), "lib", "bcrypt"))
  75. Benchmark.bmbm do |results|
  76. 4.upto(10) do |n|
  77. results.report("cost #{n}:") { TESTS.times { BCrypt::Password.create(TEST_PWD, :cost => n) } }
  78. end
  79. end
  80. end