#!/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" bool_option_map = { ":gem.:free_tier" => "ruby-cloud-free-tier", ":gem.:yard_strict" => "ruby-cloud-yard-strict" } value_option_map = { "configuration" => "ruby-cloud-config", ":gem.:name" => "ruby-cloud-gem-name", ":gem.:title" => "ruby-cloud-title", ":gem.:description" => "ruby-cloud-description", ":gem.:summary" => "ruby-cloud-summary", ":gem.:homepage" => "ruby-cloud-homepage", ":gem.:env_prefix" => "ruby-cloud-env-prefix", ":gem.:version_dependencies" => "ruby-cloud-wrapper-of", ":gem.:migration_version" => "ruby-cloud-migration-version", ":gem.:product_documentation_url" => "ruby-cloud-product-url", ":gem.:api_id" => "ruby-cloud-api-id", ":gem.:factory_method_suffix" => "ruby-cloud-factory-method-suffix" } path_option_map = { "samples" => ["ruby-cloud-samples", "samples"], "grpc_service_config" => "ruby-cloud-grpc-service-config" } parameters = {} OptionParser.new do |op| bool_option_map.each do |key, flags| flags = Array(flags).map { |f| "--#{f}" } op.on(*flags) do parameters[key] = "true" end end value_option_map.each do |key, flags| flags = Array(flags).map { |f| "--#{f} VAL" } op.on(*flags) do |val| parameters[key] = val end end path_option_map.each do |key, flags| flags = Array(flags).map { |f| "--#{f} PATH" } op.on(*flags) do |paths| parameters[key] = paths.split(";") .map { |path| File.expand_path path, "/in" } .join(";") end end end.parse! ARGV parameter_strs = parameters.map do |k, v| v = v.gsub("\\", "\\\\\\\\").gsub(",", "\\\\,").gsub("=", "\\\\=") "#{k}=#{v}" end ruby_plugin_args = if parameters[":gem.:version_dependencies"] [] else ["--ruby_out=/out/lib", "--grpc_out=/out/lib"] end protoc_cmd = [ "grpc_tools_ruby_protoc", "--proto_path=/protos/", "--proto_path=/in/" ] + ruby_plugin_args + [ "--ruby_cloud_out=/out/", "--ruby_cloud_opt", parameter_strs.join(",") ] + ARGV + Dir.glob("/in/**/*.proto").sort FileUtils.mkdir_p "/out/lib" exec(*protoc_cmd)