diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-30 09:51:03 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-30 10:00:35 +0200 |
commit | f89d2c16c1dad9b8d2f3b0e402a47e30521f5a69 (patch) | |
tree | 10fe158dd8ca79c89ede9d21bdbfc57104c65d57 /build2/config/init.cxx | |
parent | 83d5e6063f670134303a3396219f63eaac0aedff (diff) |
Add support for config.build file versioning
Diffstat (limited to 'build2/config/init.cxx')
-rw-r--r-- | build2/config/init.cxx | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/build2/config/init.cxx b/build2/config/init.cxx index 6c713df..368b9d0 100644 --- a/build2/config/init.cxx +++ b/build2/config/init.cxx @@ -23,9 +23,10 @@ namespace build2 namespace config { const string module::name ("config"); + const uint64_t module::version; void - boot (scope& rs, const location&, unique_ptr<module_base>&) + boot (scope& rs, const location& loc, unique_ptr<module_base>&) { tracer trace ("config::boot"); @@ -44,10 +45,44 @@ namespace build2 // possible that some module which needs the configuration will get // called first. // - path f (out_root / config_file); + const variable& c_v (var_pool.insert<uint64_t> ("config.version")); - if (file_exists (f)) - source (f, rs, rs); + // Don't load it if we are disfiguring. This is a bit tricky since the + // build2 core may not yet know it is disfiguring. But we know. + // + if (*current_mname != disfigure.name && + (!current_mname->empty () || *current_oname != disfigure.name)) + { + path f (out_root / config_file); + + if (file_exists (f)) + { + // Check the config version. We assume that old versions cannot + // understand new configs and new versions are incompatible with old + // configs. + // + // We extract the value manually instead of loading and then + // checking in order to be able to fixup/migrate the file which we + // may want to do in the future. + // + { + // Assume missing version is 0. + // + auto p (extract_variable (f, c_v.name.c_str ())); + uint64_t v (p.second ? cast<uint64_t> (p.first) : 0); + + if (v != module::version) + fail (loc) << "incompatible config file " << f << + info << "config file version " << v + << (p.second ? "" : " (missing)") << + info << "config module version " << module::version << + info << "consider reconfiguring " << project (rs) << '@' + << out_root; + } + + source (f, rs, rs); + } + } } bool |