aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-08-23 07:16:05 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-08-23 07:16:05 +0200
commit17aac22d51c47ebef979ea1e828afb8548d6fbbb (patch)
tree44f4718f06a10cfd13bddc74bcac6f7cd50b4ec0
parent3e9c6f5d168387e6e5d9240b9e0e201f661da913 (diff)
Split cli module into cli.config and cli
-rw-r--r--build2/b.cxx1
-rw-r--r--build2/cli/init9
-rw-r--r--build2/cli/init.cxx120
3 files changed, 87 insertions, 43 deletions
diff --git a/build2/b.cxx b/build2/b.cxx
index 8114d78..81e1b2f 100644
--- a/build2/b.cxx
+++ b/build2/b.cxx
@@ -240,6 +240,7 @@ main (int argc, char* argv[])
bm["cxx.config"] = mf {nullptr, &cxx::config_init};
bm["cxx"] = mf {nullptr, &cxx::init};
+ bm["cli.config"] = mf {nullptr, &cli::config_init};
bm["cli"] = mf {nullptr, &cli::init};
}
diff --git a/build2/cli/init b/build2/cli/init
index 917ab35..8aee0b7 100644
--- a/build2/cli/init
+++ b/build2/cli/init
@@ -15,6 +15,15 @@ namespace build2
namespace cli
{
bool
+ config_init (scope&,
+ scope&,
+ const location&,
+ unique_ptr<module_base>&,
+ bool,
+ bool,
+ const variable_map&);
+
+ bool
init (scope&,
scope&,
const location&,
diff --git a/build2/cli/init.cxx b/build2/cli/init.cxx
index 49947f5..f2a3e8c 100644
--- a/build2/cli/init.cxx
+++ b/build2/cli/init.cxx
@@ -26,28 +26,20 @@ namespace build2
static compile compile_;
bool
- init (scope& rs,
- scope& bs,
- const location& loc,
- unique_ptr<module_base>&,
- bool first,
- bool optional,
- const variable_map& config_hints)
+ config_init (scope& rs,
+ scope& bs,
+ const location&,
+ unique_ptr<module_base>&,
+ bool first,
+ bool optional,
+ const variable_map& hints)
{
- tracer trace ("cli::init");
+ tracer trace ("cli::config_init");
l5 ([&]{trace << "for " << bs.out_path ();});
- assert (config_hints.empty ()); // We don't known any hints.
+ assert (hints.empty ()); // We don't known any hints.
- // Make sure the cxx module has been loaded since we need its targets
- // types (?xx{}). Note that we don't try to load it ourselves because of
- // the non-trivial variable merging semantics. So it is better to let
- // the user load cxx explicitly.
- //
- if (!cast_false<bool> (bs["cxx.loaded"]))
- fail (loc) << "cxx module must be loaded before cli";
-
- // Enter module variables.
+ // Enter variables.
//
if (first)
{
@@ -62,15 +54,6 @@ namespace build2
v.insert<strings> ("cli.options");
}
- // Register target types.
- //
- {
- auto& t (bs.target_types);
-
- t.insert<cli> ();
- t.insert<cli_cxx> ();
- }
-
// Configure.
//
// The plan is as follows: try to configure the module. If this fails,
@@ -86,7 +69,7 @@ namespace build2
// 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 unconf (optional && config::unconfigured (rs, "config.cli"));
+ bool conf (!optional || !config::unconfigured (rs, "config.cli"));
if (first)
{
@@ -180,7 +163,7 @@ namespace build2
// so that if we fail to configure, nothing will be written to
// config.build.
//
- if (!unconf)
+ if (conf)
{
ver = test (cli);
@@ -190,7 +173,7 @@ namespace build2
// re-testing this on each run.
//
config::unconfigured (rs, "config.cli", true);
- unconf = true;
+ conf = false;
}
else
{
@@ -222,30 +205,81 @@ namespace build2
diag_record dr (text);
dr << "cli " << project (rs) << '@' << rs.out_path () << '\n';
- if (unconf)
- dr << " cli " << "not found, leaving unconfigured";
- else
+ if (conf)
dr << " cli " << pp << '\n'
<< " version " << ver;
+ else
+ dr << " cli " << "not found, leaving unconfigured";
}
- if (!unconf)
+ if (conf)
rs.assign<process_path> ("cli.path") = move (pp);
}
- // Nothing else to do if we are unconfigured.
+ if (conf)
+ {
+ // config.cli.options
+ //
+ // This one is optional. We also merge it into the corresponding
+ // cli.* variables. See the cxx module for more information on
+ // this merging semantics and some of its tricky aspects.
+ //
+ bs.assign ("cli.options") += cast_null<strings> (
+ config::optional (rs, "config.cli.options"));
+ }
+
+ return conf;
+ }
+
+ bool
+ init (scope& rs,
+ scope& bs,
+ const location& loc,
+ unique_ptr<module_base>&,
+ bool,
+ bool optional,
+ const variable_map& hints)
+ {
+ tracer trace ("cli::init");
+ l5 ([&]{trace << "for " << bs.out_path ();});
+
+ // Make sure the cxx module has been loaded since we need its targets
+ // types (?xx{}). Note that we don't try to load it ourselves because of
+ // the non-trivial variable merging semantics. So it is better to let
+ // the user load cxx explicitly.
//
- if (unconf)
- return false;
+ if (!cast_false<bool> (bs["cxx.loaded"]))
+ fail (loc) << "cxx module must be loaded before cli";
- // config.cli.options
+ // Register target types.
//
- // This one is optional. We also merge it into the corresponding
- // cli.* variables. See the cxx module for more information on
- // this merging semantics and some of its tricky aspects.
+ // Note that we do it even if the module is unconfigured. Failed that,
+ // writing a buildfile will be pretty hard (actually, a buildfile still
+ // needs to be prepared that the module itself won't be found and loaded
+ // by defining fallback target types). This will be a BC change.
+ //
+ {
+ auto& t (bs.target_types);
+
+ t.insert<cli> ();
+ t.insert<cli_cxx> ();
+ }
+
+ // Load cli.config.
//
- bs.assign ("cli.options") += cast_null<strings> (
- config::optional (rs, "config.cli.options"));
+ if (!cast_false<bool> (bs["cli.config.loaded"]))
+ {
+ if (!load_module ("cli.config", rs, bs, loc, optional, hints))
+ return false;
+ }
+ else if (!cast_false<bool> (bs["cli.config.configured"]))
+ {
+ if (!optional)
+ fail << "cli module could not be configured" <<
+ info << "re-run with -V option for more information";
+
+ return false;
+ }
// Register our rules.
//