File: generate-from-proto

package info (click to toggle)
golang-gitaly-proto 1.37.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 372 kB
  • sloc: ruby: 216; makefile: 93
file content (41 lines) | stat: -rwxr-xr-x 1,177 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env ruby

require 'erb'
require 'fileutils'

require_relative 'run.rb'

PROTO_INCLUDE = '.'
PROTO_FILES = Dir['*.proto'].sort
RUBY_PREFIX = 'ruby/lib'
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
  FileUtils.rm(Dir[File.join(RUBY_PREFIX, 'ruby/**/*_pb.rb')])
  ruby_lib_gitaly = File.join(RUBY_PREFIX, '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