From 2cc2772263d17a9b2755990d53e992a94d37e29d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 27 Mar 2020 10:39:52 +0200 Subject: Implement project configuration reporting, similar to build system modules --- libbuild2/file.cxx | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'libbuild2/file.cxx') diff --git a/libbuild2/file.cxx b/libbuild2/file.cxx index 613f095..405e1f0 100644 --- a/libbuild2/file.cxx +++ b/libbuild2/file.cxx @@ -3,6 +3,8 @@ #include +#include // left, setw() + #include #include #include @@ -1297,6 +1299,72 @@ namespace build2 if (he) {source_hooks (p, root, hd, true /* pre */); p.reset ();} if (fe) {source_once (p, root, root, f, root);} if (he) {p.reset (); source_hooks (p, root, hd, false /* pre */);} + + // Print the project configuration report, similar to how we do it in + // build system modules. + // + if (!p.config_report.empty () && verb >= (p.config_report_new ? 2 : 3)) + { + const project_name& proj (named_project (root)); // Must be there. + + // @@ TODO/MAYBE: + // + // - Should we be printing NULL values? + // + + // Use the special `config` module name (which doesn't have its own + // report) for project configuration. + // + diag_record dr (text); + dr << "config " << proj << '@' << root; + + // Printing the whole variable name would add too much noise with all + // the repetitive config.. So we are only going to print the + // part after (see parser::parse_config() for details). + // + string stem ('.' + proj.variable () + '.'); + + names storage; + for (const pair& lf: p.config_report) + { + lookup l (lf.first); + const string& f (lf.second); + + // If the report variable has been overriden, now is the time to + // lookup its value. + // + string n; + if (l.value == nullptr) + { + n = l.var->name; // Use the name as is. + l = root[*l.var]; + } + else + { + size_t p (l.var->name.find (stem)); // Must be there. + n = string (l.var->name, p + stem.size ()); + } + + dr << "\n "; + + if (const value& v = *l) + { + storage.clear (); + auto ns (reverse (v, storage)); + + if (f == "multiline") + { + dr << n; + for (auto& n: ns) + dr << "\n " << n; + } + else + dr << left << setw (10) << n << ' ' << ns; + } + else + dr << left << setw (10) << n << " [null]"; + } + } } scope& -- cgit v1.1