Files: e21326529ba4c7d40b7c8684922ca26cc06f80f0 / Rakefile
2325 bytesRaw
1 | require 'rspec/core/rake_task' |
2 | require 'rubygems/package_task' |
3 | require 'rake/extensiontask' |
4 | require 'rake/javaextensiontask' |
5 | require 'rake/clean' |
6 | require 'rdoc/task' |
7 | require 'benchmark' |
8 | |
9 | CLEAN.include( |
10 | "tmp", |
11 | "lib/1.8", |
12 | "lib/1.9", |
13 | "lib/2.0", |
14 | "lib/2.1", |
15 | "lib/bcrypt_ext.jar", |
16 | "lib/bcrypt_ext.so" |
17 | ) |
18 | CLOBBER.include( |
19 | "doc", |
20 | "pkg" |
21 | ) |
22 | |
23 | GEMSPEC = Gem::Specification.load("bcrypt.gemspec") |
24 | |
25 | task :default => [:compile, :spec] |
26 | |
27 | desc "Run all specs" |
28 | RSpec::Core::RakeTask.new do |t| |
29 | t.pattern = 'spec/**/*_spec.rb' |
30 | t.ruby_opts = '-w' |
31 | end |
32 | |
33 | desc "Run all specs, with coverage testing" |
34 | RSpec::Core::RakeTask.new(:rcov) do |t| |
35 | t.pattern = 'spec/**/*_spec.rb' |
36 | t.rcov = true |
37 | t.rcov_path = 'doc/coverage' |
38 | t.rcov_opts = ['--exclude', 'rspec,diff-lcs,rcov,_spec,_helper'] |
39 | end |
40 | |
41 | desc 'Generate RDoc' |
42 | RDoc::Task.new do |rdoc| |
43 | rdoc.rdoc_dir = 'doc/rdoc' |
44 | rdoc.options += GEMSPEC.rdoc_options |
45 | rdoc.template = ENV['TEMPLATE'] if ENV['TEMPLATE'] |
46 | rdoc.rdoc_files.include(*GEMSPEC.extra_rdoc_files) |
47 | end |
48 | |
49 | Gem::PackageTask.new(GEMSPEC) do |pkg| |
50 | pkg.need_zip = true |
51 | pkg.need_tar = true |
52 | end |
53 | |
54 | if RUBY_PLATFORM =~ /java/ |
55 | Rake::JavaExtensionTask.new('bcrypt_ext', GEMSPEC) do |ext| |
56 | ext.ext_dir = 'ext/jruby' |
57 | end |
58 | else |
59 | Rake::ExtensionTask.new("bcrypt_ext", GEMSPEC) do |ext| |
60 | ext.ext_dir = 'ext/mri' |
61 | ext.cross_compile = true |
62 | ext.cross_platform = ['x86-mingw32', 'x64-mingw32'] |
63 | end |
64 | |
65 | ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version| |
66 | platforms = { |
67 | "x86-mingw32" => "i686-w64-mingw32", |
68 | "x64-mingw32" => "x86_64-w64-mingw32" |
69 | } |
70 | platforms.each do |platform, prefix| |
71 | task "copy:bcrypt_ext:#{platform}:#{ruby_version}" do |t| |
72 | %w[lib tmp/#{platform}/stage/lib].each do |dir| |
73 | so_file = "#{dir}/#{ruby_version[/^\d+\.\d+/]}/bcrypt_ext.so" |
74 | if File.exists?(so_file) |
75 | sh "#{prefix}-strip -S #{so_file}" |
76 | end |
77 | end |
78 | end |
79 | end |
80 | end |
81 | end |
82 | |
83 | desc "Run a set of benchmarks on the compiled extension." |
84 | task :benchmark do |
85 | TESTS = 100 |
86 | TEST_PWD = "this is a test" |
87 | require File.expand_path(File.join(File.dirname(__FILE__), "lib", "bcrypt")) |
88 | Benchmark.bmbm do |results| |
89 | 4.upto(10) do |n| |
90 | results.report("cost #{n}:") { TESTS.times { BCrypt::Password.create(TEST_PWD, :cost => n) } } |
91 | end |
92 | end |
93 | end |
94 |
Built with git-ssb-web