1# Copyright 2018 gRPC authors. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15require 'open3' 16require 'tmpdir' 17 18def main 19 root_dir = File.join(File.dirname(__FILE__), '..', '..', '..') 20 pb_dir = File.join(root_dir, 'src', 'ruby', 'end2end', 'protos') 21 22 fail 'CONFIG env variable unexpectedly unset' unless ENV['CONFIG'] 23 bins_sub_dir = ENV['CONFIG'] 24 bins_dir = File.join(root_dir, 'bins', bins_sub_dir) 25 26 plugin = File.join(bins_dir, 'grpc_ruby_plugin') 27 protoc = File.join(bins_dir, 'protobuf', 'protoc') 28 29 got = nil 30 31 Dir.mktmpdir do |tmp_dir| 32 gen_out = File.join(tmp_dir, 'package_with_underscore', 'service_services_pb.rb') 33 34 pid = spawn( 35 protoc, 36 "--proto_path=#{pb_dir}", 37 'package_with_underscore/service.proto', 38 "--grpc_out=#{tmp_dir}", 39 "--plugin=protoc-gen-grpc=#{plugin}" 40 ) 41 Process.waitpid2(pid) 42 File.open(gen_out) { |f| got = f.read } 43 end 44 45 correct_modularized_rpc = 'rpc :TestOne, ' \ 46 'Grpc::Testing::PackageWithUnderscore::Data::Request, ' \ 47 'Grpc::Testing::PackageWithUnderscore::Data::Response' 48 49 return if got.include?(correct_modularized_rpc) 50 51 fail 'generated file does not match with correct_modularized_rpc' 52end 53 54main 55