)--v1-config--";
-static BeesConfig::Register s_reg_config_v1("1", bees_config_v1);
+// The oldest schema, so it inherits from nothing.
+static BeesConfig::Register s_reg_config_v1("1", nullptr, bees_config_v1);
// Schema version 2 is the one under development: new options and changed
// defaults land here. bees-config-v1.cc is frozen at what v0.11 shipped.
-static BeesConfig::Register s_reg_config_v2("2", bees_config_v2);
+static BeesConfig::Register s_reg_config_v2("2", "v0.11", bees_config_v2);
#include <sys/statfs.h>
unique_ptr<BeesConfig::DefaultMap> BeesConfig::s_defaults;
+unique_ptr<BeesConfig::PreviousMap> BeesConfig::s_previous;
-BeesConfig::Register::Register::Register(const char *const version, const char *const text)
+BeesConfig::Register::Register::Register(const char *const version, const char *const previous, const char *const text)
{
Innie in;
in.set_origin(string("<builtin_version_") + version + ">");
if (!BeesConfig::s_defaults) {
BeesConfig::s_defaults = make_unique<DefaultMap>();
}
- BeesConfig::s_defaults->insert(make_pair(version, in));
+ if (!BeesConfig::s_previous) {
+ BeesConfig::s_previous = make_unique<PreviousMap>();
+ }
+ // config.version accepts versions and aliases from one namespace, so a
+ // schema registered under a name that is already an alias would leave
+ // that name meaning two different things depending on who resolved it.
+ THROW_CHECK1(runtime_error, version, !version_aliases().count(version));
+ // map::insert is a no-op on a key that already exists, so without this
+ // a second registration of the same version would be dropped in silence
+ // and whichever translation unit happened to run first would own the
+ // schema. Both of these are build errors, and both abort before main()
+ // rather than leave a half-registered version graph behind.
+ const auto rv = BeesConfig::s_defaults->insert(make_pair(version, in));
+ THROW_CHECK1(runtime_error, version, rv.second);
+ if (previous) {
+ BeesConfig::s_previous->insert(make_pair(version, previous));
+ }
// Only need this when debugging global ctor initialization
// BEESLOGDEBUG("Registered config defaults " << in.get_origin());
}
/// Map of version string -> built-in default INI text.
using DefaultMap = map<string, Innie>;
static unique_ptr<DefaultMap> s_defaults;
+ /// Map of version string -> the version it inherits from, exactly as
+ /// written at registration. Stored unresolved: a Register runs before
+ /// main() and the version it names may not be registered yet.
+ using PreviousMap = map<string, string>;
+ static unique_ptr<PreviousMap> s_previous;
/// Newest config schema in this build: the one under development, and
/// what CURRENT resolves to.
static constexpr const char *s_current_version = "2";
* key already exists, and no error or warning is produced.
*/
struct Register {
- /// Register @p text as the default config block for schema @p version.
- Register(const char *version, const char *text);
+ /**
+ * Register @p text as the built-in defaults for schema @p version,
+ * which inherits every key it does not define from @p previous.
+ * Pass @c nullptr for the oldest schema.
+ *
+ * @p previous may name a concrete version or a frozen alias, and is
+ * resolved on first use rather than here: static initialization
+ * order across translation units is unspecified, so the schema it
+ * names may not have registered yet. A tracking alias is rejected
+ * when the edge is resolved, since it would not keep meaning the
+ * same schema.
+ */
+ Register(const char *version, const char *previous, const char *text);
};
/// Merge command-line INI values on top of all other config layers.