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/bdep.cxx | 9 +++--- bdep/config.cxx | 8 ++--- bdep/project.cli | 6 ++-- bdep/project.cxx | 99 ++++++++++++++++++++++++++++++++++++++------------------ bdep/sync.cxx | 10 ++++-- 5 files changed, 88 insertions(+), 44 deletions(-) (limited to 'bdep') diff --git a/bdep/bdep.cxx b/bdep/bdep.cxx index da64ce5..0229776 100644 --- a/bdep/bdep.cxx +++ b/bdep/bdep.cxx @@ -112,14 +112,14 @@ namespace bdep // arguments and place them into configuration_name_options::config_name. // static inline bool -cfg_name (configuration_name_options* o, const char* a) +cfg_name (configuration_name_options* o, const char* a, size_t p) { string n (a); if (n.empty ()) fail << "empty configuration name"; - o->config_name ().push_back (move (n)); + o->config_name ().emplace_back (move (n), p); o->config_name_specified (true); return true; } @@ -182,8 +182,9 @@ init (const common_options& co, // @ & -@ // - if ((*a == '@' && cfg_name (&o, a + 1)) || - (*a == '-' && a[1] == '@' && cfg_name (&o, a + 2))) + size_t p (scan.position ()); + if ((*a == '@' && cfg_name (&o, a + 1, p)) || + (*a == '-' && a[1] == '@' && cfg_name (&o, a + 2, p))) { scan.next (); continue; diff --git a/bdep/config.cxx b/bdep/config.cxx index f16d8b0..c8954b3 100644 --- a/bdep/config.cxx +++ b/bdep/config.cxx @@ -79,7 +79,7 @@ namespace bdep if (n > 1) fail << "multiple configuration names specified for " << what; - name = o.config_name ()[0]; + name = o.config_name ()[0].first; } if (size_t n = o.config_id ().size ()) @@ -87,7 +87,7 @@ namespace bdep if (n > 1) fail << "multiple configuration ids specified for " << what; - id = o.config_id ()[0]; + id = o.config_id ()[0].first; } } @@ -673,13 +673,13 @@ namespace bdep } else { - strings& ns (o.config_name ()); + vector>& ns (o.config_name ()); size_t n (ns.size ()); if (n > 1 || (n == 1 && (o.config_specified () || o.config_id_specified ()))) { - name = move (ns.back ()); + name = move (ns.back ().first); ns.pop_back (); } else diff --git a/bdep/project.cli b/bdep/project.cli index 17ef72e..6a1c4f0 100644 --- a/bdep/project.cli +++ b/bdep/project.cli @@ -75,13 +75,13 @@ namespace bdep // Note that this is also used as storage for configuration names // specified as @. // - strings --config-name|-n + vector> --config-name|-n { "", "Specify the build configuration as a name." }; - vector --config-id + vector> --config-id { "", "Specify the build configuration as an id." @@ -98,7 +98,7 @@ namespace bdep "Use all build configurations." } - dir_paths --config|-c + vector> --config|-c { "", "Specify the build configuration as a directory." 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) diff --git a/bdep/sync.cxx b/bdep/sync.cxx index 0d5132f..c8a7e4b 100644 --- a/bdep/sync.cxx +++ b/bdep/sync.cxx @@ -804,8 +804,10 @@ namespace bdep // optional open (getenv ("BPKG_OPEN_CONFIGS")); - for (dir_path d: o.config ()) + for (const pair& c: o.config ()) { + dir_path d (c.first); + normalize (d, "configuration"); if (open && contains (*open, d)) @@ -955,7 +957,11 @@ namespace bdep { add ("sync-implicit"); - r.start = default_options_start (home_directory (), o.config ()); + const vector>& cs (o.config ()); + r.start = default_options_start (home_directory (), + cs.begin (), + cs.end (), + [] (auto i) {return i->first;}); } else { -- cgit v1.1