| David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 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 |  | 
| Kevin Clark | 5a7103a | 2008-06-18 00:55:11 +0000 | [diff] [blame] | 20 | require 'rubygems' | 
|  | 21 | require 'rake' | 
| Jake Farrell | 9c39f77 | 2011-08-30 19:12:10 +0000 | [diff] [blame] | 22 | require 'rake/clean' | 
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 23 | require 'rspec/core/rake_task' | 
| Kevin Clark | 5a7103a | 2008-06-18 00:55:11 +0000 | [diff] [blame] | 24 |  | 
| Kevin Clark | c06b015 | 2008-06-24 01:05:57 +0000 | [diff] [blame] | 25 | THRIFT = '../../compiler/cpp/thrift' | 
|  | 26 |  | 
| Jake Farrell | 4bd4f0e | 2011-09-22 21:15:02 +0000 | [diff] [blame] | 27 | task :default => [:gem] | 
| Jake Farrell | 5209237 | 2011-09-23 17:24:00 +0000 | [diff] [blame] | 28 | task :spec => [:'gen-rb', :build_ext, :realspec] | 
| Bryan Duxbury | f0377e2 | 2009-03-30 17:14:06 +0000 | [diff] [blame] | 29 |  | 
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 30 | RSpec::Core::RakeTask.new(:realspec) do |t| | 
|  | 31 | t.rspec_opts = ['--color', '--format d'] | 
| Kevin Clark | 5a7103a | 2008-06-18 00:55:11 +0000 | [diff] [blame] | 32 | end | 
| Kevin Clark | c2a07b1 | 2008-06-18 00:57:06 +0000 | [diff] [blame] | 33 |  | 
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 34 | RSpec::Core::RakeTask.new(:'spec:rcov') do |t| | 
|  | 35 | t.rspec_opts = ['--color', '--format d'] | 
| Kevin Clark | eb0dd7f | 2008-06-18 01:12:15 +0000 | [diff] [blame] | 36 | t.rcov = true | 
|  | 37 | t.rcov_opts = ['--exclude', '^spec,/gems/'] | 
|  | 38 | end | 
|  | 39 |  | 
| Kevin Clark | ca8a1b3 | 2008-06-18 01:17:06 +0000 | [diff] [blame] | 40 | desc 'Compile the .thrift files for the specs' | 
| jfarrell | 4e16718 | 2015-01-29 23:03:34 -0500 | [diff] [blame] | 41 | task :'gen-rb' => [:'gen-rb:spec', :'gen-rb:namespaced_spec', :'gen-rb:flat_spec', :'gen-rb:benchmark', :'gen-rb:debug_proto'] | 
| Kevin Clark | c06b015 | 2008-06-24 01:05:57 +0000 | [diff] [blame] | 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 | 
| Kevin Clark | ca8a1b3 | 2008-06-18 01:17:06 +0000 | [diff] [blame] | 47 |  | 
| jfarrell | bf2617e | 2014-06-26 22:53:01 -0400 | [diff] [blame] | 48 | task :'namespaced_spec' do | 
|  | 49 | dir = File.dirname(__FILE__) + '/spec' | 
| Roger Meier | 051ed3c | 2016-01-10 21:08:33 +0100 | [diff] [blame] | 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" | 
| jfarrell | bf2617e | 2014-06-26 22:53:01 -0400 | [diff] [blame] | 53 | end | 
|  | 54 |  | 
| jfarrell | 4e16718 | 2015-01-29 23:03:34 -0500 | [diff] [blame] | 55 | task :'flat_spec' do | 
|  | 56 | dir = File.dirname(__FILE__) + '/spec' | 
| Stan Hu | cc70b4e | 2021-03-11 03:49:57 +0530 | [diff] [blame] | 57 | FileUtils.mkdir_p("#{dir}/gen-rb/flat") | 
| Roger Meier | 051ed3c | 2016-01-10 21:08:33 +0100 | [diff] [blame] | 58 | sh THRIFT, '--gen', 'rb', '--recurse', '-out', "#{dir}/gen-rb/flat", "#{dir}/ThriftNamespacedSpec.thrift" | 
| jfarrell | 4e16718 | 2015-01-29 23:03:34 -0500 | [diff] [blame] | 59 | end | 
|  | 60 |  | 
| Kevin Clark | c06b015 | 2008-06-24 01:05:57 +0000 | [diff] [blame] | 61 | task :'benchmark' do | 
|  | 62 | dir = File.dirname(__FILE__) + '/benchmark' | 
|  | 63 | sh THRIFT, '--gen', 'rb', '-o', dir, "#{dir}/Benchmark.thrift" | 
|  | 64 | end | 
| Bryan Duxbury | d815c21 | 2009-03-19 18:57:43 +0000 | [diff] [blame] | 65 |  | 
|  | 66 | task :'debug_proto' do | 
| Jake Farrell | 9c39f77 | 2011-08-30 19:12:10 +0000 | [diff] [blame] | 67 | sh "mkdir", "-p", "test/debug_proto" | 
| Jens Geyer | f066d84 | 2022-06-13 23:37:25 +0200 | [diff] [blame] | 68 | sh THRIFT, '--gen', 'rb', "-o", "test/debug_proto", "../../test/v0.16/DebugProtoTest.thrift" | 
| Bryan Duxbury | d815c21 | 2009-03-19 18:57:43 +0000 | [diff] [blame] | 69 | end | 
| Kevin Clark | ca8a1b3 | 2008-06-18 01:17:06 +0000 | [diff] [blame] | 70 | end | 
|  | 71 |  | 
| Jake Farrell | 9c39f77 | 2011-08-30 19:12:10 +0000 | [diff] [blame] | 72 | desc "Build the native library" | 
| Jake Farrell | 5209237 | 2011-09-23 17:24:00 +0000 | [diff] [blame] | 73 | task :build_ext => :'gen-rb' do | 
| Nephi Allred | 414f9a5b | 2019-01-02 16:34:51 -0700 | [diff] [blame] | 74 | next if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ | 
| Jake Farrell | 9c39f77 | 2011-08-30 19:12:10 +0000 | [diff] [blame] | 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" | 
|  | 78 | break | 
|  | 79 | end | 
|  | 80 | unless sh "make" | 
|  | 81 | $stderr.puts "make failed" | 
|  | 82 | break | 
|  | 83 | end | 
|  | 84 | end | 
|  | 85 | end | 
|  | 86 |  | 
|  | 87 | desc 'Run the compiler tests (requires full thrift checkout)' | 
|  | 88 | task :test do | 
|  | 89 | # ensure this is a full thrift checkout and not a tarball of the ruby libs | 
| Roger Meier | 401d399 | 2015-06-01 21:27:11 +0200 | [diff] [blame] | 90 | cmd = 'head -1 ../../README.md 2>/dev/null | grep Thrift >/dev/null 2>/dev/null' | 
| Jake Farrell | 9c39f77 | 2011-08-30 19:12:10 +0000 | [diff] [blame] | 91 | system(cmd) or fail "rake test requires a full thrift checkout" | 
|  | 92 | sh 'make', '-C', File.dirname(__FILE__) + "/../../test/rb", "check" | 
|  | 93 | end | 
|  | 94 |  | 
| Kevin Clark | ca8a1b3 | 2008-06-18 01:17:06 +0000 | [diff] [blame] | 95 | desc 'Run benchmarking of NonblockingServer' | 
|  | 96 | task :benchmark do | 
| Kevin Clark | d3cee02 | 2008-06-18 01:19:09 +0000 | [diff] [blame] | 97 | ruby 'benchmark/benchmark.rb' | 
| Kevin Clark | c2a07b1 | 2008-06-18 00:57:06 +0000 | [diff] [blame] | 98 | end | 
| Kevin Clark | 3a9ffbd | 2008-06-24 01:06:00 +0000 | [diff] [blame] | 99 |  | 
| Jake Farrell | 4bd4f0e | 2011-09-22 21:15:02 +0000 | [diff] [blame] | 100 | desc 'Builds the thrift gem' | 
|  | 101 | task :gem => [:spec, :build_ext] do | 
| Jake Farrell | 9c39f77 | 2011-08-30 19:12:10 +0000 | [diff] [blame] | 102 | unless sh 'gem', 'build', 'thrift.gemspec' | 
|  | 103 | $stderr.puts "Failed to build thrift gem" | 
|  | 104 | break | 
| Kevin Clark | 3a9ffbd | 2008-06-24 01:06:00 +0000 | [diff] [blame] | 105 | end | 
| Jake Farrell | 4bd4f0e | 2011-09-22 21:15:02 +0000 | [diff] [blame] | 106 | end | 
|  | 107 |  | 
|  | 108 | desc 'Install the thrift gem' | 
|  | 109 | task :install => [:gem] do | 
| Roger Meier | a510d6b | 2014-01-12 22:17:45 +0100 | [diff] [blame] | 110 | unless sh 'gem', 'install', Dir.glob('thrift-*.gem').last | 
| Jake Farrell | 9c39f77 | 2011-08-30 19:12:10 +0000 | [diff] [blame] | 111 | $stderr.puts "Failed to install thrift gem" | 
|  | 112 | break | 
| Kevin Clark | 3387115 | 2008-06-26 18:14:25 +0000 | [diff] [blame] | 113 | end | 
| Kevin Clark | 3a9ffbd | 2008-06-24 01:06:00 +0000 | [diff] [blame] | 114 | end | 
| Jake Farrell | 74362e0 | 2011-08-16 17:13:41 +0000 | [diff] [blame] | 115 |  | 
| Jake Farrell | f88f9c2 | 2012-09-02 03:26:50 +0000 | [diff] [blame] | 116 | CLEAN.include [ | 
|  | 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' | 
| Jake Farrell | 9c39f77 | 2011-08-30 19:12:10 +0000 | [diff] [blame] | 120 | ] |