Commit 176ee180 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Ruby library: adapted generating script

Our files layout differs from upstream's, because of the `hgitaly`
package name, and also because we only care about the generated lib,
whereas Gitaly also has Ruby code of its own.

We also derive the version module directly from `hgitaly/version`
parent 40e11e7dc7ee
......@@ -5,3 +5,13 @@ it from the protocol declarations.
This library provides only the definitions that are specific to HGitaly, and
depends on the Gitaly gRPC library.
## Regenerating
Assuming you have an active rbenv:
```
bundle install
./generate-grpc-lib
hg commit
```
\ No newline at end of file
#!/usr/bin/env ruby
# Derived from Gitaly support script (MIT license):
# _support/generate-proto-ruby
# with changes copyright 2021 Georges Racinet <georges.racinet@octobus.net>
require 'erb'
require 'fileutils'
require 'pathname'
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'
PROTO_INCLUDE = '../protos'
PROTO_FILES = Dir[File.join(PROTO_INCLUDE, 'mercurial-*.proto')].sort.map { |f| File.absolute_path(f) }
RUBY_PREFIX = 'lib'
RUBY_VERSION_FILE = 'hgitaly/version.rb'
def main
ruby_lib_gitaly = File.join(RUBY_PREFIX, 'gitaly')
ruby_lib_gitaly = File.join(RUBY_PREFIX, 'hgitaly')
FileUtils.rm(Dir[File.join(ruby_lib_gitaly, '**/*_pb.rb')])
FileUtils.mkdir_p(ruby_lib_gitaly)
Dir.chdir(File.join(Dir.pwd, 'ruby')) do
Dir.chdir(RUBY_PREFIX) 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))
......@@ -24,17 +27,18 @@ def main
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_version
write_ruby_requires
end
def write_ruby_requires
requires = Dir.chdir(RUBY_PREFIX) { Dir['gitaly/*_services_pb.rb'] }.sort
requires = Dir.chdir(RUBY_PREFIX) { Dir['hgitaly/*_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 = File.join(RUBY_PREFIX, 'hgitaly.rb')
gem_root_template = ERB.new <<~EOT
# This file is generated by #{File.basename($0)}. Do not edit.
$:.unshift(File.expand_path('../gitaly', __FILE__))
$:.unshift(File.expand_path('../hgitaly', __FILE__))
<% requires.each do |f| %>
require '<%= f.sub(/\.rb$/, '') %>'
<% end %>
......@@ -42,4 +46,18 @@ def write_ruby_requires
open(gem_root, 'w') { |f| f.write(gem_root_template.result(binding)) }
end
def write_ruby_version
version = File.read('../hgitaly/VERSION').chomp
Dir.chdir(RUBY_PREFIX) do
version_ruby = <<~EOT
# This file is generated by #{File.basename($0)}. Do not edit.
module Hgitaly
VERSION = '#{version}'
end
EOT
File.write(RUBY_VERSION_FILE, version_ruby)
end
end
main
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