#!/usr/bin/env ruby require 'erb' require 'fileutils' require_relative 'run.rb' PROTO_INCLUDE = './proto' PROTO_FILES = Dir['proto/*.proto'].sort RUBY_PREFIX = 'ruby/proto' RUBY_VERSION_FILE = 'gitaly/version.rb' ENV['PATH'] = [ File.join(Dir.pwd, '_build/protoc/bin'), File.join(Dir.pwd, '_build/bin'), ENV['PATH'], ].join(':') def main ruby_lib_gitaly = File.join(RUBY_PREFIX, 'gitaly') FileUtils.rm(Dir[File.join(ruby_lib_gitaly, '**/*_pb.rb')]) FileUtils.mkdir_p(ruby_lib_gitaly) run!(%W[grpc_tools_ruby_protoc -I #{PROTO_INCLUDE} --ruby_out=#{ruby_lib_gitaly} --grpc_out=#{ruby_lib_gitaly}] + PROTO_FILES) write_ruby_requires end def write_ruby_requires requires = Dir.chdir(RUBY_PREFIX) { Dir['gitaly/*_services_pb.rb'] }.sort abort "No auto-generated Ruby service files found" if requires.empty? requires.unshift(RUBY_VERSION_FILE) gem_root = File.join(RUBY_PREFIX, 'gitaly.rb') gem_root_template = ERB.new <<~EOT # This file is generated by #{File.basename($0)}. Do not edit. $:.unshift(File.expand_path('../gitaly', __FILE__)) <% requires.each do |f| %> require '<%= f.sub(/\.rb$/, '') %>' <% end %> EOT open(gem_root, 'w') { |f| f.write(gem_root_template.result(binding)) } end main