From 04be612dead00c36c8c6ff748c252e8e5d3b1e5c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 24 Oct 2019 11:49:44 +0200 Subject: Allow multiple forwarded configurations The new constraint is that such configurations should not have any common packages (a package cannot be forwarded to multiple configurations). --- bdep/config.cli | 7 +++++-- bdep/config.cxx | 38 ++++++++++++++++++++++++-------------- bdep/init.cxx | 27 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/bdep/config.cli b/bdep/config.cli index 3ad2bb9..818f600 100644 --- a/bdep/config.cli +++ b/bdep/config.cli @@ -90,8 +90,11 @@ namespace bdep configuration is already designated as forwarded. When a project is initialized in a forwarded build configuration, its source directory is configured to forward to this configuration (see \l{b(1)} for - details on forwarded configurations). To forward to a non-default - configuration use the \cb{--forward} option. + details on forwarded configurations). To designate a non-default + configuration as forwarded use the \cb{--forward} option. Note also + that it is possible to have multiple forwarded configurations, + however, any given package within a project can only be initialized + in one such configuration. Unless the \cb{--no-auto-sync} option is specified, an added or created build configuration will be automatically synchronized on diff --git a/bdep/config.cxx b/bdep/config.cxx index d8cf33a..f08bd41 100644 --- a/bdep/config.cxx +++ b/bdep/config.cxx @@ -187,20 +187,14 @@ namespace bdep info << "use 'bdep config set --no-default' to clear"; } - // By default the default configuration is forwarded unless another - // is already forwarded. + // By default the default configuration is forwarded unless another is + // already forwarded. // if (ao.forward () || ao.no_forward ()) fwd = ao.forward () && !ao.no_forward (); if (!fwd) fwd = *def && db.query_one (query::forward) == nullptr; - else if (*fwd) - { - if (auto p = db.query_one (query::forward)) - fail << "configuration " << *p << " is already forwarded" << - info << "use 'bdep config set --no-forward' to clear"; - } } shared_ptr r ( @@ -701,23 +695,39 @@ namespace bdep info << "while updating configuration " << *c; } - c->default_ = *d; + c->default_ = *d; } if (f) { if (*f && !c->forward) { - if (auto p = db.query_one (query::forward)) - fail << "configuration " << *p << " is already forwarded" << - info << "while updating configuration " << *c; + // Make sure there are no other forwarded configurations with the + // same package as us. + // + for (const shared_ptr& o: + pointer_result (db.query (query::forward))) + { + auto i (find_first_of ( + o->packages.begin (), o->packages.end (), + c->packages.begin (), c->packages.end (), + [] (const package_state& x, const package_state& y) + { + return x.name == y.name; + })); + + if (i != o->packages.end ()) + fail << "configuration " << *o << " is also forwarded and " + << "also has package " << i->name << " initialized" << + info << "while updating configuration " << *c; + } } - c->forward = *f; + c->forward = *f; } if (s) - c->auto_sync = *s; + c->auto_sync = *s; db.update (c); } diff --git a/bdep/init.cxx b/bdep/init.cxx index 04afd3c..1e794f8 100644 --- a/bdep/init.cxx +++ b/bdep/init.cxx @@ -94,6 +94,33 @@ namespace bdep continue; } + // If this configuration is forwarded, verify there is no other + // forwarded configuration that also has this package. + // + if (c->forward) + { + using query = bdep::query; + + for (const shared_ptr& o: + pointer_result (db.query (query::forward))) + { + if (o == c) + continue; + + if (find_if (o->packages.begin (), + o->packages.end (), + [&p] (const package_state& s) + { + return p.name == s.name; + }) != o->packages.end ()) + { + fail << "forwarded configuration " << *o << " also has package " + << p.name << " initialized" << + info << "while initializing in forwarded configuration " << *c; + } + } + } + // If we are initializing multiple packages, print their names. // if (verb && pkgs.size () > 1) -- cgit v1.1