aboutsummaryrefslogtreecommitdiff
path: root/bdep/project.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2021-08-03 20:31:37 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-08-05 11:29:51 +0300
commiteb02d377f4f10e23cc6673e9e8f048b4ecbc8492 (patch)
tree3e93aa4cb405ff9207dc714c29b6321f9f9d31fa /bdep/project.cxx
parent562fee6a0ce42f6dd2d6acbc7d88dc9b00f50d0e (diff)
Make find_configurations() to preserve configurations order on command line
Diffstat (limited to 'bdep/project.cxx')
-rw-r--r--bdep/project.cxx99
1 files changed, 68 insertions, 31 deletions
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<configuration>;
- // @<cfg-name>
- //
- if (po.config_name_specified ())
{
- for (const string& n: po.config_name ())
+ // @<cfg-name>
+ //
+ const vector<pair<string, size_t>>& ns (po.config_name ());
+ auto ni (ns.begin ());
+ auto ne (ns.end ());
+
+ // --config <cfg-dir>
+ //
+ const vector<pair<dir_path, size_t>>& ds (po.config ());
+ auto di (ds.begin ());
+ auto de (ds.end ());
+
+ // --config-id <cfg-num>
+ //
+ const vector<pair<uint64_t, size_t>>& 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<configuration> (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 <cfg-dir>
- //
- 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<configuration> (query::path == d.string ()))
- add (move (c));
- else
- fail << "no configuration directory " << d << " in project " << prj;
- }
- }
+ if (auto c = db.query_one<configuration> (query::name == n))
+ add (move (c));
+ else
+ fail << "no configuration name '" << n << "' in project " << prj;
- // --config-id <cfg-num>
- //
- if (po.config_id_specified ())
- {
- for (uint64_t id: po.config_id ())
- {
- if (auto c = db.find<configuration> (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<configuration> (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<configuration> (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<configuration> ()))
@@ -96,6 +131,8 @@ namespace bdep
// default
//
+ // Add configurations unordered.
+ //
if (r.empty ())
{
if (fallback_default)