1ffe3c632Sopenharmony_cirequire "rubygems" 2ffe3c632Sopenharmony_cirequire "rubygems/package_task" 3ffe3c632Sopenharmony_cirequire "rake/extensiontask" unless RUBY_PLATFORM == "java" 4ffe3c632Sopenharmony_cirequire "rake/testtask" 5ffe3c632Sopenharmony_ci 6ffe3c632Sopenharmony_cispec = Gem::Specification.load("google-protobuf.gemspec") 7ffe3c632Sopenharmony_ci 8ffe3c632Sopenharmony_ciwell_known_protos = %w[ 9ffe3c632Sopenharmony_ci google/protobuf/any.proto 10ffe3c632Sopenharmony_ci google/protobuf/api.proto 11ffe3c632Sopenharmony_ci google/protobuf/duration.proto 12ffe3c632Sopenharmony_ci google/protobuf/empty.proto 13ffe3c632Sopenharmony_ci google/protobuf/field_mask.proto 14ffe3c632Sopenharmony_ci google/protobuf/source_context.proto 15ffe3c632Sopenharmony_ci google/protobuf/struct.proto 16ffe3c632Sopenharmony_ci google/protobuf/timestamp.proto 17ffe3c632Sopenharmony_ci google/protobuf/type.proto 18ffe3c632Sopenharmony_ci google/protobuf/wrappers.proto 19ffe3c632Sopenharmony_ci] 20ffe3c632Sopenharmony_ci 21ffe3c632Sopenharmony_ci# These are omitted for now because we don't support proto2. 22ffe3c632Sopenharmony_ciproto2_protos = %w[ 23ffe3c632Sopenharmony_ci google/protobuf/descriptor.proto 24ffe3c632Sopenharmony_ci google/protobuf/compiler/plugin.proto 25ffe3c632Sopenharmony_ci] 26ffe3c632Sopenharmony_ci 27ffe3c632Sopenharmony_cigenproto_output = [] 28ffe3c632Sopenharmony_ci 29ffe3c632Sopenharmony_ci# We won't have access to .. from within docker, but the proto files 30ffe3c632Sopenharmony_ci# will be there, thanks to the :genproto rule dependency for gem:native. 31ffe3c632Sopenharmony_ciunless ENV['IN_DOCKER'] == 'true' 32ffe3c632Sopenharmony_ci well_known_protos.each do |proto_file| 33ffe3c632Sopenharmony_ci input_file = "../src/" + proto_file 34ffe3c632Sopenharmony_ci output_file = "lib/" + proto_file.sub(/\.proto$/, "_pb.rb") 35ffe3c632Sopenharmony_ci genproto_output << output_file 36ffe3c632Sopenharmony_ci file output_file => input_file do |file_task| 37ffe3c632Sopenharmony_ci sh "../src/protoc -I../src --ruby_out=lib #{input_file}" 38ffe3c632Sopenharmony_ci end 39ffe3c632Sopenharmony_ci end 40ffe3c632Sopenharmony_ciend 41ffe3c632Sopenharmony_ci 42ffe3c632Sopenharmony_ciif RUBY_PLATFORM == "java" 43ffe3c632Sopenharmony_ci if `which mvn` == '' 44ffe3c632Sopenharmony_ci raise ArgumentError, "maven needs to be installed" 45ffe3c632Sopenharmony_ci end 46ffe3c632Sopenharmony_ci task :clean do 47ffe3c632Sopenharmony_ci system("mvn --batch-mode clean") 48ffe3c632Sopenharmony_ci end 49ffe3c632Sopenharmony_ci 50ffe3c632Sopenharmony_ci task :compile do 51ffe3c632Sopenharmony_ci system("mvn --batch-mode package") 52ffe3c632Sopenharmony_ci end 53ffe3c632Sopenharmony_cielse 54ffe3c632Sopenharmony_ci Rake::ExtensionTask.new("protobuf_c", spec) do |ext| 55ffe3c632Sopenharmony_ci unless RUBY_PLATFORM =~ /darwin/ 56ffe3c632Sopenharmony_ci # TODO: also set "no_native to true" for mac if possible. As is, 57ffe3c632Sopenharmony_ci # "no_native" can only be set if the RUBY_PLATFORM doing 58ffe3c632Sopenharmony_ci # cross-compilation is contained in the "ext.cross_platform" array. 59ffe3c632Sopenharmony_ci ext.no_native = true 60ffe3c632Sopenharmony_ci end 61ffe3c632Sopenharmony_ci ext.ext_dir = "ext/google/protobuf_c" 62ffe3c632Sopenharmony_ci ext.lib_dir = "lib/google" 63ffe3c632Sopenharmony_ci ext.cross_compile = true 64ffe3c632Sopenharmony_ci ext.cross_platform = [ 65ffe3c632Sopenharmony_ci 'x86-mingw32', 'x64-mingw32', 66ffe3c632Sopenharmony_ci 'x86_64-linux', 'x86-linux', 67ffe3c632Sopenharmony_ci 'universal-darwin' 68ffe3c632Sopenharmony_ci ] 69ffe3c632Sopenharmony_ci end 70ffe3c632Sopenharmony_ci 71ffe3c632Sopenharmony_ci task 'gem:windows' do 72ffe3c632Sopenharmony_ci require 'rake_compiler_dock' 73ffe3c632Sopenharmony_ci ['x86-mingw32', 'x64-mingw32', 'x86_64-linux', 'x86-linux'].each do |plat| 74ffe3c632Sopenharmony_ci RakeCompilerDock.sh <<-"EOT", platform: plat 75ffe3c632Sopenharmony_ci bundle && \ 76ffe3c632Sopenharmony_ci IN_DOCKER=true rake native:#{plat} pkg/#{spec.full_name}-#{plat}.gem RUBY_CC_VERSION=2.7.0:2.6.0:2.5.0:2.4.0:2.3.0 77ffe3c632Sopenharmony_ci EOT 78ffe3c632Sopenharmony_ci end 79ffe3c632Sopenharmony_ci end 80ffe3c632Sopenharmony_ci 81ffe3c632Sopenharmony_ci if RUBY_PLATFORM =~ /darwin/ 82ffe3c632Sopenharmony_ci task 'gem:native' do 83ffe3c632Sopenharmony_ci system "rake genproto" 84ffe3c632Sopenharmony_ci system "rake cross native gem RUBY_CC_VERSION=2.7.0:2.6.0:2.5.1:2.4.0:2.3.0" 85ffe3c632Sopenharmony_ci end 86ffe3c632Sopenharmony_ci else 87ffe3c632Sopenharmony_ci task 'gem:native' => [:genproto, 'gem:windows'] 88ffe3c632Sopenharmony_ci end 89ffe3c632Sopenharmony_ciend 90ffe3c632Sopenharmony_ci 91ffe3c632Sopenharmony_ci 92ffe3c632Sopenharmony_ci# Proto for tests. 93ffe3c632Sopenharmony_cigenproto_output << "tests/generated_code.rb" 94ffe3c632Sopenharmony_cigenproto_output << "tests/generated_code_proto2.rb" 95ffe3c632Sopenharmony_cigenproto_output << "tests/test_import.rb" 96ffe3c632Sopenharmony_cigenproto_output << "tests/test_import_proto2.rb" 97ffe3c632Sopenharmony_cigenproto_output << "tests/test_ruby_package.rb" 98ffe3c632Sopenharmony_cigenproto_output << "tests/test_ruby_package_proto2.rb" 99ffe3c632Sopenharmony_cigenproto_output << "tests/basic_test.rb" 100ffe3c632Sopenharmony_cigenproto_output << "tests/basic_test_proto2.rb" 101ffe3c632Sopenharmony_cigenproto_output << "tests/wrappers.rb" 102ffe3c632Sopenharmony_cifile "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task| 103ffe3c632Sopenharmony_ci sh "../src/protoc --ruby_out=. tests/generated_code.proto" 104ffe3c632Sopenharmony_ciend 105ffe3c632Sopenharmony_ci 106ffe3c632Sopenharmony_cifile "tests/generated_code_proto2.rb" => "tests/generated_code_proto2.proto" do |file_task| 107ffe3c632Sopenharmony_ci sh "../src/protoc --ruby_out=. tests/generated_code_proto2.proto" 108ffe3c632Sopenharmony_ciend 109ffe3c632Sopenharmony_ci 110ffe3c632Sopenharmony_cifile "tests/test_import.rb" => "tests/test_import.proto" do |file_task| 111ffe3c632Sopenharmony_ci sh "../src/protoc --ruby_out=. tests/test_import.proto" 112ffe3c632Sopenharmony_ciend 113ffe3c632Sopenharmony_ci 114ffe3c632Sopenharmony_cifile "tests/test_import_proto2.rb" => "tests/test_import_proto2.proto" do |file_task| 115ffe3c632Sopenharmony_ci sh "../src/protoc --ruby_out=. tests/test_import_proto2.proto" 116ffe3c632Sopenharmony_ciend 117ffe3c632Sopenharmony_ci 118ffe3c632Sopenharmony_cifile "tests/test_ruby_package.rb" => "tests/test_ruby_package.proto" do |file_task| 119ffe3c632Sopenharmony_ci sh "../src/protoc --ruby_out=. tests/test_ruby_package.proto" 120ffe3c632Sopenharmony_ciend 121ffe3c632Sopenharmony_ci 122ffe3c632Sopenharmony_cifile "tests/test_ruby_package_proto2.rb" => "tests/test_ruby_package_proto2.proto" do |file_task| 123ffe3c632Sopenharmony_ci sh "../src/protoc --ruby_out=. tests/test_ruby_package_proto2.proto" 124ffe3c632Sopenharmony_ciend 125ffe3c632Sopenharmony_ci 126ffe3c632Sopenharmony_cifile "tests/basic_test.rb" => "tests/basic_test.proto" do |file_task| 127ffe3c632Sopenharmony_ci sh "../src/protoc --experimental_allow_proto3_optional -I../src -I. --ruby_out=. tests/basic_test.proto" 128ffe3c632Sopenharmony_ciend 129ffe3c632Sopenharmony_ci 130ffe3c632Sopenharmony_cifile "tests/basic_test_proto2.rb" => "tests/basic_test_proto2.proto" do |file_task| 131ffe3c632Sopenharmony_ci sh "../src/protoc -I../src -I. --ruby_out=. tests/basic_test_proto2.proto" 132ffe3c632Sopenharmony_ciend 133ffe3c632Sopenharmony_ci 134ffe3c632Sopenharmony_cifile "tests/wrappers.rb" => "../src/google/protobuf/wrappers.proto" do |file_task| 135ffe3c632Sopenharmony_ci sh "../src/protoc -I../src -I. --ruby_out=tests ../src/google/protobuf/wrappers.proto" 136ffe3c632Sopenharmony_ciend 137ffe3c632Sopenharmony_ci 138ffe3c632Sopenharmony_citask :genproto => genproto_output 139ffe3c632Sopenharmony_ci 140ffe3c632Sopenharmony_citask :clean do 141ffe3c632Sopenharmony_ci sh "rm -f #{genproto_output.join(' ')}" 142ffe3c632Sopenharmony_ciend 143ffe3c632Sopenharmony_ci 144ffe3c632Sopenharmony_ciGem::PackageTask.new(spec) do |pkg| 145ffe3c632Sopenharmony_ciend 146ffe3c632Sopenharmony_ci 147ffe3c632Sopenharmony_ciRake::TestTask.new(:test => :build) do |t| 148ffe3c632Sopenharmony_ci t.test_files = FileList["tests/*.rb"].exclude("tests/gc_test.rb", "tests/common_tests.rb") 149ffe3c632Sopenharmony_ciend 150ffe3c632Sopenharmony_ci 151ffe3c632Sopenharmony_ci# gc_test needs to be split out to ensure the generated file hasn't been 152ffe3c632Sopenharmony_ci# imported by other tests. 153ffe3c632Sopenharmony_ciRake::TestTask.new(:gc_test => :build) do |t| 154ffe3c632Sopenharmony_ci t.test_files = FileList["tests/gc_test.rb"] 155ffe3c632Sopenharmony_ciend 156ffe3c632Sopenharmony_ci 157ffe3c632Sopenharmony_citask :build => [:clean, :compile, :genproto] 158ffe3c632Sopenharmony_citask :default => [:build] 159ffe3c632Sopenharmony_ci 160ffe3c632Sopenharmony_ci# vim:sw=2:et 161