From 07ab59a93f9447d5489743e8d7e19b6adb5ebbf1 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 9 Jul 2021 20:55:15 +0300 Subject: Add support for configuration type and bdep-config-link sub-command --- bdep/status.cxx | 102 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 41 deletions(-) (limited to 'bdep/status.cxx') diff --git a/bdep/status.cxx b/bdep/status.cxx index 2e60b29..fc07698 100644 --- a/bdep/status.cxx +++ b/bdep/status.cxx @@ -50,34 +50,6 @@ namespace bdep pkgs); } - static void - cmd_status (const cmd_status_options& o, - const dir_path& prj, - const shared_ptr& c, - const package_locations& ps, - bool fetch) - { - assert (!c->packages.empty ()); - - // If no packages were explicitly specified, then we print the status for - // all that have been initialized in the configuration. - // - strings pkgs; - - if (ps.empty ()) - { - for (const package_state& p: c->packages) - pkgs.push_back (p.name.string ()); - } - else - { - for (const package_location& p: ps) - pkgs.push_back (p.name.string ()); - } - - cmd_status (o, prj, c->path, pkgs, fetch); - } - int cmd_status (const cmd_status_options& o, cli::scanner& args) { @@ -103,16 +75,23 @@ namespace bdep database db (open (prj, trace)); - transaction t (db.begin ()); - configurations cfgs (find_configurations (o, prj, t)); - t.commit (); + configurations cfgs; + { + transaction t (db.begin ()); + pair cs (find_configurations (o, prj, t)); + t.commit (); - // If specified, verify packages are present in each configuration. - // - if (!pp.packages.empty ()) - verify_project_packages (pp, cfgs); + // If specified, verify packages are present in at least one + // configuration. + // + if (!pp.packages.empty ()) + verify_project_packages (pp, cs); + + cfgs = move (cs.first); + } - // Print status in each configuration skipping empty ones. + // Print status in each configuration, skipping those where no package + // statuses needs to be printed. // bool first (true); for (const shared_ptr& c: cfgs) @@ -120,11 +99,50 @@ namespace bdep if (c->packages.empty ()) { if (verb) - info << "skipping empty configuration " << *c; + info << "skipping configuration " << *c << + info << "configuration is empty"; continue; } + // Collect the packages to print, unless the dependency packages are + // specified. + // + // If no packages were explicitly specified, then we print the status + // for all that have been initialized in the configuration. Otherwise, + // only for specified packages initialized in the (specified) + // configurations. + // + strings pkgs; + + if (dep_pkgs.empty ()) + { + const package_locations& ps (pp.packages); + bool all (ps.empty ()); + + for (const package_state& s: c->packages) + { + if (all || + find_if (ps.begin (), + ps.end (), + [&s] (const package_location& p) + { + return p.name == s.name; + }) != ps.end ()) + pkgs.push_back (s.name.string ()); + } + + if (pkgs.empty ()) + { + if (verb) + info << "skipping configuration " << *c << + info << "none of specified packages initialized in this " + << "configuration"; + + continue; + } + } + // If we are printing multiple configurations, separate them with a // blank line and print the configuration name/directory. // @@ -141,10 +159,12 @@ namespace bdep if (fetch) cmd_fetch (o, prj, c, o.fetch_full ()); - if (dep_pkgs.empty ()) - cmd_status (o, prj, c, pp.packages, !fetch); - else - cmd_status (o, prj, c->path, dep_pkgs, !fetch); + // Status for either packages or their dependencies must be printed, but + // not for both. + // + assert (pkgs.empty () == !dep_pkgs.empty ()); + + cmd_status (o, prj, c->path, !pkgs.empty () ? pkgs : dep_pkgs, !fetch); } return 0; -- cgit v1.1