From 9bf93c1ab73ee3cd2b763285fc5fc5456e972854 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 11 Jan 2017 10:14:23 +0200 Subject: Implement support for narrowing down tests (config.test) --- build2/config/utility | 31 ++++++++++++++++--------------- build2/config/utility.cxx | 12 ++++++------ build2/config/utility.txx | 4 ++-- 3 files changed, 24 insertions(+), 23 deletions(-) (limited to 'build2/config') diff --git a/build2/config/utility b/build2/config/utility index 1f1fba2..6c18715 100644 --- a/build2/config/utility +++ b/build2/config/utility @@ -28,14 +28,16 @@ namespace build2 // the value is "new", that is, it was set to the default value (inherited // or not, including overrides). We also treat command line overrides // (inherited or not) as new. This flag is usually used to test that the - // new value is valid, print report, etc. + // new value is valid, print report, etc. We return the value as lookup + // (always defined) to pass alone its location (could be used to detect + // inheritance, etc). // // Note also that if save_flags has save_commented, then a default value // is never considered "new" since for such variables absence of a value // means the default value. // template - pair, bool> + pair required (scope& root, const variable&, const T& default_value, @@ -43,7 +45,7 @@ namespace build2 uint64_t save_flags = 0); template - inline pair, bool> + inline pair required (scope& root, const string& name, const T& default_value, @@ -54,7 +56,7 @@ namespace build2 root, var_pool[name], default_value, override, save_flags); } - inline pair, bool> + inline pair required (scope& root, const string& name, const char* default_value, @@ -65,32 +67,31 @@ namespace build2 root, name, string (default_value), override, save_flags); } - // As above, but leave the unspecified value as undefined (and return - // NULL pointer) rather than setting it to the default value. + // As above, but leave the unspecified value as undefined rather than + // setting it to the default value. // // This can be useful when we don't have a default value but may figure // out some fallback. See config.bin.target for an example. // - pair + pair omitted (scope& root, const variable&); - inline pair + inline pair omitted (scope& root, const string& name) { return omitted (root, var_pool[name]); } - // Set, if necessary, an optional config.* variable. In particular, - // an unspecified variable is set to NULL which is used to distinguish - // between the "configured as unspecified" and "not yet configured" - // cases. + // Set, if necessary, an optional config.* variable. In particular, an + // unspecified variable is set to NULL which is used to distinguish + // between the "configured as unspecified" and "not yet configured" cases. // - // Return the value, which can be NULL. + // Return the value (as always defined lookup), which can be NULL. // - const value& + lookup optional (scope& root, const variable&); - inline const value& + inline lookup optional (scope& root, const string& var) { return optional (root, var_pool[var]); diff --git a/build2/config/utility.cxx b/build2/config/utility.cxx index dac11c2..7a3fa9c 100644 --- a/build2/config/utility.cxx +++ b/build2/config/utility.cxx @@ -14,7 +14,7 @@ namespace build2 { namespace config { - pair + pair omitted (scope& r, const variable& var) { // This is a stripped-down version of the required() twisted @@ -44,12 +44,12 @@ namespace build2 } if (l.defined () && current_mif->id == configure_id) - save_variable (r, var); + save_variable (r, var); - return pair (l.value, n); + return pair (l, n); } - const value& + lookup optional (scope& r, const variable& var) { if (current_mif->id == configure_id) @@ -57,8 +57,8 @@ namespace build2 auto l (r[var]); return l.defined () - ? *l - : r.assign (var); // NULL. + ? l + : lookup (r.assign (var), r); // NULL. } bool diff --git a/build2/config/utility.txx b/build2/config/utility.txx index b6859d0..1434406 100644 --- a/build2/config/utility.txx +++ b/build2/config/utility.txx @@ -10,7 +10,7 @@ namespace build2 namespace config { template - pair, bool> + pair required (scope& root, const variable& var, const T& def_val, @@ -60,7 +60,7 @@ namespace build2 } } - return pair, bool> (*l, n); + return pair (l, n); } } } -- cgit v1.1