Commit f04f6e77 authored by Kenton Varda's avatar Kenton Varda

Enforce that library header versions match capnp compiler version.

parent 83f9754e
......@@ -276,6 +276,7 @@ capnp_test_SOURCES = \
src/kj/mutex-test.c++ \
src/kj/parse/common-test.c++ \
src/kj/parse/char-test.c++ \
src/capnp/common-test.c++ \
src/capnp/blob-test.c++ \
src/capnp/endian-test.c++ \
src/capnp/endian-fallback-test.c++ \
......
// Copyright (c) 2013, Kenton Varda <temporal@gmail.com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "common.h"
#include <gtest/gtest.h>
#include <kj/string.h>
#include <kj/debug.h>
#if HAVE_CONFIG_H
#include "config.h"
#endif
namespace capnp {
namespace {
TEST(Common, Version) {
#ifdef VERSION
auto expectedVersion =
kj::str(CAPNP_VERSION_MAJOR, '.', CAPNP_VERSION_MINOR, '.', CAPNP_VERSION_MICRO);
kj::StringPtr actualVersion = VERSION;
KJ_ASSERT(actualVersion == expectedVersion ||
actualVersion.startsWith(kj::str(expectedVersion, '-')),
expectedVersion, actualVersion);
#endif
}
} // namespace
} // namespace capnp
......@@ -33,6 +33,13 @@
namespace capnp {
#define CAPNP_VERSION_MAJOR 0
#define CAPNP_VERSION_MINOR 3
#define CAPNP_VERSION_MICRO 0
#define CAPNP_VERSION \
(CAPNP_VERSION_MAJOR * 1000000 + CAPNP_VERSION_MINOR * 1000 + CAPNP_VERSION_MICRO)
typedef unsigned int uint;
enum class Void {
......
......@@ -1384,7 +1384,13 @@ private:
"#ifndef CAPNP_INCLUDED_", kj::hex(node.getId()), "_\n",
"#define CAPNP_INCLUDED_", kj::hex(node.getId()), "_\n"
"\n"
"#include <capnp/generated-header-support.h>\n",
"#include <capnp/generated-header-support.h>\n"
"\n"
"#if CAPNP_VERSION != ", CAPNP_VERSION, "\n"
"#error \"Version mismatch between generated code and library headers. You must "
"use the same version of the Cap'n Proto compiler and library.\"\n"
"#endif\n"
"\n",
KJ_MAP(includes, path) {
if (path.startsWith("/")) {
return kj::strTree("#include <", path.slice(1), ".h>\n");
......
......@@ -27,6 +27,15 @@ update_version() {
local OLD_REGEX=${OLD//./[.]}
doit sed -i -e "s/$OLD_REGEX/$NEW/g" c++/configure.ac
local NEW_NOTAG=${NEW%%-*}
declare -a NEW_ARR=(${NEW_NOTAG//./ })
doit sed -i -re "
s/^#define CAPNP_VERSION_MAJOR [0-9]+\$/#define CAPNP_VERSION_MAJOR ${NEW_ARR[0]}/g;
s/^#define CAPNP_VERSION_MINOR [0-9]+\$/#define CAPNP_VERSION_MINOR ${NEW_ARR[1]}/g;
s/^#define CAPNP_VERSION_MICRO [0-9]+\$/#define CAPNP_VERSION_MICRO ${NEW_ARR[2]:-0}/g" \
c++/src/capnp/common.h
doit git commit -a -m "Set $BRANCH_DESC version to $NEW."
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment