From eb02d377f4f10e23cc6673e9e8f048b4ecbc8492 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 3 Aug 2021 20:31:37 +0300 Subject: Make find_configurations() to preserve configurations order on command line --- bdep/project.cxx | 99 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 68 insertions(+), 31 deletions(-) (limited to 'bdep/project.cxx') diff --git a/bdep/project.cxx b/bdep/project.cxx index ace8e3b..8280a48 100644 --- a/bdep/project.cxx +++ b/bdep/project.cxx @@ -42,49 +42,84 @@ namespace bdep database& db (t.database ()); using query = bdep::query; - // @ - // - if (po.config_name_specified ()) { - for (const string& n: po.config_name ()) + // @ + // + const vector>& ns (po.config_name ()); + auto ni (ns.begin ()); + auto ne (ns.end ()); + + // --config + // + const vector>& ds (po.config ()); + auto di (ds.begin ()); + auto de (ds.end ()); + + // --config-id + // + const vector>& is (po.config_id ()); + auto ii (is.begin ()); + auto ie (is.end ()); + + // Return true if the first options range is not empty and position of + // its leftmost option is less than positions in two other option + // ranges. + // + auto lt = [] (auto oi1, auto oe1, auto oi2, auto oe2, auto oi3, auto oe3) { - if (auto c = db.query_one (query::name == n)) - add (move (c)); - else - fail << "no configuration name '" << n << "' in project " << prj; - } - } + return oi1 != oe1 && + (oi2 == oe2 || oi2->second > oi1->second) && + (oi3 == oe3 || oi3->second > oi1->second); + }; - // --config - // - if (po.config_specified ()) - { - for (dir_path d: po.config ()) + while (ni != ne || di != de || ii != ie) { - normalize (d, "configuration"); + if (lt (ni, ne, di, de, ii, ie)) + { + const string& n (ni->first); - if (auto c = db.query_one (query::path == d.string ())) - add (move (c)); - else - fail << "no configuration directory " << d << " in project " << prj; - } - } + if (auto c = db.query_one (query::name == n)) + add (move (c)); + else + fail << "no configuration name '" << n << "' in project " << prj; - // --config-id - // - if (po.config_id_specified ()) - { - for (uint64_t id: po.config_id ()) - { - if (auto c = db.find (id)) - add (move (c)); + ++ni; + } + else if (lt (di, de, ii, ie, ni, ne)) + { + dir_path d (di->first); + + normalize (d, "configuration"); + + if (auto c = db.query_one (query::path == + d.string ())) + add (move (c)); + else + fail << "no configuration directory " << d << " in project " + << prj; + + ++di; + } + else if (lt (ii, ie, ni, ne, di, de)) + { + uint64_t id (ii->first); + + if (auto c = db.find (id)) + add (move (c)); + else + fail << "no configuration id " << id << " in project " << prj; + + ++ii; + } else - fail << "no configuration id " << id << " in project " << prj; + assert (false); } } // --all // + // Add configurations unordered. + // if (po.all ()) { for (auto c: pointer_result (db.query ())) @@ -96,6 +131,8 @@ namespace bdep // default // + // Add configurations unordered. + // if (r.empty ()) { if (fallback_default) -- cgit v1.1