Use protoc version for --version

pull/10386/head
Deanna Garcia 2 years ago
parent b36782ae98
commit f05ad8ee71
  1. 2
      src/google/protobuf/compiler/command_line_interface.cc
  2. 12
      src/google/protobuf/stubs/common.cc
  3. 7
      src/google/protobuf/stubs/common.h

@ -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.

@ -92,7 +92,7 @@ void VerifyVersion(int headerVersion,
}
}
std::string VersionString(int version) {
std::string VersionString(int version, bool cppMajor) {
int major = version / 1000000;
int minor = (version / 1000) % 1000;
int micro = version % 1000;
@ -100,7 +100,11 @@ std::string VersionString(int version) {
// 128 bytes should always be enough, but we use snprintf() anyway to be
// safe.
char buffer[128];
snprintf(buffer, sizeof(buffer), "%d.%d.%d", major, minor, micro);
if (cppMajor) {
snprintf(buffer, sizeof(buffer), "%d.%d.%d", major, minor, micro);
} else {
snprintf(buffer, sizeof(buffer), "%d.%d", minor, micro);
}
// Guard against broken MSVC snprintf().
buffer[sizeof(buffer)-1] = '\0';
@ -108,6 +112,10 @@ std::string VersionString(int version) {
return buffer;
}
std::string ProtocVersionString(int version) {
return VersionString(version, false);
}
} // namespace internal
// ===================================================================

@ -106,7 +106,12 @@ void PROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion,
const char* filename);
// Converts a numeric version number to a string.
std::string PROTOBUF_EXPORT VersionString(int version);
// If cppMajor is true the string will have the C++ major version, otherwise
// the string will be the protoc version.
std::string PROTOBUF_EXPORT VersionString(int version, bool cppMajor = true);
// Prints the protoc compiler version (no major version)
std::string PROTOBUF_EXPORT ProtocVersionString(int version);
} // namespace internal

Loading…
Cancel
Save