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 |
| 26 | ext.cross_platform = ['x86-mingw32', 'x64-mingw32'] |
Nicolas "Pixel" Noble | d51d121 | 2016-01-31 11:33:19 +0100 | [diff] [blame^] | 27 | ext.cross_compiling do |spec| |
| 28 | spec.files = %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby ) |
| 29 | spec.files += Dir.glob('src/ruby/bin/**/*') |
| 30 | spec.files += Dir.glob('src/ruby/ext/**/*') |
| 31 | spec.files += Dir.glob('src/ruby/lib/**/*') |
| 32 | spec.files += Dir.glob('src/ruby/pb/**/*') |
| 33 | end |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 34 | end |
| 35 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 36 | # Define the test suites |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 37 | SPEC_SUITES = [ |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 38 | { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) }, |
| 39 | { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic), |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 40 | tags: ['~bidi', '~server'] }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 41 | { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic), |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 42 | tag: 'bidi' }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 43 | { 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] | 44 | tag: 'server' }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 45 | { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) } |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 46 | ] |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 47 | namespace :suite do |
| 48 | SPEC_SUITES.each do |suite| |
| 49 | desc "Run all specs in the #{suite[:title]} spec suite" |
| 50 | RSpec::Core::RakeTask.new(suite[:id]) do |t| |
Tim Emiola | c85c1ae | 2015-04-17 18:12:32 -0700 | [diff] [blame] | 51 | ENV['COVERAGE_NAME'] = suite[:id].to_s |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 52 | spec_files = [] |
| 53 | suite[:files].each { |f| spec_files += Dir[f] } if suite[:files] |
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 | if suite[:dir] |
| 56 | suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] } |
| 57 | end |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 58 | helper = 'src/ruby/spec/spec_helper.rb' |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 59 | spec_files << helper unless spec_files.include?(helper) |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 60 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 61 | t.pattern = spec_files |
| 62 | t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag] |
| 63 | if suite[:tags] |
| 64 | t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ') |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 65 | end |
| 66 | end |
| 67 | end |
| 68 | end |
| 69 | |
Nicolas "Pixel" Noble | cb287a1 | 2016-01-28 05:01:01 +0100 | [diff] [blame] | 70 | desc 'Build the gem file under rake_compiler_dock' |
| 71 | task 'gem:windows' do |
Nicolas "Pixel" Noble | 1723044 | 2016-01-29 01:46:19 +0100 | [diff] [blame] | 72 | grpc_config = ENV['GRPC_CONFIG'] || 'opt' |
| 73 | V = ENV['V'] || '0' |
| 74 | |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 75 | env = 'CPPFLAGS="-D_WIN32_WINNT=0x600 -DUNICODE -D_UNICODE" ' |
Nicolas "Pixel" Noble | 0215d90 | 2016-01-31 09:57:07 +0100 | [diff] [blame] | 76 | env += 'LDFLAGS=-static ' |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 77 | env += 'SYSTEM=MINGW32 ' |
| 78 | env += 'EMBED_ZLIB=true ' |
| 79 | env += 'BUILDDIR=/tmp ' |
| 80 | out = '/tmp/libs/opt/grpc-0.dll' |
| 81 | |
| 82 | env_comp = 'CC=x86_64-w64-mingw32-gcc ' |
| 83 | env_comp += 'LD=x86_64-w64-mingw32-gcc ' |
Nicolas "Pixel" Noble | 0215d90 | 2016-01-31 09:57:07 +0100 | [diff] [blame] | 84 | docker_for_windows "#{env} #{env_comp} make -j #{out} && x86_64-w64-mingw32-strip -x -S #{out} && cp #{out} grpc_c.64.ruby" |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 85 | |
| 86 | env_comp = 'CC=i686-w64-mingw32-gcc ' |
| 87 | env_comp += 'LD=i686-w64-mingw32-gcc ' |
Nicolas "Pixel" Noble | 0215d90 | 2016-01-31 09:57:07 +0100 | [diff] [blame] | 88 | docker_for_windows "#{env} #{env_comp} make -j #{out} && i686-w64-mingw32-strip -x -S #{out} && cp #{out} grpc_c.32.ruby" |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 89 | |
| 90 | docker_for_windows "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" Noble | cb287a1 | 2016-01-28 05:01:01 +0100 | [diff] [blame] | 91 | end |
| 92 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 93 | # Define dependencies between the suites. |
| 94 | task 'suite:wrapper' => [:compile, :rubocop] |
| 95 | task 'suite:idiomatic' => 'suite:wrapper' |
| 96 | task 'suite:bidi' => 'suite:wrapper' |
| 97 | task 'suite:server' => 'suite:wrapper' |
Tim Emiola | 975d0cb | 2015-08-14 10:44:17 -0700 | [diff] [blame] | 98 | task 'suite:pb' => 'suite:server' |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 99 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 100 | desc 'Compiles the gRPC extension then runs all the tests' |
Tim Emiola | 975d0cb | 2015-08-14 10:44:17 -0700 | [diff] [blame] | 101 | task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server'] |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 102 | task default: :all |