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
10 # http://www.apache.org/licenses/LICENSE-2.0
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
23 require 'rspec/core/rake_task'
25 THRIFT = '../../compiler/cpp/thrift'
27 task :default => [:gem]
28 task :spec => [:'gen-rb', :build_ext, :realspec]
30 RSpec::Core::RakeTask.new(:realspec) do |t|
31 t.rspec_opts = ['--color', '--format d']
34 RSpec::Core::RakeTask.new(:'spec:rcov') do |t|
35 t.rspec_opts = ['--color', '--format d']
37 t.rcov_opts = ['--exclude', '^spec,/gems/']
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']
42 namespace :'gen-rb' do
44 dir = File.dirname(__FILE__) + '/spec'
45 sh THRIFT, '--gen', 'rb', '-o', dir, "#{dir}/ThriftSpec.thrift"
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"
56 dir = File.dirname(__FILE__) + '/spec'
57 mkdir_p("#{dir}/gen-rb/flat")
58 sh THRIFT, '--gen', 'rb', '--recurse', '-out', "#{dir}/gen-rb/flat", "#{dir}/ThriftNamespacedSpec.thrift"
62 dir = File.dirname(__FILE__) + '/benchmark'
63 sh THRIFT, '--gen', 'rb', '-o', dir, "#{dir}/Benchmark.thrift"
66 task :'debug_proto' do
67 sh "mkdir", "-p", "test/debug_proto"
68 sh THRIFT, '--gen', 'rb', "-o", "test/debug_proto", "../../test/DebugProtoTest.thrift"
72 desc "Build the native library"
73 task :build_ext => :'gen-rb' do
74 next if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
75 Dir::chdir(File::dirname('ext/extconf.rb')) do
76 unless sh "ruby #{File::basename('ext/extconf.rb')}"
77 $stderr.puts "Failed to run extconf"
81 $stderr.puts "make failed"
87 desc 'Run the compiler tests (requires full thrift checkout)'
89 # ensure this is a full thrift checkout and not a tarball of the ruby libs
90 cmd = 'head -1 ../../README.md 2>/dev/null | grep Thrift >/dev/null 2>/dev/null'
91 system(cmd) or fail "rake test requires a full thrift checkout"
92 sh 'make', '-C', File.dirname(__FILE__) + "/../../test/rb", "check"
95 desc 'Run benchmarking of NonblockingServer'
97 ruby 'benchmark/benchmark.rb'
100 desc 'Builds the thrift gem'
101 task :gem => [:spec, :build_ext] do
102 unless sh 'gem', 'build', 'thrift.gemspec'
103 $stderr.puts "Failed to build thrift gem"
108 desc 'Install the thrift gem'
109 task :install => [:gem] do
110 unless sh 'gem', 'install', Dir.glob('thrift-*.gem').last
111 $stderr.puts "Failed to install thrift gem"
117 '.bundle', 'benchmark/gen-rb', 'coverage', 'ext/*.{o,bundle,so,dll}', 'ext/mkmf.log',
118 'ext/Makefile', 'ext/conftest.dSYM', 'Gemfile.lock', 'mkmf.log', 'pkg', 'spec/gen-rb',
119 'test', 'thrift-*.gem'