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

Deterministic protoc --descriptor_set_out #7175

Merged
merged 2 commits into from Feb 12, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/google/protobuf/compiler/command_line_interface.cc
Expand Up @@ -2228,12 +2228,18 @@ bool CommandLineInterface::WriteDescriptorSet(
}

io::FileOutputStream out(fd);
if (!file_set.SerializeToZeroCopyStream(&out)) {

io::CodedOutputStream coded_out(&out);
// Determinism is useful here because build outputs are sometimes checked
// into version control.
coded_out.SetSerializationDeterministic(true);
if (!file_set.SerializeToCodedStream(&coded_out)) {
std::cerr << descriptor_set_out_name_ << ": " << strerror(out.GetErrno())
<< std::endl;
out.Close();
return false;
}
coded_out.Trim();
Copy link
Member

Choose a reason for hiding this comment

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

We usually just create the CodedOutputStream inside a block with curly braces: that way the destructor will take care of any cleanup and this Trim() call won't be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if (!out.Close()) {
std::cerr << descriptor_set_out_name_ << ": " << strerror(out.GetErrno())
<< std::endl;
Expand Down