Commit 71ea8925 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Ruby library: copy of upstream generating scripts

The `generate-proto-ruby` script and its supporting `run.rb`
are pristine copies from Gitaly 13.12.2.

They don't work for HGitaly at this point: this changeset is there
to make application of upstream updates easier.
parent c52e3be18244
#!/usr/bin/env ruby
# Derived from Gitaly support script (MIT license):
# _support/generate-proto-ruby
require 'erb'
require 'fileutils'
require_relative 'run.rb'
PROTO_INCLUDE = './proto'
PROTO_FILES = Dir[File.join(PROTO_INCLUDE, '*.proto')].sort.map { |f| File.absolute_path(f) }
RUBY_PREFIX = 'ruby/proto'
RUBY_VERSION_FILE = 'gitaly/version.rb'
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)
Dir.chdir(File.join(Dir.pwd, 'ruby')) do
# Using an absolute path make sure the prefixes match, or the passed in file
# locations. `protoc` requires this.
proto_include_abs = File.absolute_path(File.join('..', PROTO_INCLUDE))
run!(%W[bundle exec grpc_tools_ruby_protoc -I #{proto_include_abs} --ruby_out=../#{ruby_lib_gitaly} --grpc_out=../#{ruby_lib_gitaly}] + PROTO_FILES)
end
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
# Copied from Gitaly support scripts (MIT License):
# _support/run.rb
def run!(cmd, chdir='.')
GitalySupport.print_cmd(cmd)
unless system(*cmd, chdir: chdir)
GitalySupport.fail_cmd!(cmd)
end
end
def run2!(cmd, chdir: '.', out: 1)
GitalySupport.print_cmd(cmd)
unless system(*cmd, chdir: chdir, out: out)
GitalySupport.fail_cmd!(cmd)
end
end
def capture!(cmd, chdir='.')
GitalySupport.print_cmd(cmd)
output = IO.popen(cmd, chdir: chdir) { |io| io.read }
GitalySupport.fail_cmd!(cmd) unless $?.success?
output
end
module GitalySupport
class << self
def print_cmd(cmd)
puts '-> ' + printable_cmd(cmd)
end
def fail_cmd!(cmd)
abort "command failed: #{printable_cmd(cmd)}"
end
def printable_cmd(cmd)
cmd.join(' ')
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment