| 1 |
# |
| 2 |
# Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
# or more contributor license agreements. See the NOTICE file |
| 4 |
# distributed with this work for additional information |
| 5 |
# regarding copyright ownership. The ASF licenses this file |
| 6 |
# to you under the Apache License, Version 2.0 (the |
| 7 |
# "License"); you may not use this file except in compliance |
| 8 |
# with the License. You may obtain a copy of the License at |
| 9 |
# |
| 10 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
# |
| 12 |
# Unless required by applicable law or agreed to in writing, |
| 13 |
# software distributed under the License is distributed on an |
| 14 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
# KIND, either express or implied. See the License for the |
| 16 |
# specific language governing permissions and limitations |
| 17 |
# under the License. |
| 18 |
# |
| 19 |
|
| 20 |
require 'rubygems' |
| 21 |
require 'rake' |
| 22 |
require 'rake/clean' |
| 23 |
require 'rspec/core/rake_task' |
| 24 |
|
| 25 |
THRIFT = '../../compiler/cpp/thrift' |
| 26 |
|
| 27 |
task :default => [:gem] |
| 28 |
task :spec => [:'gen-rb', :build_ext, :realspec] |
| 29 |
|
| 30 |
RSpec::Core::RakeTask.new(:realspec) do |t| |
| 31 |
t.rspec_opts = ['--color', '--format d'] |
| 32 |
end |
| 33 |
|
| 34 |
RSpec::Core::RakeTask.new(:'spec:rcov') do |t| |
| 35 |
t.rspec_opts = ['--color', '--format d'] |
| 36 |
t.rcov = true |
| 37 |
t.rcov_opts = ['--exclude', '^spec,/gems/'] |
| 38 |
end |
| 39 |
|
| 40 |
desc 'Compile the .thrift files for the specs' |
| 41 |
task :'gen-rb' => [:'gen-rb:spec', :'gen-rb:namespaced_spec', :'gen-rb:flat_spec', :'gen-rb:benchmark', :'gen-rb:debug_proto', :'gen-rb:constants_demo', :'gen-rb:fuzz'] |
| 42 |
namespace :'gen-rb' do |
| 43 |
task :'spec' do |
| 44 |
dir = File.dirname(__FILE__) + '/spec' |
| 45 |
sh THRIFT, '--gen', 'rb', '-o', dir, "#{dir}/ThriftSpec.thrift" |
| 46 |
end |
| 47 |
|
| 48 |
task :'namespaced_spec' do |
| 49 |
dir = File.dirname(__FILE__) + '/spec' |
| 50 |
sh THRIFT, '--gen', 'rb:namespaced', '--recurse', '-o', dir, "#{dir}/ThriftNamespacedSpec.thrift" |
| 51 |
sh THRIFT, '--gen', 'rb:namespaced', '--recurse', '-o', dir, "#{dir}/BaseService.thrift" |
| 52 |
sh THRIFT, '--gen', 'rb:namespaced', '--recurse', '-o', dir, "#{dir}/ExtendedService.thrift" |
| 53 |
end |
| 54 |
|
| 55 |
task :'flat_spec' do |
| 56 |
dir = File.dirname(__FILE__) + '/spec' |
| 57 |
FileUtils.mkdir_p("#{dir}/gen-rb/flat") |
| 58 |
sh THRIFT, '--gen', 'rb', '--recurse', '-out', "#{dir}/gen-rb/flat", "#{dir}/ThriftNamespacedSpec.thrift" |
| 59 |
end |
| 60 |
|
| 61 |
task :'benchmark' do |
| 62 |
dir = File.dirname(__FILE__) + '/benchmark' |
| 63 |
sh THRIFT, '--gen', 'rb', '-o', dir, "#{dir}/Benchmark.thrift" |
| 64 |
end |
| 65 |
|
| 66 |
task :'debug_proto' do |
| 67 |
sh "mkdir", "-p", "test/debug_proto" |
| 68 |
sh THRIFT, '--gen', 'rb', "-o", "test/debug_proto", "../../test/DebugProtoTest.thrift" |
| 69 |
end |
| 70 |
|
| 71 |
task :'constants_demo' do |
| 72 |
dir = File.dirname(__FILE__) + '/spec' |
| 73 |
sh THRIFT, '--gen', 'rb:namespaced', '--recurse', '-o', dir, "../../test/ConstantsDemo.thrift" |
| 74 |
end |
| 75 |
|
| 76 |
task :'fuzz' do |
| 77 |
dir = File.dirname(__FILE__) + '/test/fuzz' |
| 78 |
sh "mkdir", "-p", dir |
| 79 |
sh THRIFT, '--gen', 'rb', '-o', dir, "../../test/FuzzTest.thrift" |
| 80 |
end |
| 81 |
end |
| 82 |
|
| 83 |
desc "Build the native library" |
| 84 |
task :build_ext => :'gen-rb' do |
| 85 |
next if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ |
| 86 |
next if ENV['SKIP_BUILD_EXT'] == '1' |
| 87 |
Dir::chdir(File::dirname('ext/extconf.rb')) do |
| 88 |
unless sh "ruby #{File::basename('ext/extconf.rb')}" |
| 89 |
$stderr.puts "Failed to run extconf" |
| 90 |
break |
| 91 |
end |
| 92 |
unless sh "make" |
| 93 |
$stderr.puts "make failed" |
| 94 |
break |
| 95 |
end |
| 96 |
end |
| 97 |
end |
| 98 |
|
| 99 |
desc 'Run the compiler tests (requires full thrift checkout)' |
| 100 |
task :test do |
| 101 |
# ensure this is a full thrift checkout and not a tarball of the ruby libs |
| 102 |
cmd = 'head -1 ../../README.md 2>/dev/null | grep Thrift >/dev/null 2>/dev/null' |
| 103 |
system(cmd) or fail "rake test requires a full thrift checkout" |
| 104 |
sh 'make', '-C', File.dirname(__FILE__) + "/../../test/rb", "check" |
| 105 |
end |
| 106 |
|
| 107 |
desc 'Run benchmarking of NonblockingServer' |
| 108 |
task :benchmark do |
| 109 |
ruby 'benchmark/benchmark.rb' |
| 110 |
end |
| 111 |
|
| 112 |
begin |
| 113 |
require "rubocop/rake_task" |
| 114 |
RuboCop::RakeTask.new |
| 115 |
rescue LoadError |
| 116 |
task(:rubocop) { abort "Install the rubocop gem to run a static analysis" } |
| 117 |
end |
| 118 |
|
| 119 |
desc 'Builds the thrift gem' |
| 120 |
task :gem => [:spec, :build_ext] do |
| 121 |
unless sh 'gem', 'build', 'thrift.gemspec' |
| 122 |
$stderr.puts "Failed to build thrift gem" |
| 123 |
break |
| 124 |
end |
| 125 |
end |
| 126 |
|
| 127 |
desc 'Install the thrift gem' |
| 128 |
task :install => [:gem] do |
| 129 |
unless sh 'gem', 'install', Dir.glob('thrift-*.gem').last |
| 130 |
$stderr.puts "Failed to install thrift gem" |
| 131 |
break |
| 132 |
end |
| 133 |
end |
| 134 |
|
| 135 |
CLEAN.include [ |
| 136 |
'.bundle', 'benchmark/gen-rb', 'coverage', 'ext/*.{o,bundle,so,dll}', 'ext/mkmf.log', |
| 137 |
'ext/Makefile', 'ext/conftest.dSYM', 'ext/thrift_native.bundle.dSYM', 'mkmf.log', |
| 138 |
'pkg', 'spec/gen-rb', 'test/debug_proto/gen-rb', 'thrift-*.gem' |
| 139 |
] |