Skip to content

Commit

Permalink
rprotoc now simply execs against protoc with the same args
Browse files Browse the repository at this point in the history
The command will print a deprecation warning (to stderr) as well as the
actual command executed (to stdout).
  • Loading branch information
localshred committed Aug 20, 2013
1 parent e3085af commit 0bc9674
Showing 1 changed file with 4 additions and 58 deletions.
62 changes: 4 additions & 58 deletions bin/rprotoc
Original file line number Diff line number Diff line change
@@ -1,62 +1,8 @@
#!/usr/bin/env ruby

require 'rubygems'
require 'ffi'
command = [ 'protoc', ARGV ].flatten.join(' ')

base_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
$stderr.puts "[DEPRECATED] `rprotoc` is deprecated. Use `protoc --ruby_out ...` instead."
$stdout.puts command

GENERATOR_FILE_PATH = case
when File.exists?(File.join(base_dir, "ruby_generator.bundle")) then
File.join(base_dir, "ruby_generator.bundle")
when File.exists?(File.join(base_dir, "ruby_generator.dll")) then
File.join(base_dir, "ruby_generator.dll")
else
File.join(base_dir, "ruby_generator.so")
end

unless File.exists?(GENERATOR_FILE_PATH)
$stdout << <<-WARNING
Cannot locate shared object to plugin to protocol buffers generator.
Thought the file would be located at #{GENERATOR_FILE_PATH}
If you are running on Windows you should compile protocol buffer
definitions on another VM and then use those definitions locally.
Only the compiler is restricted by this. The definitions should work without issue.
WARNING
$stdout << $/

exit 1
end

module Protobuf
module RProtoC
extend FFI::Library
ffi_lib ::GENERATOR_FILE_PATH
attach_function :_rprotoc_extern, [:int, :pointer], :int32

def self.compile_proto(args)
GC.disable # Don't want strings to be GC'd while protoc has them
args = args.dup
args.unshift("rprotoc")
args << "--help" if args.size == 1

ptr_params = []
args.each do |param|
ptr_params << ::FFI::MemoryPointer.from_string(param.dup)
end
ptr_params << nil

argv = ::FFI::MemoryPointer.new(:pointer, ptr_params.size)
ptr_params.each_with_index do |param_pointer, index|
argv[index].put_pointer(0, param_pointer)
end

self._rprotoc_extern(ptr_params.compact.size, argv)
ensure
GC.enable
end
end
end

::Protobuf::RProtoC.compile_proto(ARGV)
exec command

0 comments on commit 0bc9674

Please sign in to comment.