nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 1 | # -*- ruby -*- |
| 2 | require 'rake/extensiontask' |
| 3 | require 'rspec/core/rake_task' |
Tim Emiola | e2860c5 | 2015-01-16 02:58:41 -0800 | [diff] [blame] | 4 | require 'rubocop/rake_task' |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 5 | require 'bundler/gem_tasks' |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 6 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 7 | # Add rubocop style checking tasks |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 8 | RuboCop::RakeTask.new(:rubocop) do |task| |
| 9 | task.options = ['-c', 'src/ruby/.rubocop.yml'] |
| 10 | task.patterns = ['src/ruby/{lib,spec}/**/*.rb'] |
| 11 | end |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 12 | |
Nicolas "Pixel" Noble | cb287a1 | 2016-01-28 05:01:01 +0100 | [diff] [blame^] | 13 | spec = Gem::Specification.load('grpc.gemspec') |
| 14 | |
| 15 | Gem::PackageTask.new(spec) do |pkg| |
| 16 | end |
| 17 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 18 | # Add the extension compiler task |
Nicolas "Pixel" Noble | cb287a1 | 2016-01-28 05:01:01 +0100 | [diff] [blame^] | 19 | Rake::ExtensionTask.new('grpc', spec) do |ext| |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 20 | 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" Noble | cb287a1 | 2016-01-28 05:01:01 +0100 | [diff] [blame^] | 23 | ext.cross_compile = true |
| 24 | ext.cross_platform = ['x86-mingw32', 'x64-mingw32'] |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 25 | end |
| 26 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 27 | # Define the test suites |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 28 | SPEC_SUITES = [ |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 29 | { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) }, |
| 30 | { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic), |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 31 | tags: ['~bidi', '~server'] }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 32 | { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic), |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 33 | tag: 'bidi' }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 34 | { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic), |
Tim Emiola | 975d0cb | 2015-08-14 10:44:17 -0700 | [diff] [blame] | 35 | tag: 'server' }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 36 | { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) } |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 37 | ] |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 38 | namespace :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 Emiola | c85c1ae | 2015-04-17 18:12:32 -0700 | [diff] [blame] | 42 | ENV['COVERAGE_NAME'] = suite[:id].to_s |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 43 | spec_files = [] |
| 44 | suite[:files].each { |f| spec_files += Dir[f] } if suite[:files] |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 45 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 46 | if suite[:dir] |
| 47 | suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] } |
| 48 | end |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 49 | helper = 'src/ruby/spec/spec_helper.rb' |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 50 | spec_files << helper unless spec_files.include?(helper) |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 51 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 52 | 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(' ') |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 56 | end |
| 57 | end |
| 58 | end |
| 59 | end |
| 60 | |
Nicolas "Pixel" Noble | cb287a1 | 2016-01-28 05:01:01 +0100 | [diff] [blame^] | 61 | desc 'Build the gem file under rake_compiler_dock' |
| 62 | task 'gem:windows' do |
| 63 | require 'digest' |
| 64 | require 'rake_compiler_dock' |
| 65 | version = Digest::SHA1.file('third_party/rake-compiler-dock/Dockerfile').hexdigest |
| 66 | image_name = 'grpc/rake-compiler-dock:' + version |
| 67 | cmd = "docker build -t #{image_name} third_party/rake-compiler-dock" |
| 68 | puts cmd |
| 69 | system cmd |
| 70 | exit 1 unless $? == 0 |
| 71 | ENV['RAKE_COMPILER_DOCK_IMAGE'] = image_name |
| 72 | RakeCompilerDock.sh "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6:2.0.0" |
| 73 | end |
| 74 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 75 | # Define dependencies between the suites. |
| 76 | task 'suite:wrapper' => [:compile, :rubocop] |
| 77 | task 'suite:idiomatic' => 'suite:wrapper' |
| 78 | task 'suite:bidi' => 'suite:wrapper' |
| 79 | task 'suite:server' => 'suite:wrapper' |
Tim Emiola | 975d0cb | 2015-08-14 10:44:17 -0700 | [diff] [blame] | 80 | task 'suite:pb' => 'suite:server' |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 81 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 82 | desc 'Compiles the gRPC extension then runs all the tests' |
Tim Emiola | 975d0cb | 2015-08-14 10:44:17 -0700 | [diff] [blame] | 83 | task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server'] |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 84 | task default: :all |