loosen the coupling between protoc-c and the protobuf-c headers

exact version coupling between the compiler and the public headers is
too strict because some existing projects (such as collectd,
riemann-c-client, and nmsg) directly embed .pb-c.h files generated by
protoc-c into their exported headers. this would cause unnecessary build
failures in downstream clients of these libraries if a newer version of
the protobuf-c headers is installed.

however, it's still desireable to be able to explicitly declare when
compatibility is broken between the headers and the compiler, so
introduce new variables that allow independently setting the minimum
header version required by the compiler and the minimum compiler version
required by the header.

this follows the protobuf C++ implementation a little bit more closely,
though we don't have an analogous facility for verifying that the header
and *library* are compatible. (this seems like overkill for a C project;
in practice the headers and the library will be from the same version,
especially in downstream distributors like debian where the -dev package
has an exact versioned dependency on the shared library package.)
This commit is contained in:
Robert Edmonds 2014-06-03 13:54:50 -04:00
parent f406c9c537
commit 9fa749d679
2 changed files with 10 additions and 3 deletions

View File

@ -103,6 +103,12 @@ protobuf_c_version_number(void);
*/
#define PROTOBUF_C_VERSION_NUMBER 1000000
/**
* The minimum protoc-c version which works with the current version of the
* protobuf-c headers.
*/
#define PROTOBUF_C_MIN_COMPILER_VERSION 1000000
typedef int protobuf_c_boolean;
typedef enum {

View File

@ -119,6 +119,8 @@ FileGenerator::~FileGenerator() {}
void FileGenerator::GenerateHeader(io::Printer* printer) {
string filename_identifier = FilenameIdentifier(file_->name());
static const int min_header_version = 1000000;
// Generate top of header.
printer->Print(
"/* Generated by the protocol buffer compiler. DO NOT EDIT! */\n"
@ -140,14 +142,13 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
"#if PROTOBUF_C_VERSION_NUMBER < $min_header_version$\n"
"# error This file was generated by a newer version of protoc-c which is "
"incompatible with your libprotobuf-c headers. Please update your headers.\n"
"#elif $protoc_version$ < PROTOBUF_C_VERSION_NUMBER\n"
"#elif $protoc_version$ < PROTOBUF_C_MIN_COMPILER_VERSION\n"
"# error This file was generated by an older version of protoc-c which is "
"incompatible with your libprotobuf-c headers. Please regenerate this file "
"with a newer version of protoc-c.\n"
"#endif\n"
"\n",
"min_header_version",
SimpleItoa(PROTOBUF_C_VERSION_NUMBER),
"min_header_version", SimpleItoa(min_header_version),
"protoc_version", SimpleItoa(PROTOBUF_C_VERSION_NUMBER));
for (int i = 0; i < file_->dependency_count(); i++) {