Commit 891294c0 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Create Server subpackage

Prior to this change, all proto definitions were in the root of this
project. Creating one big package, and confusion. For example, myself
and others expected each service to be a namespace, so the
RepositoyService::Exists message was a different one from
NamespaceService::Exists for example.

This change *copies* the server proto to a package directory. Having a
separte directory for each package or module/class is not a neccesity,
but it given this is the usual way of doing it in multiple languages it
seemed the cleanest way to signal a serperation of concerns.

Given the structure of the repository changed, the ruby script
generating the proto defintions has been changed too.

Changes are needed for: gitaly#655
parent e3a5c0a6
Pipeline #27848925 passed with stage
in 1 minute and 29 seconds
#!/usr/bin/env ruby
require 'erb'
require 'pathname'
require 'fileutils'
require_relative 'run.rb'
PROTO_INCLUDE = '.'
PROTO_FILES = Dir['*.proto'].sort
RUBY_PREFIX = 'ruby/lib'
RUBY_VERSION_FILE = 'gitaly/version.rb'
REPO_ROOT = Pathname.new(File.join(File.dirname(__FILE__), '../')).realpath
PACKAGES_DIR = Pathname.new(File.join(REPO_ROOT, 'packages'))
GO_DIR = File.join(REPO_ROOT, 'go')
RUBY_DIR = File.join(REPO_ROOT, 'ruby', 'lib')
RUBY_VERSION_FILE = File.join('gitaly', 'version')
ENV['PATH'] = [
File.join(ENV['GOPATH'], 'bin'),
......@@ -19,19 +21,21 @@ ENV['PATH'] = [
def main
FileUtils.rm(Dir['go/**/*.pb.go'])
run!(%W[protoc -I #{PROTO_INCLUDE}] + PROTO_FILES + %w[--go_out=plugins=grpc:go])
FileUtils.rm(Dir[File.join(RUBY_DIR, '**/*_pb.rb')])
packages = PACKAGES_DIR.children << REPO_ROOT
packages.each { |directory| generate_package(directory) }
FileUtils.rm(Dir[File.join(RUBY_PREFIX, '**/*_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
requires = Dir.chdir(RUBY_DIR) { Dir['**/*_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')
requires.unshift(File.join('gitaly', 'version'))
gem_root = File.join(RUBY_DIR, '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__))
......@@ -42,4 +46,24 @@ EOT
open(gem_root, 'w') { |f| f.write(gem_root_template.result(binding)) }
end
def generate_package(dir)
return unless File.directory?(dir)
package_name = dir == REPO_ROOT ? '' : dir.basename
Dir.chdir(dir) do
files = Dir['*.proto'].sort
go_package_dir = File.join(GO_DIR, package_name)
ruby_lib_gitaly = File.join(RUBY_DIR, 'gitaly', package_name)
# Generate Golang code
FileUtils.mkdir_p(go_package_dir) unless Dir.exist?(go_package_dir)
run!(%w[protoc -I .] + files + %W[--go_out=plugins=grpc:#{go_package_dir}])
# Generate Ruby code
FileUtils.mkdir_p(ruby_lib_gitaly) unless Dir.exist?(ruby_lib_gitaly)
run!(%W[grpc_tools_ruby_protoc -I . --ruby_out=#{ruby_lib_gitaly} --grpc_out=#{ruby_lib_gitaly}] + files)
end
end
main
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: info.proto
/*
Package gitaly_server is a generated protocol buffer package.
It is generated from these files:
info.proto
It has these top-level messages:
InfoRequest
InfoResponse
*/
package gitaly_server
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type InfoRequest struct {
}
func (m *InfoRequest) Reset() { *m = InfoRequest{} }
func (m *InfoRequest) String() string { return proto.CompactTextString(m) }
func (*InfoRequest) ProtoMessage() {}
func (*InfoRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type InfoResponse struct {
ServerVersion string `protobuf:"bytes,1,opt,name=server_version,json=serverVersion" json:"server_version,omitempty"`
GitVersion string `protobuf:"bytes,2,opt,name=git_version,json=gitVersion" json:"git_version,omitempty"`
}
func (m *InfoResponse) Reset() { *m = InfoResponse{} }
func (m *InfoResponse) String() string { return proto.CompactTextString(m) }
func (*InfoResponse) ProtoMessage() {}
func (*InfoResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *InfoResponse) GetServerVersion() string {
if m != nil {
return m.ServerVersion
}
return ""
}
func (m *InfoResponse) GetGitVersion() string {
if m != nil {
return m.GitVersion
}
return ""
}
func init() {
proto.RegisterType((*InfoRequest)(nil), "gitaly.server.InfoRequest")
proto.RegisterType((*InfoResponse)(nil), "gitaly.server.InfoResponse")
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// Client API for ServerService service
type ServerServiceClient interface {
GetInfo(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*InfoResponse, error)
}
type serverServiceClient struct {
cc *grpc.ClientConn
}
func NewServerServiceClient(cc *grpc.ClientConn) ServerServiceClient {
return &serverServiceClient{cc}
}
func (c *serverServiceClient) GetInfo(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*InfoResponse, error) {
out := new(InfoResponse)
err := grpc.Invoke(ctx, "/gitaly.server.ServerService/GetInfo", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for ServerService service
type ServerServiceServer interface {
GetInfo(context.Context, *InfoRequest) (*InfoResponse, error)
}
func RegisterServerServiceServer(s *grpc.Server, srv ServerServiceServer) {
s.RegisterService(&_ServerService_serviceDesc, srv)
}
func _ServerService_GetInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(InfoRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ServerServiceServer).GetInfo(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/gitaly.server.ServerService/GetInfo",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ServerServiceServer).GetInfo(ctx, req.(*InfoRequest))
}
return interceptor(ctx, in, info, handler)
}
var _ServerService_serviceDesc = grpc.ServiceDesc{
ServiceName: "gitaly.server.ServerService",
HandlerType: (*ServerServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GetInfo",
Handler: _ServerService_GetInfo_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "info.proto",
}
func init() { proto.RegisterFile("info.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 166 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xca, 0xcc, 0x4b, 0xcb,
0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x4d, 0xcf, 0x2c, 0x49, 0xcc, 0xa9, 0xd4, 0x2b,
0x4e, 0x2d, 0x2a, 0x4b, 0x2d, 0x52, 0xe2, 0xe5, 0xe2, 0xf6, 0xcc, 0x4b, 0xcb, 0x0f, 0x4a, 0x2d,
0x2c, 0x4d, 0x2d, 0x2e, 0x51, 0x0a, 0xe3, 0xe2, 0x81, 0x70, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53,
0x85, 0x54, 0xb9, 0xf8, 0x20, 0x0a, 0xe3, 0xcb, 0x52, 0x8b, 0x8a, 0x33, 0xf3, 0xf3, 0x24, 0x18,
0x15, 0x18, 0x35, 0x38, 0x83, 0x78, 0x21, 0xa2, 0x61, 0x10, 0x41, 0x21, 0x79, 0x2e, 0xee, 0xf4,
0xcc, 0x12, 0xb8, 0x1a, 0x26, 0xb0, 0x1a, 0xae, 0xf4, 0xcc, 0x12, 0xa8, 0x02, 0xa3, 0x50, 0x2e,
0xde, 0x60, 0xb0, 0x0e, 0x10, 0x99, 0x99, 0x9c, 0x2a, 0xe4, 0xc2, 0xc5, 0xee, 0x9e, 0x5a, 0x02,
0xb2, 0x4b, 0x48, 0x4a, 0x0f, 0xc5, 0x49, 0x7a, 0x48, 0xee, 0x91, 0x92, 0xc6, 0x2a, 0x07, 0x71,
0x9c, 0x12, 0x43, 0x12, 0x1b, 0xd8, 0x4f, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x84, 0xe4,
0x40, 0xbf, 0xe1, 0x00, 0x00, 0x00,
}
syntax = "proto3";
package gitaly.server;
service ServerService {
rpc GetInfo(InfoRequest) returns (InfoResponse) {}
}
message InfoRequest {
}
message InfoResponse {
string server_version = 1;
string git_version = 2;
}
......@@ -25,6 +25,8 @@ require 'gitaly/remote_services_pb'
require 'gitaly/repository-service_services_pb'
require 'gitaly/server/info_services_pb'
require 'gitaly/server_services_pb'
require 'gitaly/smarthttp_services_pb'
......
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: info.proto
require 'google/protobuf'
Google::Protobuf::DescriptorPool.generated_pool.build do
add_message "gitaly.server.InfoRequest" do
end
add_message "gitaly.server.InfoResponse" do
optional :server_version, :string, 1
optional :git_version, :string, 2
end
end
module Gitaly
module Server
InfoRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.server.InfoRequest").msgclass
InfoResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.server.InfoResponse").msgclass
end
end
# Generated by the protocol buffer compiler. DO NOT EDIT!
# Source: info.proto for package 'gitaly.server'
require 'grpc'
require 'info_pb'
module Gitaly
module Server
module ServerService
class Service
include GRPC::GenericService
self.marshal_class_method = :encode
self.unmarshal_class_method = :decode
self.service_name = 'gitaly.server.ServerService'
rpc :GetInfo, InfoRequest, InfoResponse
end
Stub = Service.rpc_stub_class
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