From c6265603e0e98c19f8d81c8edd5a34a550063c02 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 23 Nov 2016 09:53:18 +0200 Subject: Add support for config.cli=false (leave unconfigured) --- build2/cli/init.cxx | 57 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 19 deletions(-) (limited to 'build2/cli') diff --git a/build2/cli/init.cxx b/build2/cli/init.cxx index 093cdbb..3cb1f98 100644 --- a/build2/cli/init.cxx +++ b/build2/cli/init.cxx @@ -28,7 +28,7 @@ namespace build2 bool config_init (scope& rs, scope& bs, - const location&, + const location& l, unique_ptr&, bool first, bool optional, @@ -47,6 +47,9 @@ namespace build2 // Note: some overridable, some not. // + // The config.cli=false is recognized as an explicit request to leave + // the module unconfigured. + // v.insert ("config.cli", true); v.insert ("config.cli.options", true); @@ -59,17 +62,33 @@ namespace build2 // The plan is as follows: try to configure the module. If this fails, // we are using default values, and the module is optional, leave it // unconfigured. - // - // We will only honor optional if the user didn't specify any cli - // configuration explicitly. + // First take care of the explicit request by the user to leave the + // module unconfigured. // - optional = optional && !config::specified (rs, "config.cli"); + bool conf (true); - // If the configuration says we are unconfigured, then we don't need to - // re-run tests, etc. But we may still need to print the config report. - // - bool conf (!optional || !config::unconfigured (rs, "config.cli")); + if (const path* p = cast_null (rs["config.cli"])) + { + conf = p->string () != "false"; + + if (!conf && !optional) + fail (l) << "non-optional module requested to be left unconfigured"; + } + + if (conf) + { + // Otherwise we will only honor optional if the user didn't specify + // any cli configuration explicitly. + // + optional = optional && !config::specified (rs, "config.cli"); + + // If the configuration says we are unconfigured, then we should't + // re-run tests, etc. But we may still need to print the config + // report. + // + conf = !optional || !config::unconfigured (rs, "config.cli"); + } if (first) { @@ -168,13 +187,7 @@ namespace build2 ver = test (cli); if (ver.empty ()) - { - // Note that we are unconfigured so that we don't keep - // re-testing this on each run. - // - config::unconfigured (rs, "config.cli", true); conf = false; - } else { auto p (config::required (rs, "config.cli", cli)); @@ -197,6 +210,12 @@ namespace build2 nv = p.second; } + // Note that we are unconfigured so that we don't keep re-testing this + // on each run. + // + if (!conf) + nv = config::unconfigured (rs, "config.cli", true) || nv; + // If this is a new value (e.g., we are configuring), then print the // report at verbosity level 2 and up (-v). // @@ -234,7 +253,7 @@ namespace build2 bool init (scope& rs, scope& bs, - const location& loc, + const location& l, unique_ptr&, bool, bool optional, @@ -249,19 +268,19 @@ namespace build2 // the user load cxx explicitly. // if (!cast_false (bs["cxx.loaded"])) - fail (loc) << "cxx module must be loaded before cli"; + fail (l) << "cxx module must be loaded before cli"; // Load cli.config. // if (!cast_false (bs["cli.config.loaded"])) { - if (!load_module ("cli.config", rs, bs, loc, optional, hints)) + if (!load_module ("cli.config", rs, bs, l, optional, hints)) return false; } else if (!cast_false (bs["cli.config.configured"])) { if (!optional) - fail << "cli module could not be configured" << + fail (l) << "cli module could not be configured" << info << "re-run with -V option for more information"; return false; -- cgit v1.1