forked from lian/bitcoin-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
87 lines (70 loc) · 2.55 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
# libsecp256k1 repository URL
LIBSECP256K1_REPO = 'https://github.com/bitcoin-core/secp256k1/'.freeze
# Folder into which libsecp256k1 repository is cloned
LIBSECP256K1_PATH = 'secp256k1'.freeze
RUBY = 'ruby' unless defined?(RUBY)
# Attempts to configure the path to libsecp256k1.
#
# @return [Bool] true if the library was found and configured, false otherwise.
def configure_libsecp256k1
return true if ENV["SECP256K1_LIB_PATH"]
if File.exist?('secp256k1.so')
ENV['SECP256K1_LIB_PATH'] = File.join(Dir.pwd, 'secp256k1.so')
return true
end
false
end
task :default => :rspec
RSpec::Core::RakeTask.new(:rspec) do |t|
t.rspec_opts = '--exclude spec/unit/integrations/*'
end
RSpec::Core::RakeTask.new(:coin_spec, :coin) do |t, args|
t.rspec_opts = "--pattern spec/unit/integrations/#{args[:coin]}_spec.rb"
end
desc 'Compiles the libsecp256k1 library'
task :build_libsecp256k1, [:force] do |_, args|
# Commit hash for libsecp256k1 from May 31, 2018.
COMMIT_HASH = '1e6f1f5ad5e7f1e3ef79313ec02023902bf8175c'.freeze
force = args[:force]
if Dir.exists?(LIBSECP256K1_PATH) && !force
puts "ERROR: Folder #{LIBSECP256K1_PATH} already exists, run with " \
"[force:true] to force cloning and building anyways."
exit 1
end
sh "rm -rf #{LIBSECP256K1_PATH}"
sh "git clone #{LIBSECP256K1_REPO}"
Dir.chdir(LIBSECP256K1_PATH) do
sh "git checkout #{COMMIT_HASH}"
sh './autogen.sh'
sh './configure --enable-module-recovery --with-pic'
sh 'make libsecp256k1.la'
end
libfile = 'libsecp256k1.so.0.0.0'
# Handle macOS libraries being different from Linux libraries
libfile = 'libsecp256k1.0.dylib' unless RUBY_PLATFORM.match(/darwin/).nil?
sh "cp #{LIBSECP256K1_PATH}/.libs/#{libfile} secp256k1.so"
sh "rm -rf #{LIBSECP256K1_PATH}"
end
desc 'Generate RDoc documentation'
task :rdoc do
`rm -rf rdoc`
system("rdoc -a -A -H -t 'bitcoin-ruby RDoc' -W 'https://github.com/mhanne/bitcoin-ruby/tree/master/%s' -o rdoc -m README.rdoc examples/ doc/ lib/ README.rdoc COPYING")
end
desc 'Generate test coverage report'
task :coverage do
if !configure_libsecp256k1
puts 'ERROR: Skipping code coverage tests since required library '\
'libsecp256k1 was not found. Run `rake build_libsecp256k1` to build.'
exit 1
end
begin
require 'simplecov'
rescue LoadError
puts "Simplecov not found. Run `gem install simplecov` to install it."
exit
end
Rake::Task['rspec'].invoke
system('open coverage/index.html') if RUBY_PLATFORM.include? 'darwin'
end