diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-03-09 15:06:27 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2018-03-09 15:06:27 +0200 |
commit | d304762e4338b4a055e2be018205a00c2ca9ee2f (patch) | |
tree | 252a4aa70118135e589095442fb4df3879c96eb0 /bdep/init.cxx | |
parent | df5e58e6e5eb2727a185bf9a98a462c18fa3a83d (diff) |
Support for resolving and adding configurations
Diffstat (limited to 'bdep/init.cxx')
-rw-r--r-- | bdep/init.cxx | 100 |
1 files changed, 93 insertions, 7 deletions
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 <bdep/init.hxx> +#include <bdep/config.hxx> #include <bdep/project.hxx> +#include <bdep/database.hxx> #include <bdep/diagnostics.hxx> 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<string> 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<uint64_t> 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; } } |