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

Use protoc version for --version #10386

Merged
merged 2 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/command_line_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@ CommandLineInterface::InterpretArgument(const std::string& name,
if (!version_info_.empty()) {
std::cout << version_info_ << std::endl;
}
std::cout << "libprotoc " << internal::VersionString(PROTOBUF_VERSION)
std::cout << "libprotoc " << internal::ProtocVersionString(PROTOBUF_VERSION)
<< PROTOBUF_VERSION_SUFFIX << std::endl;
return PARSE_ARGUMENT_DONE_AND_EXIT; // Exit without running compiler.

Expand Down
16 changes: 16 additions & 0 deletions src/google/protobuf/stubs/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ std::string VersionString(int version) {
return buffer;
}

std::string ProtocVersionString(int version) {
int minor = (version / 1000) % 1000;
int micro = version % 1000;

// 128 bytes should always be enough, but we use snprintf() anyway to be
// safe.
char buffer[128];
snprintf(buffer, sizeof(buffer), "%d.%d", minor, micro);

// Guard against broken MSVC snprintf().
buffer[sizeof(buffer)-1] = '\0';

return buffer;

}

} // namespace internal

// ===================================================================
Expand Down
3 changes: 3 additions & 0 deletions src/google/protobuf/stubs/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ void PROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion,
// Converts a numeric version number to a string.
std::string PROTOBUF_EXPORT VersionString(int version);

// Prints the protoc compiler version (no major version)
std::string PROTOBUF_EXPORT ProtocVersionString(int version);

} // namespace internal

// Place this macro in your main() function (or somewhere before you attempt
Expand Down