aboutsummaryrefslogtreecommitdiff
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
parent562fee6a0ce42f6dd2d6acbc7d88dc9b00f50d0e (diff)
Make find_configurations() to preserve configurations order on command line
-rw-r--r--bdep/bdep.cxx9
-rw-r--r--bdep/config.cxx8
-rw-r--r--bdep/project.cli6
-rw-r--r--bdep/project.cxx99
-rw-r--r--bdep/sync.cxx10
5 files changed, 88 insertions, 44 deletions
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,
// @<cfg-name> & -@<cfg-name>
//
- 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<pair<string, size_t>>& 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 @<name>.
//
- strings --config-name|-n
+ vector<pair<string, size_t>> --config-name|-n
{
"<name>",
"Specify the build configuration as a name."
};
- vector<uint64_t> --config-id
+ vector<pair<uint64_t, size_t>> --config-id
{
"<num>",
"Specify the build configuration as an id."
@@ -98,7 +98,7 @@ namespace bdep
"Use all build configurations."
}
- dir_paths --config|-c
+ vector<pair<dir_path, size_t>> --config|-c
{
"<dir>",
"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<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)
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<string> open (getenv ("BPKG_OPEN_CONFIGS"));
- for (dir_path d: o.config ())
+ for (const pair<dir_path, size_t>& 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<pair<dir_path, size_t>>& cs (o.config ());
+ r.start = default_options_start (home_directory (),
+ cs.begin (),
+ cs.end (),
+ [] (auto i) {return i->first;});
}
else
{