blob: 02c98679e2eef27b5fa2051a0c4e9247138de1da [file] [log] [blame]
nnoble097ef9b2014-12-01 17:06:10 -08001# -*- ruby -*-
2require 'rake/extensiontask'
3require 'rspec/core/rake_task'
Tim Emiolae2860c52015-01-16 02:58:41 -08004require 'rubocop/rake_task'
Tim Emiolaf20d7602015-03-24 08:11:47 -07005require 'bundler/gem_tasks'
nnoble097ef9b2014-12-01 17:06:10 -08006
Tim Emiolaf20d7602015-03-24 08:11:47 -07007# Add rubocop style checking tasks
murgatroid99d7e1a102015-12-18 11:16:16 -08008RuboCop::RakeTask.new(:rubocop) do |task|
9 task.options = ['-c', 'src/ruby/.rubocop.yml']
10 task.patterns = ['src/ruby/{lib,spec}/**/*.rb']
11end
nnoble097ef9b2014-12-01 17:06:10 -080012
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010013spec = Gem::Specification.load('grpc.gemspec')
14
15Gem::PackageTask.new(spec) do |pkg|
16end
17
Tim Emiolaf20d7602015-03-24 08:11:47 -070018# Add the extension compiler task
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010019Rake::ExtensionTask.new('grpc', spec) do |ext|
murgatroid99d7e1a102015-12-18 11:16:16 -080020 ext.source_pattern = '**/*.{c,h}'
21 ext.ext_dir = File.join('src', 'ruby', 'ext', 'grpc')
22 ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc')
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010023 ext.cross_compile = true
24 ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
nnoble097ef9b2014-12-01 17:06:10 -080025end
26
Tim Emiolaf20d7602015-03-24 08:11:47 -070027# Define the test suites
nnoble097ef9b2014-12-01 17:06:10 -080028SPEC_SUITES = [
murgatroid99d7e1a102015-12-18 11:16:16 -080029 { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) },
30 { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080031 tags: ['~bidi', '~server'] },
murgatroid99d7e1a102015-12-18 11:16:16 -080032 { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080033 tag: 'bidi' },
murgatroid99d7e1a102015-12-18 11:16:16 -080034 { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic),
Tim Emiola975d0cb2015-08-14 10:44:17 -070035 tag: 'server' },
murgatroid99d7e1a102015-12-18 11:16:16 -080036 { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) }
nnoble097ef9b2014-12-01 17:06:10 -080037]
Tim Emiolaf20d7602015-03-24 08:11:47 -070038namespace :suite do
39 SPEC_SUITES.each do |suite|
40 desc "Run all specs in the #{suite[:title]} spec suite"
41 RSpec::Core::RakeTask.new(suite[:id]) do |t|
Tim Emiolac85c1ae2015-04-17 18:12:32 -070042 ENV['COVERAGE_NAME'] = suite[:id].to_s
Tim Emiolaf20d7602015-03-24 08:11:47 -070043 spec_files = []
44 suite[:files].each { |f| spec_files += Dir[f] } if suite[:files]
nnoble097ef9b2014-12-01 17:06:10 -080045
Tim Emiolaf20d7602015-03-24 08:11:47 -070046 if suite[:dir]
47 suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] }
48 end
murgatroid99d7e1a102015-12-18 11:16:16 -080049 helper = 'src/ruby/spec/spec_helper.rb'
Tim Emiolaf20d7602015-03-24 08:11:47 -070050 spec_files << helper unless spec_files.include?(helper)
nnoble097ef9b2014-12-01 17:06:10 -080051
Tim Emiolaf20d7602015-03-24 08:11:47 -070052 t.pattern = spec_files
53 t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag]
54 if suite[:tags]
55 t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ')
nnoble097ef9b2014-12-01 17:06:10 -080056 end
57 end
58 end
59end
60
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010061desc 'Build the gem file under rake_compiler_dock'
62task 'gem:windows' do
63 require 'digest'
64 require 'rake_compiler_dock'
Nicolas "Pixel" Noble17230442016-01-29 01:46:19 +010065
66 grpc_config = ENV['GRPC_CONFIG'] || 'opt'
67 V = ENV['V'] || '0'
68
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010069 version = Digest::SHA1.file('third_party/rake-compiler-dock/Dockerfile').hexdigest
70 image_name = 'grpc/rake-compiler-dock:' + version
71 cmd = "docker build -t #{image_name} third_party/rake-compiler-dock"
72 puts cmd
73 system cmd
74 exit 1 unless $? == 0
75 ENV['RAKE_COMPILER_DOCK_IMAGE'] = image_name
Nicolas "Pixel" Noble17230442016-01-29 01:46:19 +010076 RakeCompilerDock.sh "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6:2.0.0 GRPC_CONFIG=#{grpc_config} V=#{V}"
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010077end
78
Tim Emiolaf20d7602015-03-24 08:11:47 -070079# Define dependencies between the suites.
80task 'suite:wrapper' => [:compile, :rubocop]
81task 'suite:idiomatic' => 'suite:wrapper'
82task 'suite:bidi' => 'suite:wrapper'
83task 'suite:server' => 'suite:wrapper'
Tim Emiola975d0cb2015-08-14 10:44:17 -070084task 'suite:pb' => 'suite:server'
Tim Emiola397fda02015-01-29 13:26:21 -080085
Tim Emiolaf20d7602015-03-24 08:11:47 -070086desc 'Compiles the gRPC extension then runs all the tests'
Tim Emiola975d0cb2015-08-14 10:44:17 -070087task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server']
Tim Emiola397fda02015-01-29 13:26:21 -080088task default: :all