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 | |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 7 | load 'tools/distrib/docker_for_windows.rb' |
| 8 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 9 | # Add rubocop style checking tasks |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 10 | RuboCop::RakeTask.new(:rubocop) do |task| |
| 11 | task.options = ['-c', 'src/ruby/.rubocop.yml'] |
| 12 | task.patterns = ['src/ruby/{lib,spec}/**/*.rb'] |
| 13 | end |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 14 | |
Nicolas "Pixel" Noble | cb287a1 | 2016-01-28 05:01:01 +0100 | [diff] [blame] | 15 | spec = Gem::Specification.load('grpc.gemspec') |
| 16 | |
| 17 | Gem::PackageTask.new(spec) do |pkg| |
| 18 | end |
| 19 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 20 | # Add the extension compiler task |
Nicolas "Pixel" Noble | eade6e0 | 2016-01-29 22:53:31 +0100 | [diff] [blame] | 21 | Rake::ExtensionTask.new('grpc_c', spec) do |ext| |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 22 | ext.source_pattern = '**/*.{c,h}' |
| 23 | ext.ext_dir = File.join('src', 'ruby', 'ext', 'grpc') |
| 24 | ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc') |
Nicolas "Pixel" Noble | cb287a1 | 2016-01-28 05:01:01 +0100 | [diff] [blame] | 25 | ext.cross_compile = true |
Nicolas "Pixel" Noble | 5219c6d | 2016-02-05 22:22:29 +0100 | [diff] [blame^] | 26 | ext.cross_platform = [ |
| 27 | 'x86-mingw32', 'x64-mingw32', |
| 28 | 'x86_64-linux', 'x86-linux', |
| 29 | 'x86_64-darwin-11', |
| 30 | 'x86_64-darwin-12', |
| 31 | 'x86_64-darwin-13', |
| 32 | 'x86_64-darwin-14', |
| 33 | 'x86_64-darwin-15' |
| 34 | ] |
Nicolas "Pixel" Noble | d51d121 | 2016-01-31 11:33:19 +0100 | [diff] [blame] | 35 | ext.cross_compiling do |spec| |
| 36 | spec.files = %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby ) |
| 37 | spec.files += Dir.glob('src/ruby/bin/**/*') |
| 38 | spec.files += Dir.glob('src/ruby/ext/**/*') |
| 39 | spec.files += Dir.glob('src/ruby/lib/**/*') |
| 40 | spec.files += Dir.glob('src/ruby/pb/**/*') |
| 41 | end |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 42 | end |
| 43 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 44 | # Define the test suites |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 45 | SPEC_SUITES = [ |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 46 | { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) }, |
| 47 | { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic), |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 48 | tags: ['~bidi', '~server'] }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 49 | { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic), |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 50 | tag: 'bidi' }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 51 | { 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] | 52 | tag: 'server' }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 53 | { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) } |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 54 | ] |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 55 | namespace :suite do |
| 56 | SPEC_SUITES.each do |suite| |
| 57 | desc "Run all specs in the #{suite[:title]} spec suite" |
| 58 | RSpec::Core::RakeTask.new(suite[:id]) do |t| |
Tim Emiola | c85c1ae | 2015-04-17 18:12:32 -0700 | [diff] [blame] | 59 | ENV['COVERAGE_NAME'] = suite[:id].to_s |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 60 | spec_files = [] |
| 61 | suite[:files].each { |f| spec_files += Dir[f] } if suite[:files] |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 62 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 63 | if suite[:dir] |
| 64 | suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] } |
| 65 | end |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 66 | helper = 'src/ruby/spec/spec_helper.rb' |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 67 | spec_files << helper unless spec_files.include?(helper) |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 68 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 69 | t.pattern = spec_files |
| 70 | t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag] |
| 71 | if suite[:tags] |
| 72 | t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ') |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 73 | end |
| 74 | end |
| 75 | end |
| 76 | end |
| 77 | |
Nicolas "Pixel" Noble | f08399f | 2016-01-31 23:54:38 +0100 | [diff] [blame] | 78 | desc 'Build the Windows gRPC DLLs for Ruby' |
| 79 | task 'dlls' do |
Nicolas "Pixel" Noble | 1723044 | 2016-01-29 01:46:19 +0100 | [diff] [blame] | 80 | grpc_config = ENV['GRPC_CONFIG'] || 'opt' |
Nicolas "Pixel" Noble | 89d8ed1 | 2016-02-03 01:12:14 +0100 | [diff] [blame] | 81 | verbose = ENV['V'] || '0' |
Nicolas "Pixel" Noble | 1723044 | 2016-01-29 01:46:19 +0100 | [diff] [blame] | 82 | |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 83 | env = 'CPPFLAGS="-D_WIN32_WINNT=0x600 -DUNICODE -D_UNICODE" ' |
Nicolas "Pixel" Noble | 0215d90 | 2016-01-31 09:57:07 +0100 | [diff] [blame] | 84 | env += 'LDFLAGS=-static ' |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 85 | env += 'SYSTEM=MINGW32 ' |
| 86 | env += 'EMBED_ZLIB=true ' |
| 87 | env += 'BUILDDIR=/tmp ' |
Nicolas "Pixel" Noble | 89d8ed1 | 2016-02-03 01:12:14 +0100 | [diff] [blame] | 88 | env += "V=#{verbose} " |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 89 | out = '/tmp/libs/opt/grpc-0.dll' |
| 90 | |
Nicolas "Pixel" Noble | f08399f | 2016-01-31 23:54:38 +0100 | [diff] [blame] | 91 | w64 = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64.ruby' } |
| 92 | w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby' } |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 93 | |
Nicolas "Pixel" Noble | f08399f | 2016-01-31 23:54:38 +0100 | [diff] [blame] | 94 | [ w64, w32 ].each do |opt| |
| 95 | env_comp = "CC=#{opt[:cross]}-gcc " |
| 96 | env_comp += "LD=#{opt[:cross]}-gcc " |
| 97 | docker_for_windows "#{env} #{env_comp} make -j #{out} && #{opt[:cross]}-strip -x -S #{out} && cp #{out} #{opt[:out]}" |
| 98 | end |
| 99 | |
| 100 | end |
| 101 | |
Nicolas "Pixel" Noble | 5219c6d | 2016-02-05 22:22:29 +0100 | [diff] [blame^] | 102 | desc 'Build the native gem file under rake_compiler_dock' |
| 103 | task 'gem:native' do |
Nicolas "Pixel" Noble | 89d8ed1 | 2016-02-03 01:12:14 +0100 | [diff] [blame] | 104 | verbose = ENV['V'] || '0' |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 105 | |
Nicolas "Pixel" Noble | 89d8ed1 | 2016-02-03 01:12:14 +0100 | [diff] [blame] | 106 | docker_for_windows "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6:2.0.0 V=#{verbose}" |
Nicolas "Pixel" Noble | cb287a1 | 2016-01-28 05:01:01 +0100 | [diff] [blame] | 107 | end |
| 108 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 109 | # Define dependencies between the suites. |
| 110 | task 'suite:wrapper' => [:compile, :rubocop] |
| 111 | task 'suite:idiomatic' => 'suite:wrapper' |
| 112 | task 'suite:bidi' => 'suite:wrapper' |
| 113 | task 'suite:server' => 'suite:wrapper' |
Tim Emiola | 975d0cb | 2015-08-14 10:44:17 -0700 | [diff] [blame] | 114 | task 'suite:pb' => 'suite:server' |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 115 | |
Nicolas "Pixel" Noble | 5219c6d | 2016-02-05 22:22:29 +0100 | [diff] [blame^] | 116 | task 'gem:native' => 'dlls' |
Nicolas "Pixel" Noble | 89d8ed1 | 2016-02-03 01:12:14 +0100 | [diff] [blame] | 117 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 118 | desc 'Compiles the gRPC extension then runs all the tests' |
Tim Emiola | 975d0cb | 2015-08-14 10:44:17 -0700 | [diff] [blame] | 119 | task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server'] |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 120 | task default: :all |