From bbd0f3bb21442a2833916110cbe8e9a07e9f4c1f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 31 Jul 2015 12:52:20 +0200 Subject: Essential install module functionality --- build/config/utility | 58 ++++++++++++++++++++++++------------------------ build/config/utility.cxx | 30 +++++++++++++++++++++++++ build/config/utility.txx | 24 ++++++++++++++++++++ 3 files changed, 83 insertions(+), 29 deletions(-) (limited to 'build/config') diff --git a/build/config/utility b/build/config/utility index 713ab01..ef3ceed 100644 --- a/build/config/utility +++ b/build/config/utility @@ -27,6 +27,13 @@ namespace build std::pair required (scope& root, const char* name, const T& default_value); + template + inline std::pair + required (scope& root, const std::string& name, const T& default_value) + { + return required (root, name.c_str (), default_value); + } + std::pair required (scope& root, const char* name, const char* default_value); @@ -48,45 +55,38 @@ namespace build return optional (root, name.c_str ()); } + // 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 config.build. We call it omitted/delayed + // configuration. + // + bool + specified (scope& root, const std::string& ns); + + // @@ Why are these here? + // + // Add all the values from a variable to the C-string list. T is // either target or scope. // template void - append_options (cstrings& args, T& s, const char* var) - { - if (auto val = s[var]) - { - for (const name& n: val.template as ()) - { - if (n.simple ()) - args.push_back (n.value.c_str ()); - else if (n.directory ()) - args.push_back (n.dir.string ().c_str ()); - else - fail << "expected option instead of " << n << - info << "in variable " << var; - } - } - } + append_options (cstrings& args, T& s, const char* var); + + // As above but from the list value directly. Variable name is for + // diagnostics. + // + void + append_options (cstrings& args, const list_value&, const char* var); // Check if a specified option is present. T is either target or scope. // template bool - find_option (const char* option, T& s, const char* var) - { - if (auto val = s[var]) - { - for (const name& n: val.template as ()) - { - if (n.simple () && n.value == option) - return true; - } - } - - return false; - } + find_option (const char* option, T& s, const char* var); } } diff --git a/build/config/utility.cxx b/build/config/utility.cxx index 212d030..e2afc80 100644 --- a/build/config/utility.cxx +++ b/build/config/utility.cxx @@ -37,5 +37,35 @@ namespace build return pair (v.as (), true); } + + bool + specified (scope& r, const string& ns) + { + // Search all outer scopes for any value in this namespace. + // + for (scope* s (&r); s != nullptr; s = s->parent_scope ()) + { + auto p (s->vars.find_namespace (ns)); + if (p.first != p.second) + return true; + } + + return false; + } + + void + append_options (cstrings& args, const list_value& lv, const char* var) + { + for (const name& n: lv) + { + if (n.simple ()) + args.push_back (n.value.c_str ()); + else if (n.directory ()) + args.push_back (n.dir.string ().c_str ()); + else + fail << "expected option instead of " << n << + info << "in variable " << var; + } + } } } diff --git a/build/config/utility.txx b/build/config/utility.txx index bee8a0b..cffdecf 100644 --- a/build/config/utility.txx +++ b/build/config/utility.txx @@ -57,5 +57,29 @@ namespace build return r; } + + template + void + append_options (cstrings& args, T& s, const char* var) + { + if (auto val = s[var]) + append_options (args, val.template as (), var); + } + + template + bool + find_option (const char* option, T& s, const char* var) + { + if (auto val = s[var]) + { + for (const name& n: val.template as ()) + { + if (n.simple () && n.value == option) + return true; + } + } + + return false; + } } } -- cgit v1.1