forked from redis-rb/redis-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
123 lines (110 loc) · 3.69 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
116
117
118
119
120
121
122
123
# frozen_string_literal: true
require "rake/extensiontask"
require "rake/testtask"
require 'rubocop/rake_task'
RuboCop::RakeTask.new
require "rake/clean"
CLOBBER.include "pkg"
require "bundler/gem_helper"
Bundler::GemHelper.install_tasks(name: "redis-client")
Bundler::GemHelper.install_tasks(dir: "hiredis-client", name: "hiredis-client")
gemspec = Gem::Specification.load("redis-client.gemspec")
Rake::ExtensionTask.new do |ext|
ext.name = "hiredis_connection"
ext.ext_dir = "hiredis-client/ext/redis_client/hiredis"
ext.lib_dir = "hiredis-client/lib/redis_client"
ext.gem_spec = gemspec
CLEAN.add("#{ext.ext_dir}/vendor/*.{a,o}")
end
namespace :test do
Rake::TestTask.new(:ruby) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"].exclude("test/sentinel/*_test.rb")
t.options = '-v' if ENV['CI'] || ENV['VERBOSE']
end
Rake::TestTask.new(:sentinel) do |t|
t.libs << "test/sentinel"
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/sentinel/*_test.rb"]
t.options = '-v' if ENV['CI'] || ENV['VERBOSE']
end
Rake::TestTask.new(:hiredis) do |t|
t.libs << "test/hiredis"
t.libs << "test"
t.libs << "hiredis-client/lib"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"].exclude("test/sentinel/*_test.rb")
t.options = '-v' if ENV['CI'] || ENV['VERBOSE']
end
end
hiredis_supported = RUBY_ENGINE == "ruby" && !RUBY_PLATFORM.match?(/mswin/)
if hiredis_supported
task test: %i[test:ruby test:hiredis test:sentinel]
else
task test: %i[test:ruby test:sentinel]
end
namespace :hiredis do
task :download do
version = "1.0.2"
archive_path = "tmp/hiredis-#{version}.tar.gz"
url = "https://github.com/redis/hiredis/archive/refs/tags/v#{version}.tar.gz"
system("curl", "-L", url, out: archive_path) or raise "Downloading of #{url} failed"
system("rm", "-rf", "hiredis-client/ext/redis_client/hiredis/vendor/")
system("mkdir", "-p", "hiredis-client/ext/redis_client/hiredis/vendor/")
system(
"tar", "xvzf", archive_path,
"-C", "hiredis-client/ext/redis_client/hiredis/vendor",
"--strip-components", "1",
)
system("rm", "-rf", "hiredis-client/ext/redis_client/hiredis/vendor/examples")
end
end
benchmark_suites = %w(single pipelined)
benchmark_modes = %i[ruby yjit hiredis]
namespace :benchmark do
benchmark_suites.each do |suite|
benchmark_modes.each do |mode|
name = "#{suite}_#{mode}"
task name do
output_path = "benchmark/#{name}.md"
sh "rm", "-f", output_path
File.open(output_path, "w+") do |output|
output.puts("ruby: `#{RUBY_DESCRIPTION}`\n\n")
output.puts("redis-server: `#{`redis-server -v`.strip}`\n\n")
output.puts
output.flush
env = {}
args = []
args << "--yjit" if mode == :yjit
env["DRIVER"] = mode == :hiredis ? "hiredis" : "ruby"
system(env, RbConfig.ruby, *args, "benchmark/#{suite}.rb", out: output)
end
skipping = false
output = File.readlines(output_path).reject do |line|
if skipping
if line == "Comparison:\n"
skipping = false
true
else
skipping
end
else
skipping = true if line.start_with?("Warming up ---")
skipping
end
end
File.write(output_path, output.join)
end
end
end
task all: benchmark_suites.flat_map { |s| benchmark_modes.flat_map { |m| "#{s}_#{m}" } }
end
if hiredis_supported
task default: %i[compile test rubocop]
task ci: %i[compile test:ruby test:hiredis]
else
task default: %i[test rubocop]
task ci: %i[test:ruby]
end