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/file.cxx | |
parent | 83d5e6063f670134303a3396219f63eaac0aedff (diff) |
Add support for config.build file versioning
Diffstat (limited to 'build2/file.cxx')
-rw-r--r-- | build2/file.cxx | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/build2/file.cxx b/build2/file.cxx index d267fec..46362e1 100644 --- a/build2/file.cxx +++ b/build2/file.cxx @@ -272,7 +272,7 @@ namespace build2 // be the first non-comment line and not to rely on any variable expansion // other than those from the global scope or any variable overrides. // - static value + pair<value, bool> extract_variable (const path& bf, const char* name) { try @@ -288,8 +288,7 @@ namespace build2 tt != token_type::prepend && tt != token_type::append)) { - error << "variable '" << name << "' expected as first line in " << bf; - throw failed (); // Suppress "used uninitialized" warning. + return make_pair (value (), false); } const variable& var (var_pool.find (move (t.value))); @@ -300,14 +299,18 @@ namespace build2 value* v (tmp.vars.find (var)); assert (v != nullptr); - return move (*v); // Steal the value, the scope is going away. + + // Steal the value, the scope is going away. + // + return make_pair (move (*v), true); } catch (const ifdstream::failure& e) { - fail << "unable to read buildfile " << bf << ": " << e.what (); + error << "unable to read buildfile " << bf << ": " << e.what (); + throw failed (); } - return value (); // Never reaches. + // Never reached. } // Extract the project name from bootstrap.build. @@ -336,7 +339,12 @@ namespace build2 src_root = &fallback_src_root; else { - src_root_v = extract_variable (f, "src_root"); + auto p (extract_variable (f, "src_root")); + + if (!p.second) + error << "variable 'src_root' expected as first line in " << f; + + src_root_v = move (p.first); src_root = &cast<dir_path> (src_root_v); l5 ([&]{trace << "extracted src_root " << *src_root << " for " << out_root;}); @@ -345,8 +353,13 @@ namespace build2 string name; { - value v (extract_variable (*src_root / bootstrap_file, "project")); - name = cast<string> (move (v)); + path f (*src_root / bootstrap_file); + auto p (extract_variable (f, "project")); + + if (!p.second) + error << "variable 'project' expected as first line in " << f; + + name = cast<string> (move (p.first)); } l5 ([&]{trace << "extracted project name '" << name << "' for " |