Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2019-07-25 18:11:52 +0300
committerPaul Okstad <pokstad@gitlab.com>2019-07-25 18:11:52 +0300
commitc5829d906a7418bfc4d2736f8ed80911cbe9e5cf (patch)
tree26678ea5e0c0ae8788d2b5a159b08381eb4ebee9 /_support/generate-proto-ruby
parent1cb2541eecc6d32e4816d0f817db7e42e0c69f50 (diff)
Generate embedded Go and Ruby proto stubs
Diffstat (limited to '_support/generate-proto-ruby')
-rwxr-xr-x_support/generate-proto-ruby44
1 files changed, 44 insertions, 0 deletions
diff --git a/_support/generate-proto-ruby b/_support/generate-proto-ruby
new file mode 100755
index 000000000..c8742037e
--- /dev/null
+++ b/_support/generate-proto-ruby
@@ -0,0 +1,44 @@
+#!/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