From 028e10ba787a7dbb46e3fcba6f88f496b76cebc5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 27 Apr 2020 09:47:55 +0200 Subject: Add utility config::{assign,append}_config() functions --- libbuild2/config/utility.hxx | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'libbuild2') diff --git a/libbuild2/config/utility.hxx b/libbuild2/config/utility.hxx index ee266f1..614791f 100644 --- a/libbuild2/config/utility.hxx +++ b/libbuild2/config/utility.hxx @@ -250,11 +250,53 @@ namespace build2 new_value, rs, var, string (default_value), save_flags, override); } + // Helper functions for assigning/appending config.x.y value to x.y, + // essentially: + // + // rs.assign (var) = lookup_config (rs, "config." + var, default_value); + // rs.append (var) += lookup_config (rs, "config." + var, default_value); + // + template + inline const V* + assign_config (scope& rs, scope& bs, string var, T&& default_value) + { + const V* cv ( + cast_null ( + lookup_config (rs, + rs.var_pool ().insert ("config." + var), + std::forward (default_value)))); // VC14 + + value& v (bs.assign (move (var))); + + if (cv != nullptr) + v = *cv; + + return v.null ? nullptr : &v.as (); + } + + template + inline const V* + append_config (scope& rs, scope& bs, string var, T&& default_value) + { + const V* cv ( + cast_null ( + lookup_config (rs, + rs.var_pool ().insert ("config." + var), + std::forward (default_value)))); // VC14 + + value& v (bs.append (move (var))); + + if (cv != nullptr) + v += *cv; + + return v.null ? nullptr : &v.as (); + } + // Check whether there are any variables specified from the config. // namespace. The idea is that we can check if there are any, say, // config.install.* values. If there are none, then we can assume this // functionality is not (yet) used and omit writing a whole bunch of NULL - // config.install.* values to the config.build file. We call this + // config.install.* values to the config.build file. We call this // omitted/delayed configuration. // // Note that this function detects and ignores special config.* variables -- cgit v1.1