#!/usr/bin/env ruby # frozen_string_literal: true # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require "optparse" require "fileutils" parameters = {} OptionParser.new do |op| op.on "--ruby-cloud-config FILE" do |val| parameters["configuration"] = val end op.on "--ruby-cloud-samples FILE", "--samples FILE" do |val| paths = val.split(";") .map { |path| File.expand_path path, "/in" } .join(";") parameters["samples"] = paths end op.on "--ruby-cloud-grpc-service-config FILE" do |val| path = File.expand_path val, "/in" parameters["grpc_service_config"] = path end op.on "--ruby-cloud-gem-name NAME" do |val| parameters[":gem.:name"] = val end op.on "--ruby-cloud-title NAME" do |val| parameters[":gem.:title"] = val end op.on "--ruby-cloud-summary VAL" do |val| parameters[":gem.:summary"] = val end op.on "--ruby-cloud-homepage VAL" do |val| parameters[":gem.:homepage"] = val end op.on "--ruby-cloud-env-prefix VAL" do |val| parameters[":gem.:env_prefix"] = val end end.parse! ARGV parameter_strs = parameters.map do |k, v| v = v.gsub("\\", "\\\\\\\\").gsub(",", "\\\\,").gsub("=", "\\\\=") "#{k}=#{v}" end protoc_cmd = [ "grpc_tools_ruby_protoc", "--proto_path=/protos/", "--proto_path=/in/", "--ruby_out=/out/lib", "--grpc_out=/out/lib", "--ruby_cloud_out=/out/", "--ruby_cloud_opt", parameter_strs.join(",") ] + ARGV + Dir.glob("/in/**/*.proto").sort FileUtils.mkdir_p "/out/lib" exec(*protoc_cmd)