Files: 5e8c83fc81f04397f8ce2953b8b8c6745f648ff2 / Rakefile
3303 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.1.0" |
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 | task :gem => ["compile:jruby"] |
83 | |
84 | Rake::GemPackageTask.new(spec) do |pkg| |
85 | pkg.need_zip = true |
86 | pkg.need_tar = true |
87 | end |
88 | |
89 | desc "Clean, then compile the extension that's native to the current Ruby compiler." |
90 | if RUBY_PLATFORM == "java" |
91 | task :compile => 'compile:jruby' |
92 | else |
93 | task :compile => 'compile:mri' |
94 | end |
95 | |
96 | namespace :compile do |
97 | desc "CLean, then compile all extensions" |
98 | task :all => [:mri, :jruby] |
99 | |
100 | desc "Clean, then compile the MRI extension" |
101 | task :mri => :clean do |
102 | Dir.chdir('ext/mri') do |
103 | ruby "extconf.rb" |
104 | sh "make" |
105 | end |
106 | end |
107 | |
108 | desc "Clean, then compile the JRuby extension" |
109 | task :jruby => :clean do |
110 | Dir.chdir('ext/jruby/bcrypt_jruby') do |
111 | sh "javac BCrypt.java" |
112 | end |
113 | end |
114 | end |
115 | |
116 | desc "Run a set of benchmarks on the compiled extension." |
117 | task :benchmark do |
118 | TESTS = 100 |
119 | TEST_PWD = "this is a test" |
120 | require File.expand_path(File.join(File.dirname(__FILE__), "lib", "bcrypt")) |
121 | Benchmark.bmbm do |results| |
122 | 4.upto(10) do |n| |
123 | results.report("cost #{n}:") { TESTS.times { BCrypt::Password.create(TEST_PWD, :cost => n) } } |
124 | end |
125 | end |
126 | end |
127 |
Built with git-ssb-web