From f6902d6afebfbcb28a492145a75611660230810e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A4rtel?= Date: Wed, 5 Feb 2020 14:43:43 +0200 Subject: [PATCH] Made protoc --descriptor_set_out deterministic. Repeatable protoc output is useful because it's sometimes checked into version control, and rerunning protoc should not generate unnecessary diffs. --- src/google/protobuf/compiler/command_line_interface.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index c5b20303bb..093284e819 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -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(); if (!out.Close()) { std::cerr << descriptor_set_out_name_ << ": " << strerror(out.GetErrno()) << std::endl;