Files: 7e4f6e0afadfe4fcafb532df1846f9f05c340463 / Rakefile
3272 bytesRaw
1 | gem "rspec" |
2 | require "spec/rake/spectask" |
3 | require 'rake/gempackagetask' |
4 | require 'rake/contrib/rubyforgepublisher' |
5 | require 'rake/clean' |
6 | require 'rake/rdoctask' |
7 | require "benchmark" |
8 | |
9 | PKG_NAME = "bcrypt-ruby" |
10 | PKG_VERSION = "2.0.5" |
11 | PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" |
12 | PKG_FILES = FileList[ |
13 | '[A-Z]*', |
14 | 'lib/**/*.rb', |
15 | 'spec/**/*.rb', |
16 | 'ext/mri/*.c', |
17 | 'ext/mri/*.h', |
18 | 'ext/mri/*.rb', |
19 | 'ext/jruby/bcrypt_jruby/BCrypt.java', |
20 | 'ext/jruby/bcrypt_jruby/BCrypt.class' |
21 | ] |
22 | CLEAN.include( |
23 | "ext/mri/*.o", |
24 | "ext/mri/*.bundle", |
25 | "ext/mri/*.so", |
26 | "ext/jruby/bcrypt_jruby/*.class" |
27 | ) |
28 | CLOBBER.include( |
29 | "ext/mri/Makefile", |
30 | "doc/coverage" |
31 | ) |
32 | |
33 | task :default => [:compile, :spec] |
34 | |
35 | desc "Run all specs" |
36 | Spec::Rake::SpecTask.new do |t| |
37 | t.spec_files = FileList['spec/**/*_spec.rb'] |
38 | t.spec_opts = ['--color','--backtrace','--diff'] |
39 | end |
40 | |
41 | desc "Run all specs, with coverage testing" |
42 | Spec::Rake::SpecTask.new(:rcov) do |t| |
43 | t.spec_files = FileList['spec/**/*_spec.rb'] |
44 | t.spec_opts = ['--color','--backtrace','--diff'] |
45 | t.rcov = true |
46 | t.rcov_dir = 'doc/coverage' |
47 | t.rcov_opts = ['--exclude', 'rspec,diff-lcs,rcov,_spec,_helper'] |
48 | end |
49 | |
50 | desc 'Generate RDoc' |
51 | rd = Rake::RDocTask.new do |rdoc| |
52 | rdoc.rdoc_dir = 'doc/rdoc' |
53 | rdoc.options << '--title' << 'bcrypt-ruby' << '--line-numbers' << '--inline-source' << '--main' << 'README' |
54 | rdoc.template = ENV['TEMPLATE'] if ENV['TEMPLATE'] |
55 | rdoc.rdoc_files.include('README', 'COPYING', 'CHANGELOG', 'lib/**/*.rb') |
56 | end |
57 | |
58 | spec = Gem::Specification.new do |s| |
59 | s.name = PKG_NAME |
60 | s.version = PKG_VERSION |
61 | s.summary = "OpenBSD's bcrypt() password hashing algorithm." |
62 | s.description = <<-EOF |
63 | bcrypt() is a sophisticated and secure hash algorithm designed by The OpenBSD project |
64 | for hashing passwords. bcrypt-ruby provides a simple, humane wrapper for safely handling |
65 | passwords. |
66 | EOF |
67 | |
68 | s.files = PKG_FILES.to_a |
69 | s.require_path = 'lib' |
70 | |
71 | s.has_rdoc = true |
72 | s.rdoc_options = rd.options |
73 | s.extra_rdoc_files = rd.rdoc_files.to_a |
74 | |
75 | s.extensions = FileList["ext/mri/extconf.rb"].to_a |
76 | |
77 | s.authors = ["Coda Hale"] |
78 | s.email = "coda.hale@gmail.com" |
79 | s.homepage = "http://bcrypt-ruby.rubyforge.org" |
80 | s.rubyforge_project = "bcrypt-ruby" |
81 | end |
82 | |
83 | Rake::GemPackageTask.new(spec) do |pkg| |
84 | pkg.need_zip = true |
85 | pkg.need_tar = true |
86 | end |
87 | |
88 | desc "Clean, then compile the extension that's native to the current Ruby compiler." |
89 | if RUBY_PLATFORM == "java" |
90 | task :compile => 'compile:jruby' |
91 | else |
92 | task :compile => 'compile:mri' |
93 | end |
94 | |
95 | namespace :compile do |
96 | desc "CLean, then compile all extensions" |
97 | task :all => [:mri, :jruby] |
98 | |
99 | desc "Clean, then compile the MRI extension" |
100 | task :mri => :clean do |
101 | Dir.chdir('ext/mri') do |
102 | ruby "extconf.rb" |
103 | sh "make" |
104 | end |
105 | end |
106 | |
107 | desc "Clean, then compile the JRuby extension" |
108 | task :jruby => :clean do |
109 | Dir.chdir('ext/jruby/bcrypt_jruby') do |
110 | sh "javac BCrypt.java" |
111 | end |
112 | end |
113 | end |
114 | |
115 | desc "Run a set of benchmarks on the compiled extension." |
116 | task :benchmark do |
117 | TESTS = 100 |
118 | TEST_PWD = "this is a test" |
119 | require File.expand_path(File.join(File.dirname(__FILE__), "lib", "bcrypt")) |
120 | Benchmark.bmbm do |results| |
121 | 4.upto(10) do |n| |
122 | results.report("cost #{n}:") { TESTS.times { BCrypt::Password.create(TEST_PWD, :cost => n) } } |
123 | end |
124 | end |
125 | end |
126 |
Built with git-ssb-web