Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 1 | require "rubygems" |
| 2 | require "rubygems/package_task" |
| 3 | require "rake/extensiontask" unless RUBY_PLATFORM == "java" |
Chris Fallin | 973f425 | 2014-11-18 14:19:58 -0800 | [diff] [blame] | 4 | require "rake/testtask" |
| 5 | |
Chris Fallin | 91473dc | 2014-12-12 15:58:26 -0800 | [diff] [blame] | 6 | spec = Gem::Specification.load("google-protobuf.gemspec") |
Chris Fallin | 973f425 | 2014-11-18 14:19:58 -0800 | [diff] [blame] | 7 | |
Nicolas "Pixel" Noble | 1f8b6da | 2016-04-29 20:00:43 +0200 | [diff] [blame] | 8 | well_known_protos = %w[ |
| 9 | google/protobuf/any.proto |
| 10 | google/protobuf/api.proto |
| 11 | google/protobuf/duration.proto |
| 12 | google/protobuf/empty.proto |
| 13 | google/protobuf/field_mask.proto |
| 14 | google/protobuf/source_context.proto |
| 15 | google/protobuf/struct.proto |
| 16 | google/protobuf/timestamp.proto |
| 17 | google/protobuf/type.proto |
| 18 | google/protobuf/wrappers.proto |
| 19 | ] |
| 20 | |
| 21 | # These are omitted for now because we don't support proto2. |
| 22 | proto2_protos = %w[ |
| 23 | google/protobuf/descriptor.proto |
| 24 | google/protobuf/compiler/plugin.proto |
| 25 | ] |
| 26 | |
| 27 | genproto_output = [] |
| 28 | |
Nicolas "Pixel" Noble | 236b939 | 2016-04-30 02:14:18 +0200 | [diff] [blame] | 29 | # We won't have access to .. from within docker, but the proto files |
| 30 | # will be there, thanks to the :genproto rule dependency for gem:native. |
Nicolas "Pixel" Noble | 1f8b6da | 2016-04-29 20:00:43 +0200 | [diff] [blame] | 31 | unless ENV['IN_DOCKER'] == 'true' |
| 32 | well_known_protos.each do |proto_file| |
| 33 | input_file = "../src/" + proto_file |
Colin Cross | dc38447 | 2018-11-04 17:34:26 -0800 | [diff] [blame] | 34 | output_file = "lib/" + proto_file.sub(/\.proto$/, ".rb") |
Nicolas "Pixel" Noble | 1f8b6da | 2016-04-29 20:00:43 +0200 | [diff] [blame] | 35 | genproto_output << output_file |
| 36 | file output_file => input_file do |file_task| |
| 37 | sh "../src/protoc -I../src --ruby_out=lib #{input_file}" |
| 38 | end |
| 39 | end |
| 40 | end |
| 41 | |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 42 | if RUBY_PLATFORM == "java" |
Adam Greene | d55733c | 2015-05-01 11:54:29 -0700 | [diff] [blame] | 43 | if `which mvn` == '' |
| 44 | raise ArgumentError, "maven needs to be installed" |
| 45 | end |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 46 | task :clean do |
Colin Cross | dc38447 | 2018-11-04 17:34:26 -0800 | [diff] [blame] | 47 | system("mvn clean") |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 48 | end |
| 49 | |
| 50 | task :compile do |
Colin Cross | dc38447 | 2018-11-04 17:34:26 -0800 | [diff] [blame] | 51 | system("mvn package") |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 52 | end |
| 53 | else |
| 54 | Rake::ExtensionTask.new("protobuf_c", spec) do |ext| |
| 55 | ext.ext_dir = "ext/google/protobuf_c" |
| 56 | ext.lib_dir = "lib/google" |
Nicolas "Pixel" Noble | bbb188a | 2016-02-06 00:55:45 +0100 | [diff] [blame] | 57 | ext.cross_compile = true |
| 58 | ext.cross_platform = [ |
| 59 | 'x86-mingw32', 'x64-mingw32', |
| 60 | 'x86_64-linux', 'x86-linux', |
| 61 | 'universal-darwin' |
| 62 | ] |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 63 | end |
Josh Haberman | af4aa9b | 2016-02-04 10:44:22 -0800 | [diff] [blame] | 64 | |
| 65 | task 'gem:windows' do |
| 66 | require 'rake_compiler_dock' |
Colin Cross | dc38447 | 2018-11-04 17:34:26 -0800 | [diff] [blame] | 67 | RakeCompilerDock.sh "bundle && IN_DOCKER=true rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.5:2.0.0" |
Josh Haberman | af4aa9b | 2016-02-04 10:44:22 -0800 | [diff] [blame] | 68 | end |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 69 | |
Nicolas "Pixel" Noble | 236b939 | 2016-04-30 02:14:18 +0200 | [diff] [blame] | 70 | if RUBY_PLATFORM =~ /darwin/ |
| 71 | task 'gem:native' do |
Nicolas "Pixel" Noble | edd2949 | 2016-05-04 02:29:17 +0200 | [diff] [blame] | 72 | system "rake genproto" |
Colin Cross | dc38447 | 2018-11-04 17:34:26 -0800 | [diff] [blame] | 73 | system "rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.5:2.0.0" |
Nicolas "Pixel" Noble | 236b939 | 2016-04-30 02:14:18 +0200 | [diff] [blame] | 74 | end |
| 75 | else |
| 76 | task 'gem:native' => [:genproto, 'gem:windows'] |
| 77 | end |
Josh Haberman | 513875d | 2016-03-03 14:08:54 -0800 | [diff] [blame] | 78 | end |
| 79 | |
| 80 | |
| 81 | # Proto for tests. |
| 82 | genproto_output << "tests/generated_code.rb" |
Josh Haberman | 513875d | 2016-03-03 14:08:54 -0800 | [diff] [blame] | 83 | file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task| |
| 84 | sh "../src/protoc --ruby_out=. tests/generated_code.proto" |
| 85 | end |
| 86 | |
Josh Haberman | 513875d | 2016-03-03 14:08:54 -0800 | [diff] [blame] | 87 | task :genproto => genproto_output |
| 88 | |
| 89 | task :clean do |
| 90 | sh "rm -f #{genproto_output.join(' ')}" |
| 91 | end |
| 92 | |
Isaiah Peng | 27e2b57 | 2014-12-24 15:48:41 +0100 | [diff] [blame] | 93 | Gem::PackageTask.new(spec) do |pkg| |
Chris Fallin | 973f425 | 2014-11-18 14:19:58 -0800 | [diff] [blame] | 94 | end |
| 95 | |
| 96 | Rake::TestTask.new(:test => :build) do |t| |
Colin Cross | dc38447 | 2018-11-04 17:34:26 -0800 | [diff] [blame] | 97 | t.test_files = FileList["tests/*.rb"] |
Chris Fallin | 973f425 | 2014-11-18 14:19:58 -0800 | [diff] [blame] | 98 | end |
| 99 | |
Josh Haberman | 513875d | 2016-03-03 14:08:54 -0800 | [diff] [blame] | 100 | task :build => [:clean, :compile, :genproto] |
Chris Fallin | 973f425 | 2014-11-18 14:19:58 -0800 | [diff] [blame] | 101 | task :default => [:build] |
| 102 | |
| 103 | # vim:sw=2:et |