blob: cdecaa68c1de3b6d8f12cb7d9fb84d47fbbadb09 [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001#
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
Kevin Clark5a7103a2008-06-18 00:55:11 +000020require 'rubygems'
21require 'rake'
Jake Farrell9c39f772011-08-30 19:12:10 +000022require 'rake/clean'
Jake Farrella87810f2012-09-28 01:59:04 +000023require 'rspec/core/rake_task'
Kevin Clark5a7103a2008-06-18 00:55:11 +000024
Kevin Clarkc06b0152008-06-24 01:05:57 +000025THRIFT = '../../compiler/cpp/thrift'
26
Jake Farrell4bd4f0e2011-09-22 21:15:02 +000027task :default => [:gem]
Jake Farrell52092372011-09-23 17:24:00 +000028task :spec => [:'gen-rb', :build_ext, :realspec]
Bryan Duxburyf0377e22009-03-30 17:14:06 +000029
Jake Farrella87810f2012-09-28 01:59:04 +000030RSpec::Core::RakeTask.new(:realspec) do |t|
31 t.rspec_opts = ['--color', '--format d']
Kevin Clark5a7103a2008-06-18 00:55:11 +000032end
Kevin Clarkc2a07b12008-06-18 00:57:06 +000033
Jake Farrella87810f2012-09-28 01:59:04 +000034RSpec::Core::RakeTask.new(:'spec:rcov') do |t|
35 t.rspec_opts = ['--color', '--format d']
Kevin Clarkeb0dd7f2008-06-18 01:12:15 +000036 t.rcov = true
37 t.rcov_opts = ['--exclude', '^spec,/gems/']
38end
39
Kevin Clarkca8a1b32008-06-18 01:17:06 +000040desc 'Compile the .thrift files for the specs'
jfarrell4e167182015-01-29 23:03:34 -050041task :'gen-rb' => [:'gen-rb:spec', :'gen-rb:namespaced_spec', :'gen-rb:flat_spec', :'gen-rb:benchmark', :'gen-rb:debug_proto']
Kevin Clarkc06b0152008-06-24 01:05:57 +000042namespace :'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
Kevin Clarkca8a1b32008-06-18 01:17:06 +000047
jfarrellbf2617e2014-06-26 22:53:01 -040048 task :'namespaced_spec' do
49 dir = File.dirname(__FILE__) + '/spec'
Roger Meier051ed3c2016-01-10 21:08:33 +010050 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"
jfarrellbf2617e2014-06-26 22:53:01 -040053 end
54
jfarrell4e167182015-01-29 23:03:34 -050055 task :'flat_spec' do
56 dir = File.dirname(__FILE__) + '/spec'
57 mkdir_p("#{dir}/gen-rb/flat")
Roger Meier051ed3c2016-01-10 21:08:33 +010058 sh THRIFT, '--gen', 'rb', '--recurse', '-out', "#{dir}/gen-rb/flat", "#{dir}/ThriftNamespacedSpec.thrift"
jfarrell4e167182015-01-29 23:03:34 -050059 end
60
Kevin Clarkc06b0152008-06-24 01:05:57 +000061 task :'benchmark' do
62 dir = File.dirname(__FILE__) + '/benchmark'
63 sh THRIFT, '--gen', 'rb', '-o', dir, "#{dir}/Benchmark.thrift"
64 end
Bryan Duxburyd815c212009-03-19 18:57:43 +000065
66 task :'debug_proto' do
Jake Farrell9c39f772011-08-30 19:12:10 +000067 sh "mkdir", "-p", "test/debug_proto"
68 sh THRIFT, '--gen', 'rb', "-o", "test/debug_proto", "../../test/DebugProtoTest.thrift"
Bryan Duxburyd815c212009-03-19 18:57:43 +000069 end
Kevin Clarkca8a1b32008-06-18 01:17:06 +000070end
71
Jake Farrell9c39f772011-08-30 19:12:10 +000072desc "Build the native library"
Jake Farrell52092372011-09-23 17:24:00 +000073task :build_ext => :'gen-rb' do
Jake Farrell9c39f772011-08-30 19:12:10 +000074 Dir::chdir(File::dirname('ext/extconf.rb')) do
75 unless sh "ruby #{File::basename('ext/extconf.rb')}"
76 $stderr.puts "Failed to run extconf"
77 break
78 end
79 unless sh "make"
80 $stderr.puts "make failed"
81 break
82 end
83 end
84end
85
86desc 'Run the compiler tests (requires full thrift checkout)'
87task :test do
88 # ensure this is a full thrift checkout and not a tarball of the ruby libs
Roger Meier401d3992015-06-01 21:27:11 +020089 cmd = 'head -1 ../../README.md 2>/dev/null | grep Thrift >/dev/null 2>/dev/null'
Jake Farrell9c39f772011-08-30 19:12:10 +000090 system(cmd) or fail "rake test requires a full thrift checkout"
91 sh 'make', '-C', File.dirname(__FILE__) + "/../../test/rb", "check"
92end
93
Kevin Clarkca8a1b32008-06-18 01:17:06 +000094desc 'Run benchmarking of NonblockingServer'
95task :benchmark do
Kevin Clarkd3cee022008-06-18 01:19:09 +000096 ruby 'benchmark/benchmark.rb'
Kevin Clarkc2a07b12008-06-18 00:57:06 +000097end
Kevin Clark3a9ffbd2008-06-24 01:06:00 +000098
Jake Farrell4bd4f0e2011-09-22 21:15:02 +000099desc 'Builds the thrift gem'
100task :gem => [:spec, :build_ext] do
Jake Farrell9c39f772011-08-30 19:12:10 +0000101 unless sh 'gem', 'build', 'thrift.gemspec'
102 $stderr.puts "Failed to build thrift gem"
103 break
Kevin Clark3a9ffbd2008-06-24 01:06:00 +0000104 end
Jake Farrell4bd4f0e2011-09-22 21:15:02 +0000105end
106
107desc 'Install the thrift gem'
108task :install => [:gem] do
Roger Meiera510d6b2014-01-12 22:17:45 +0100109 unless sh 'gem', 'install', Dir.glob('thrift-*.gem').last
Jake Farrell9c39f772011-08-30 19:12:10 +0000110 $stderr.puts "Failed to install thrift gem"
111 break
Kevin Clark33871152008-06-26 18:14:25 +0000112 end
Kevin Clark3a9ffbd2008-06-24 01:06:00 +0000113end
Jake Farrell74362e02011-08-16 17:13:41 +0000114
Jake Farrellf88f9c22012-09-02 03:26:50 +0000115CLEAN.include [
116 '.bundle', 'benchmark/gen-rb', 'coverage', 'ext/*.{o,bundle,so,dll}', 'ext/mkmf.log',
117 'ext/Makefile', 'ext/conftest.dSYM', 'Gemfile.lock', 'mkmf.log', 'pkg', 'spec/gen-rb',
118 'test', 'thrift-*.gem'
Jake Farrell9c39f772011-08-30 19:12:10 +0000119]