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