Skip to content

Commit 751fa28

Browse files
committed
engine: Support stack minor versions and bump to "4.1"
This should not be a breaking change, since this provides support for versions "4", "4.0", and "4.1". The idea is that one can specify in the stack which version you target, and cloe-engine will make sure it's at least that recent. For example, if a stackfile requires "4", everything still works. If it requires "4.1", it will only work with a cloe-engine of at least this version, which is as intended. Bumping a version in the future will require modifying the CLOE_STACK_VERSION and CLOE_STACK_SUPPORTED_VERSIONS defines in stack.hpp.
1 parent cff17e3 commit 751fa28

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

engine/src/stack.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Conf default_conf_reader(const std::string& filepath) { return Conf{filepath}; }
137137
Stack::Stack()
138138
: Confable()
139139
, reserved_ids_({"_", "cloe", "sim", "simulation"})
140+
, version(CLOE_STACK_VERSION)
140141
, engine_schema(&engine, "engine configuration")
141142
, include_schema(&include, include_prototype(), "include configurations")
142143
, plugins_schema(&plugins, "plugin configuration")
@@ -147,6 +148,7 @@ Stack::Stack(const Stack& other)
147148
// Constants (1)
148149
, reserved_ids_(other.reserved_ids_)
149150
// Configuration (13)
151+
, version(other.version)
150152
, engine(other.engine)
151153
, server(other.server)
152154
, include(other.include)
@@ -191,6 +193,7 @@ void swap(Stack& left, Stack& right) {
191193
swap(left.reserved_ids_, right.reserved_ids_);
192194

193195
// Configuration (13)
196+
swap(left.version, right.version);
194197
swap(left.engine, right.engine);
195198
swap(left.server, right.server);
196199
swap(left.include, right.include);
@@ -435,27 +438,29 @@ void Stack::to_json(Json& j) const {
435438
}
436439

437440
void Stack::from_conf(const Conf& _conf, size_t depth) {
441+
static std::vector<std::string> versions CLOE_STACK_SUPPORTED_VERSIONS;
442+
438443
applied_confs_.emplace_back(_conf);
439444
Conf c = _conf;
440445

441446
// First check the version so the user gets higher-level errors first.
442447
if (c.has("version")) {
443448
auto ver = c.get<std::string>("version");
444-
if (ver != CLOE_STACK_VERSION) {
449+
if (std::find(versions.begin(), versions.end(), ver) == versions.end()) {
445450
// If we threw a SchemaError, it would look like this:
446451
//
447452
// throw SchemaError{
448453
// c,
449454
// this->schema().json_schema(),
450455
// Json{},
451-
// "require version {}, got {}",
456+
// "require version compatible with {}, got {}",
452457
// CLOE_STACK_VERSION,
453458
// ver,
454459
// };
455460
//
456461
// But that would result in a very verbose error message, so we shall
457462
// throw a more user-friendly error message instead.
458-
throw Error{"require version {}, got {}", CLOE_STACK_VERSION, ver}.explanation(R"(
463+
throw Error{"require version compatible with {}, got {}", CLOE_STACK_VERSION, ver}.explanation(R"(
459464
It looks like you are attempting to load a stack file with an
460465
incompatible version.
461466

engine/src/stack.hpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@
4545
#include "plugin.hpp" // for Plugin
4646

4747
#ifndef CLOE_STACK_VERSION
48-
#define CLOE_STACK_VERSION "4"
48+
#define CLOE_STACK_VERSION "4.1"
49+
#endif
50+
51+
#ifndef CLOE_STACK_SUPPORTED_VERSIONS
52+
#define CLOE_STACK_SUPPORTED_VERSIONS {"4", "4.0", "4.1"}
4953
#endif
5054

5155
#ifndef CLOE_XDG_SUFFIX
@@ -887,6 +891,7 @@ class Stack : public Confable {
887891
boost::optional<std::string> schema_ref_;
888892

889893
public: // Configuration (13)
894+
std::string version;
890895
EngineConf engine;
891896
ServerConf server;
892897
std::vector<IncludeConf> include;
@@ -1091,7 +1096,9 @@ class Stack : public Confable {
10911096

10921097
return Struct{
10931098
{"$schema", make_schema(&schema_ref_, "valid URI to schema describing this cloe stack version")},
1094-
{"version", make_const_str(CLOE_STACK_VERSION, "version of stackfile").require()},
1099+
{"version", make_schema(&version, "version of stackfile").require().enum_of(
1100+
CLOE_STACK_SUPPORTED_VERSIONS
1101+
)},
10951102
{"engine", engine_schema},
10961103
{"include", include_schema},
10971104
{"logging", make_schema(&logging, "logging configuration").extend(true)},

engine/src/stack_test.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ TEST(cloe_stack, serialization_of_empty_stack) {
3737
Stack s;
3838

3939
fable::assert_from_conf(s, R"({
40-
"version": "4"
40+
"version": "4.1"
4141
})");
4242

4343
Json expect = R"({
@@ -110,7 +110,7 @@ TEST(cloe_stack, serialization_of_empty_stack) {
110110
"simulators": [],
111111
"triggers": [],
112112
"vehicles": [],
113-
"version": "4"
113+
"version": "4.1"
114114
})"_json;
115115

116116
ASSERT_EQ(s.to_json().dump(2), expect.dump(2));
@@ -120,7 +120,7 @@ TEST(cloe_stack, serialization_with_logging) {
120120
Stack s;
121121

122122
assert_from_conf(s, R"({
123-
"version": "4",
123+
"version": "4.1",
124124
"defaults": {
125125
"simulators": [
126126
{ "binding": "vtd", "args": { "label_vehicle": "symbol" } }
@@ -205,7 +205,7 @@ TEST(cloe_stack, serialization_with_logging) {
205205
},
206206
"triggers": [],
207207
"vehicles": [],
208-
"version": "4"
208+
"version": "4.1"
209209
})"_json;
210210

211211
ASSERT_NO_THROW(Json{s.logging[0]}.dump());

0 commit comments

Comments
 (0)