Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

teach protoc-gen-ruby PB_{DUMP,LOAD}_REQUEST_BYTES #307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion bin/protoc-gen-ruby
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,23 @@ require 'protobuf/code_generator'
STDIN.binmode
STDOUT.binmode

request_bytes = STDIN.read
request_bytes = if ENV['PB_LOAD_REQUEST_BYTES']
File.read(ENV['PB_LOAD_REQUEST_BYTES'])
else
STDIN.read
end
if ENV['PB_DUMP_REQUEST_BYTES']
dump_file = ENV['PB_DUMP_REQUEST_BYTES']
unless File.directory?(File.dirname(dump_file))
warn "PB_DUMP_REQUEST_BYTES=#{dump_file.inspect} is not a valid path for the request bytes"
warn "Usage: PB_DUMP_REQUEST_BYTES=/path/to/desired/dump/file.bin protoc blah.proto"
exit 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @nerdrew did you actually want this to be exit 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind this is fine, the Ruby docs on exit were misleading

end
File.open(dump_file, 'w') do |f|
f.print(request_bytes)
end
exit 1
end
code_generator = ::Protobuf::CodeGenerator.new(request_bytes)
code_generator.eval_unknown_extensions!
STDOUT.print(code_generator.response_bytes)