OLD | NEW |
1 require "rubygems" | 1 require "rubygems" |
2 require "rubygems/package_task" | 2 require "rubygems/package_task" |
3 require "rake/extensiontask" unless RUBY_PLATFORM == "java" | 3 require "rake/extensiontask" unless RUBY_PLATFORM == "java" |
4 require "rake/testtask" | 4 require "rake/testtask" |
5 | 5 |
6 spec = Gem::Specification.load("google-protobuf.gemspec") | 6 spec = Gem::Specification.load("google-protobuf.gemspec") |
7 | 7 |
| 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 |
| 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. |
| 31 unless ENV['IN_DOCKER'] == 'true' |
| 32 well_known_protos.each do |proto_file| |
| 33 input_file = "../src/" + proto_file |
| 34 output_file = "lib/" + proto_file.sub(/\.proto$/, ".rb") |
| 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 |
8 if RUBY_PLATFORM == "java" | 42 if RUBY_PLATFORM == "java" |
9 if `which mvn` == '' | 43 if `which mvn` == '' |
10 raise ArgumentError, "maven needs to be installed" | 44 raise ArgumentError, "maven needs to be installed" |
11 end | 45 end |
12 task :clean do | 46 task :clean do |
13 system("mvn clean") | 47 system("mvn clean") |
14 end | 48 end |
15 | 49 |
16 task :compile do | 50 task :compile do |
17 system("mvn package") | 51 system("mvn package") |
18 end | 52 end |
19 else | 53 else |
20 Rake::ExtensionTask.new("protobuf_c", spec) do |ext| | 54 Rake::ExtensionTask.new("protobuf_c", spec) do |ext| |
21 ext.ext_dir = "ext/google/protobuf_c" | 55 ext.ext_dir = "ext/google/protobuf_c" |
22 ext.lib_dir = "lib/google" | 56 ext.lib_dir = "lib/google" |
| 57 ext.cross_compile = true |
| 58 ext.cross_platform = [ |
| 59 'x86-mingw32', 'x64-mingw32', |
| 60 'x86_64-linux', 'x86-linux', |
| 61 'universal-darwin' |
| 62 ] |
| 63 end |
| 64 |
| 65 task 'gem:windows' do |
| 66 require 'rake_compiler_dock' |
| 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" |
| 68 end |
| 69 |
| 70 if RUBY_PLATFORM =~ /darwin/ |
| 71 task 'gem:native' do |
| 72 system "rake genproto" |
| 73 system "rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.5:2.0.0" |
| 74 end |
| 75 else |
| 76 task 'gem:native' => [:genproto, 'gem:windows'] |
23 end | 77 end |
24 end | 78 end |
25 | 79 |
| 80 |
| 81 # Proto for tests. |
| 82 genproto_output << "tests/generated_code.rb" |
| 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 |
| 87 task :genproto => genproto_output |
| 88 |
| 89 task :clean do |
| 90 sh "rm -f #{genproto_output.join(' ')}" |
| 91 end |
| 92 |
26 Gem::PackageTask.new(spec) do |pkg| | 93 Gem::PackageTask.new(spec) do |pkg| |
27 end | 94 end |
28 | 95 |
29 Rake::TestTask.new(:test => :build) do |t| | 96 Rake::TestTask.new(:test => :build) do |t| |
30 t.test_files = FileList["tests/*.rb"] | 97 t.test_files = FileList["tests/*.rb"] |
31 end | 98 end |
32 | 99 |
33 task :build => [:clean, :compile] | 100 task :build => [:clean, :compile, :genproto] |
34 task :default => [:build] | 101 task :default => [:build] |
35 | 102 |
36 # vim:sw=2:et | 103 # vim:sw=2:et |
OLD | NEW |