2014-12-24 14:48:41 +00:00
|
|
|
require "rubygems"
|
|
|
|
require "rubygems/package_task"
|
|
|
|
require "rake/extensiontask" unless RUBY_PLATFORM == "java"
|
2014-11-18 22:19:58 +00:00
|
|
|
require "rake/testtask"
|
|
|
|
|
2014-12-12 23:58:26 +00:00
|
|
|
spec = Gem::Specification.load("google-protobuf.gemspec")
|
2014-11-18 22:19:58 +00:00
|
|
|
|
2016-04-29 18:00:43 +00:00
|
|
|
well_known_protos = %w[
|
|
|
|
google/protobuf/any.proto
|
|
|
|
google/protobuf/api.proto
|
|
|
|
google/protobuf/duration.proto
|
|
|
|
google/protobuf/empty.proto
|
|
|
|
google/protobuf/field_mask.proto
|
|
|
|
google/protobuf/source_context.proto
|
|
|
|
google/protobuf/struct.proto
|
|
|
|
google/protobuf/timestamp.proto
|
|
|
|
google/protobuf/type.proto
|
|
|
|
google/protobuf/wrappers.proto
|
|
|
|
]
|
|
|
|
|
|
|
|
# These are omitted for now because we don't support proto2.
|
|
|
|
proto2_protos = %w[
|
|
|
|
google/protobuf/descriptor.proto
|
|
|
|
google/protobuf/compiler/plugin.proto
|
|
|
|
]
|
|
|
|
|
|
|
|
genproto_output = []
|
|
|
|
|
2016-04-30 00:14:18 +00:00
|
|
|
# We won't have access to .. from within docker, but the proto files
|
|
|
|
# will be there, thanks to the :genproto rule dependency for gem:native.
|
2016-04-29 18:00:43 +00:00
|
|
|
unless ENV['IN_DOCKER'] == 'true'
|
|
|
|
well_known_protos.each do |proto_file|
|
|
|
|
input_file = "../src/" + proto_file
|
2016-07-25 08:47:50 +00:00
|
|
|
output_file = "lib/" + proto_file.sub(/\.proto$/, "_pb.rb")
|
2016-04-29 18:00:43 +00:00
|
|
|
genproto_output << output_file
|
|
|
|
file output_file => input_file do |file_task|
|
|
|
|
sh "../src/protoc -I../src --ruby_out=lib #{input_file}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-12-24 14:48:41 +00:00
|
|
|
if RUBY_PLATFORM == "java"
|
2015-05-01 18:54:29 +00:00
|
|
|
if `which mvn` == ''
|
|
|
|
raise ArgumentError, "maven needs to be installed"
|
|
|
|
end
|
2014-12-24 14:48:41 +00:00
|
|
|
task :clean do
|
2016-12-03 16:51:25 +00:00
|
|
|
system("mvn --batch-mode clean")
|
2014-12-24 14:48:41 +00:00
|
|
|
end
|
2014-11-18 22:19:58 +00:00
|
|
|
|
2014-12-24 14:48:41 +00:00
|
|
|
task :compile do
|
2016-12-03 16:51:25 +00:00
|
|
|
system("mvn --batch-mode package")
|
2014-12-24 14:48:41 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
Rake::ExtensionTask.new("protobuf_c", spec) do |ext|
|
2018-04-25 16:52:30 +00:00
|
|
|
unless RUBY_PLATFORM =~ /darwin/
|
|
|
|
# TODO: also set "no_native to true" for mac if possible. As is,
|
|
|
|
# "no_native" can only be set if the RUBY_PLATFORM doing
|
|
|
|
# cross-compilation is contained in the "ext.cross_platform" array.
|
|
|
|
ext.no_native = true
|
|
|
|
end
|
2014-12-24 14:48:41 +00:00
|
|
|
ext.ext_dir = "ext/google/protobuf_c"
|
|
|
|
ext.lib_dir = "lib/google"
|
2016-02-05 23:55:45 +00:00
|
|
|
ext.cross_compile = true
|
|
|
|
ext.cross_platform = [
|
|
|
|
'x86-mingw32', 'x64-mingw32',
|
|
|
|
'x86_64-linux', 'x86-linux',
|
|
|
|
'universal-darwin'
|
|
|
|
]
|
2014-12-24 14:48:41 +00:00
|
|
|
end
|
2016-02-04 18:44:22 +00:00
|
|
|
|
|
|
|
task 'gem:windows' do
|
|
|
|
require 'rake_compiler_dock'
|
2019-01-08 03:44:54 +00:00
|
|
|
RakeCompilerDock.sh "bundle && IN_DOCKER=true rake cross native gem RUBY_CC_VERSION=2.6.0:2.5.0:2.4.0:2.3.0"
|
2016-02-04 18:44:22 +00:00
|
|
|
end
|
2014-11-18 22:19:58 +00:00
|
|
|
|
2016-04-30 00:14:18 +00:00
|
|
|
if RUBY_PLATFORM =~ /darwin/
|
|
|
|
task 'gem:native' do
|
2016-05-04 00:29:17 +00:00
|
|
|
system "rake genproto"
|
2019-01-08 03:44:54 +00:00
|
|
|
system "rake cross native gem RUBY_CC_VERSION=2.6.0:2.5.1:2.4.0:2.3.0"
|
2016-04-30 00:14:18 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
task 'gem:native' => [:genproto, 'gem:windows']
|
|
|
|
end
|
2016-03-03 22:08:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Proto for tests.
|
|
|
|
genproto_output << "tests/generated_code.rb"
|
2017-08-25 19:11:15 +00:00
|
|
|
genproto_output << "tests/generated_code_proto2.rb"
|
2016-07-25 07:29:47 +00:00
|
|
|
genproto_output << "tests/test_import.rb"
|
2017-08-25 19:11:15 +00:00
|
|
|
genproto_output << "tests/test_import_proto2.rb"
|
2018-05-18 00:11:06 +00:00
|
|
|
genproto_output << "tests/test_ruby_package.rb"
|
2017-08-25 19:11:15 +00:00
|
|
|
genproto_output << "tests/test_ruby_package_proto2.rb"
|
|
|
|
genproto_output << "tests/basic_test.rb"
|
|
|
|
genproto_output << "tests/basic_test_proto2.rb"
|
2019-03-27 16:44:43 +00:00
|
|
|
genproto_output << "tests/wrappers.rb"
|
2016-03-03 22:08:54 +00:00
|
|
|
file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
|
|
|
|
sh "../src/protoc --ruby_out=. tests/generated_code.proto"
|
|
|
|
end
|
|
|
|
|
2017-08-25 19:11:15 +00:00
|
|
|
file "tests/generated_code_proto2.rb" => "tests/generated_code_proto2.proto" do |file_task|
|
|
|
|
sh "../src/protoc --ruby_out=. tests/generated_code_proto2.proto"
|
|
|
|
end
|
|
|
|
|
2016-07-25 07:29:47 +00:00
|
|
|
file "tests/test_import.rb" => "tests/test_import.proto" do |file_task|
|
|
|
|
sh "../src/protoc --ruby_out=. tests/test_import.proto"
|
|
|
|
end
|
|
|
|
|
2017-08-25 19:11:15 +00:00
|
|
|
file "tests/test_import_proto2.rb" => "tests/test_import_proto2.proto" do |file_task|
|
|
|
|
sh "../src/protoc --ruby_out=. tests/test_import_proto2.proto"
|
|
|
|
end
|
|
|
|
|
2018-05-18 00:11:06 +00:00
|
|
|
file "tests/test_ruby_package.rb" => "tests/test_ruby_package.proto" do |file_task|
|
|
|
|
sh "../src/protoc --ruby_out=. tests/test_ruby_package.proto"
|
|
|
|
end
|
|
|
|
|
2017-08-25 19:11:15 +00:00
|
|
|
file "tests/test_ruby_package_proto2.rb" => "tests/test_ruby_package_proto2.proto" do |file_task|
|
|
|
|
sh "../src/protoc --ruby_out=. tests/test_ruby_package_proto2.proto"
|
|
|
|
end
|
|
|
|
|
|
|
|
file "tests/basic_test.rb" => "tests/basic_test.proto" do |file_task|
|
2019-02-28 04:26:14 +00:00
|
|
|
sh "../src/protoc -I../src -I. --ruby_out=. tests/basic_test.proto"
|
2017-08-25 19:11:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
file "tests/basic_test_proto2.rb" => "tests/basic_test_proto2.proto" do |file_task|
|
2019-02-28 04:26:14 +00:00
|
|
|
sh "../src/protoc -I../src -I. --ruby_out=. tests/basic_test_proto2.proto"
|
2017-08-25 19:11:15 +00:00
|
|
|
end
|
|
|
|
|
2019-03-27 16:44:43 +00:00
|
|
|
file "tests/wrappers.rb" => "../src/google/protobuf/wrappers.proto" do |file_task|
|
|
|
|
sh "../src/protoc -I../src -I. --ruby_out=tests ../src/google/protobuf/wrappers.proto"
|
|
|
|
end
|
|
|
|
|
2016-03-03 22:08:54 +00:00
|
|
|
task :genproto => genproto_output
|
|
|
|
|
|
|
|
task :clean do
|
|
|
|
sh "rm -f #{genproto_output.join(' ')}"
|
|
|
|
end
|
|
|
|
|
2014-11-18 22:19:58 +00:00
|
|
|
Gem::PackageTask.new(spec) do |pkg|
|
|
|
|
end
|
|
|
|
|
2014-12-24 14:48:41 +00:00
|
|
|
Rake::TestTask.new(:test => :build) do |t|
|
2017-08-25 19:11:15 +00:00
|
|
|
t.test_files = FileList["tests/*.rb"].exclude("tests/gc_test.rb", "tests/common_tests.rb")
|
2017-10-04 00:28:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# gc_test needs to be split out to ensure the generated file hasn't been
|
|
|
|
# imported by other tests.
|
|
|
|
Rake::TestTask.new(:gc_test => :build) do |t|
|
|
|
|
t.test_files = FileList["tests/gc_test.rb"]
|
2014-12-24 14:48:41 +00:00
|
|
|
end
|
|
|
|
|
2016-03-03 22:08:54 +00:00
|
|
|
task :build => [:clean, :compile, :genproto]
|
2014-11-18 22:19:58 +00:00
|
|
|
task :default => [:build]
|
|
|
|
|
|
|
|
# vim:sw=2:et
|