This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Rakefile
115 lines (98 loc) · 2.93 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
begin
require "bundler/gem_tasks"
rescue LoadError
puts "bundler not installed, use 'gem install bundler' to install"
end
require 'fileutils'
require 'tmpdir'
task :default => :spec
desc 'Run specs, default will skip Ethereum fixtures tests, use "rake spec[full]" to run full tests'
task :spec, [:full] do |task, args|
exit(1) unless check_env
cli = "parallel_rspec -- --fail-fast --profile"
if args.fetch(:full, false)
puts "Run full tests.. it will take a long time"
else
puts "Run fast tests.."
cli += ' --tag ~slow'
end
cli += ' -- spec'
run(cli)
end
namespace :install do
desc "Build and install secp256k1 shared library"
task :secp256k1 do
Dir.mktmpdir do |path|
source_dir = "secp256k1"
build_dir = "#{path}/#{source_dir}"
FileUtils.copy_entry source_dir, build_dir
Dir.chdir(build_dir)
run("./autogen.sh")
run("./configure --enable-module-recovery --enable-experimental --enable-module-ecdh")
run("make")
run("make install")
end
puts "Success installed secp256k1"
end
desc "Build and install all"
task all: [:secp256k1, :install]
end
namespace :docker do
base_image = 'ciriethereum/ciri'
desc 'pull docker image'
task :pull do
run("docker pull #{base_image}:latest")
end
desc 'build docker image, rerun this task after updated Gemfile or Dockerfile'
task :build do
system("git submodule init && git submodule update")
run("docker build . -f docker/Dockerfile -t #{base_image}:latest")
end
desc 'push docker image'
task :push do
run("docker push #{base_image}:latest")
end
desc 'open Ciri develop container shell'
task :shell do
container_name = 'ciri-develop'
if system("docker inspect #{container_name} > /dev/null")
system("docker start -i #{container_name}")
else
puts "start a new develop container: #{container_name}"
system("docker run -v `pwd`:/app -it --name #{container_name} #{base_image}:latest bash")
end
end
desc 'run spec in docker'
task :spec, [:full] do |task, args|
cli_args = ""
args_hash = args.to_h
unless args_hash.empty?
cli_args = "[#{args_hash.values.join(", ")}]"
end
run("docker run -v `pwd`:/app --rm #{base_image}:latest rake 'spec#{cli_args}'")
end
private
def default_stack_size
52428800
end
def check_env
pass = false
if ENV['RUBY_THREAD_VM_STACK_SIZE'].to_i < default_stack_size
warn "Ruby stack size is not enough: set env 'RUBY_THREAD_VM_STACK_SIZE' to #{default_stack_size} and try again, otherwise you may failed to pass EVM related tests"
warn "export RUBY_THREAD_VM_STACK_SIZE=#{default_stack_size}"
else
pass = true
end
pass
end
def default_env
{'RUBY_THREAD_VM_STACK_SIZE' => ENV['RUBY_THREAD_VM_STACK_SIZE'] || default_stack_size.to_s}
end
end
private
def run(cmd)
puts "$ #{cmd}"
pid = spawn(cmd)
Process.wait(pid)
exit $?.exitstatus unless $?.success?
end