-
Notifications
You must be signed in to change notification settings - Fork 101
/
Rakefile
66 lines (52 loc) · 2.14 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
$LOAD_PATH << ::File.expand_path('../', __FILE__)
$LOAD_PATH << ::File.expand_path('../spec', __FILE__)
require 'fileutils'
require 'rubygems'
require 'rubygems/package_task'
require 'bundler/gem_tasks'
require 'benchmark/tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new
task :default => ['compile:spec', 'compile:rpc', :spec, :rubocop]
desc 'Run specs'
namespace :compile do
desc 'Compile spec protos in spec/supprt/ directory'
task :spec do
proto_path = ::File.expand_path('../spec/support/', __FILE__)
proto_files = Dir[File.join(proto_path, '**', '*.proto')]
proto_files.each do |proto_file|
cmd = %(protoc --plugin=protoc-gen-ruby-protobuf=./bin/protoc-gen-ruby --ruby-protobuf_out=#{proto_path} -I #{proto_path} #{proto_file})
puts cmd
system(cmd) || fail("Failed to compile spec proto: #{proto_file}")
end
end
desc 'Compile rpc protos in protos/ directory'
task :rpc do
proto_path = ::File.expand_path('../proto', __FILE__)
proto_files = Dir[File.join(proto_path, '**', '*.proto')]
output_dir = ::File.expand_path('../tmp/rpc', __FILE__)
::FileUtils.mkdir_p(output_dir)
cmd = %(protoc --plugin=protoc-gen-ruby-protobuf=./bin/protoc-gen-ruby --ruby-protobuf_out=#{output_dir} -I #{proto_path} #{proto_files.join(' ')})
puts cmd
system(cmd) || fail("Failed to compile rpc protos!")
files = {
'tmp/rpc/dynamic_discovery.pb.rb' => 'lib/protobuf/rpc',
'tmp/rpc/rpc.pb.rb' => 'lib/protobuf/rpc',
'tmp/rpc/google/protobuf/descriptor.pb.rb' => 'lib/protobuf/descriptors/google/protobuf',
'tmp/rpc/google/protobuf/compiler/plugin.pb.rb' => 'lib/protobuf/descriptors/google/protobuf/compiler',
}
files.each_pair do |source_file, destination_dir|
source_file = ::File.expand_path("../#{source_file}", __FILE__)
destination_dir = ::File.expand_path("../#{destination_dir}", __FILE__)
::FileUtils::Verbose.cp(source_file, destination_dir)
end
end
end
task :console do
require 'pry'
require 'protobuf'
ARGV.clear
::Pry.start
end