From d304762e4338b4a055e2be018205a00c2ca9ee2f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 9 Mar 2018 15:06:27 +0200 Subject: Support for resolving and adding configurations --- bdep/init.cxx | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 7 deletions(-) (limited to 'bdep/init.cxx') diff --git a/bdep/init.cxx b/bdep/init.cxx index 1e850b8..2355498 100644 --- a/bdep/init.cxx +++ b/bdep/init.cxx @@ -4,7 +4,9 @@ #include +#include #include +#include #include using namespace std; @@ -16,18 +18,102 @@ namespace bdep { tracer trace ("init"); - //@@ TODO: validate project/config options for sub-modes. - //@@ TODO: print project/package(s) being initialized. - project_packages pp ( - find_project_packages (o, - o.empty () /* ignore_packages */)); + find_project_packages (o, o.empty () /* ignore_packages */)); - text << pp.project; + const dir_path& prj (pp.project); + text << prj; for (const dir_path& d: pp.packages) - text << " " << (pp.project / d); + text << " " << (prj / d); + + // Create .bdep/. + // + { + dir_path d (prj / bdep_dir); + + if (!exists (d)) + mk (prj / bdep_dir); + } + + // Open the database creating it if necessary. + // + database db (open (pp.project, trace, true /* create */)); + + // --empty + // + bool ca (o.config_add_specified ()); + bool cc (o.config_create_specified ()); + + if (o.empty ()) + { + if (ca) fail << "both --empty and --config-add specified"; + if (cc) fail << "both --empty and --config-create specified"; + + //@@ TODO: what should we do if the database already exists? + + return 0; + } + + // Make sure everyone refers to the same objects across all the + // transactions. + // + session s; + + // --config-add/create + // + configurations cfgs; + if (ca || cc) + { + const char* m (!ca ? "--config-create" : + !cc ? "--config-add" : + nullptr); + + if (m == nullptr) + fail << "both --config-add and --config-create specified"; + + optional name; + if (size_t n = o.config_name ().size ()) + { + if (n > 1) + fail << "multiple configuration names specified for " << m; + + name = o.config_name ()[0]; + } + + optional id; + if (size_t n = o.config_id ().size ()) + { + if (n > 1) + fail << "multiple configuration ids specified for " << m; + + id = o.config_id ()[0]; + } + + cfgs.push_back ( + ca + ? cmd_config_add (prj, + db, + o.config_add (), + move (name), + nullopt /* default */, // @@ TODO: --[no]-default + move (id)) + : nullptr); // @@ TODO: create + + // Fall through. + } + + transaction t (db.begin ()); + + // If this is the default mode, then find the configurations the user + // wants us to use. + // + if (cfgs.empty ()) + cfgs = find_configurations (prj, t, o); + + //@@ TODO: print project/package(s) being initialized. + t.commit (); return 0; } } -- cgit v1.1