aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-02 22:47:27 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-02 22:47:27 +0100
commit44d70450c5c24e8324c6ba87a027e6cd47f86895 (patch)
treeffe6f5bffe27603f986693b578015427f0dab103
parentf5bb0e4827bbc8d9bbab98c55fd3c9ad0093569b (diff)
downloadpaludis-44d70450c5c24e8324c6ba87a027e6cd47f86895.tar.gz
paludis-44d70450c5c24e8324c6ba87a027e6cd47f86895.tar.xz
parameterise use_installed
-rw-r--r--paludis/resolver/Makefile.am1
-rw-r--r--paludis/resolver/reason-fwd.hh2
-rw-r--r--paludis/resolver/reason.cc62
-rw-r--r--paludis/resolver/reason.hh44
-rw-r--r--paludis/resolver/resolver.cc82
-rw-r--r--paludis/resolver/resolver.hh13
-rw-r--r--paludis/resolver/resolver_functions-fwd.hh31
-rw-r--r--paludis/resolver/resolver_functions.hh50
-rw-r--r--src/clients/cave/cmd_resolve.cc127
9 files changed, 314 insertions, 98 deletions
diff --git a/paludis/resolver/Makefile.am b/paludis/resolver/Makefile.am
index 3042b46..65a723c 100644
--- a/paludis/resolver/Makefile.am
+++ b/paludis/resolver/Makefile.am
@@ -23,6 +23,7 @@ noinst_HEADERS = \
reason.hh reason-fwd.hh \
resolution.hh resolution-fwd.hh \
resolver.hh resolver-fwd.hh \
+ resolver_functions.hh resolver_functions-fwd.hh \
sanitised_dependencies.hh sanitised_dependencies-fwd.hh \
use_installed.hh use_installed-fwd.hh use_installed-se.hh
diff --git a/paludis/resolver/reason-fwd.hh b/paludis/resolver/reason-fwd.hh
index a0ef572..245f2e3 100644
--- a/paludis/resolver/reason-fwd.hh
+++ b/paludis/resolver/reason-fwd.hh
@@ -30,6 +30,8 @@ namespace paludis
struct Reason;
struct DependencyReason;
struct TargetReason;
+ struct PresetReason;
+ struct SetReason;
std::ostream & operator<< (std::ostream & s, const Reason &) PALUDIS_VISIBLE;
}
diff --git a/paludis/resolver/reason.cc b/paludis/resolver/reason.cc
index b668af9..fcffb91 100644
--- a/paludis/resolver/reason.cc
+++ b/paludis/resolver/reason.cc
@@ -43,18 +43,6 @@ TargetReason::as_string() const
return "Target()";
}
-DependencyReason *
-TargetReason::if_dependency_reason()
-{
- return 0;
-}
-
-const DependencyReason *
-TargetReason::if_dependency_reason() const
-{
- return 0;
-}
-
namespace paludis
{
template <>
@@ -98,17 +86,55 @@ DependencyReason::as_string() const
return "Dependency(package: " + stringify(_imp->qpn_s) + " dep: " + stringify(_imp->dep) + ")";
}
-DependencyReason *
-DependencyReason::if_dependency_reason()
+std::string
+PresetReason::as_string() const
+{
+ return "Preset()";
+}
+
+namespace paludis
+{
+ template <>
+ struct Implementation<SetReason>
+ {
+ const SetName set_name;
+ const std::tr1::shared_ptr<const Reason> reason_for_set;
+
+ Implementation(const SetName & s, const std::tr1::shared_ptr<const Reason> & r) :
+ set_name(s),
+ reason_for_set(r)
+ {
+ }
+ };
+}
+
+SetReason::SetReason(const SetName & s, const std::tr1::shared_ptr<const Reason> & r) :
+ PrivateImplementationPattern<SetReason>(new Implementation<SetReason>(s, r))
+{
+}
+
+SetReason::~SetReason()
{
- return this;
}
-const DependencyReason *
-DependencyReason::if_dependency_reason() const
+const SetName
+SetReason::set_name() const
+{
+ return _imp->set_name;
+}
+
+const std::tr1::shared_ptr<const Reason>
+SetReason::reason_for_set() const
+{
+ return _imp->reason_for_set;
+}
+
+std::string
+SetReason::as_string() const
{
- return this;
+ return "Set(set: " + stringify(_imp->set_name) + " because: " + stringify(*_imp->reason_for_set) + ")";
}
template class PrivateImplementationPattern<DependencyReason>;
+template class PrivateImplementationPattern<SetReason>;
diff --git a/paludis/resolver/reason.hh b/paludis/resolver/reason.hh
index 620dd75..0778800 100644
--- a/paludis/resolver/reason.hh
+++ b/paludis/resolver/reason.hh
@@ -24,33 +24,36 @@
#include <paludis/resolver/qpn_s-fwd.hh>
#include <paludis/resolver/sanitised_dependencies-fwd.hh>
#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/util/simple_visitor.hh>
+#include <paludis/util/type_list.hh>
+#include <paludis/name-fwd.hh>
+#include <tr1/memory>
namespace paludis
{
namespace resolver
{
- class Reason
+ class Reason :
+ public virtual DeclareAbstractAcceptMethods<Reason, MakeTypeList<
+ TargetReason, DependencyReason, PresetReason, SetReason>::Type>
{
public:
virtual ~Reason() = 0;
virtual std::string as_string() const = 0;
-
- virtual DependencyReason * if_dependency_reason() = 0;
- virtual const DependencyReason * if_dependency_reason() const = 0;
};
class TargetReason :
- public Reason
+ public Reason,
+ public ImplementAcceptMethods<Reason, TargetReason>
{
public:
virtual std::string as_string() const;
- virtual DependencyReason * if_dependency_reason();
- virtual const DependencyReason * if_dependency_reason() const;
};
class DependencyReason :
private PrivateImplementationPattern<DependencyReason>,
- public Reason
+ public Reason,
+ public ImplementAcceptMethods<Reason, DependencyReason>
{
public:
DependencyReason(
@@ -60,19 +63,38 @@ namespace paludis
~DependencyReason();
const QPN_S qpn_s() const;
-
const SanitisedDependency & sanitised_dependency() const;
virtual std::string as_string() const;
+ };
+
+ class PresetReason :
+ public Reason,
+ public ImplementAcceptMethods<Reason, PresetReason>
+ {
+ public:
+ virtual std::string as_string() const;
+ };
+
+ class SetReason :
+ public Reason,
+ private PrivateImplementationPattern<SetReason>,
+ public ImplementAcceptMethods<Reason, SetReason>
+ {
+ public:
+ SetReason(const SetName &, const std::tr1::shared_ptr<const Reason> &);
+ ~SetReason();
- virtual DependencyReason * if_dependency_reason();
+ const SetName set_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
+ const std::tr1::shared_ptr<const Reason> reason_for_set() const PALUDIS_ATTRIBUTE((warn_unused_result));
- virtual const DependencyReason * if_dependency_reason() const;
+ virtual std::string as_string() const;
};
}
#ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
extern template class PrivateImplementationPattern<resolver::DependencyReason>;
+ extern template class PrivateImplementationPattern<resolver::SetReason>;
#endif
}
diff --git a/paludis/resolver/resolver.cc b/paludis/resolver/resolver.cc
index e65ca17..ea4ff03 100644
--- a/paludis/resolver/resolver.cc
+++ b/paludis/resolver/resolver.cc
@@ -26,11 +26,13 @@
#include <paludis/resolver/arrow.hh>
#include <paludis/resolver/decision.hh>
#include <paludis/resolver/destinations.hh>
+#include <paludis/resolver/resolver_functions.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/make_named_values.hh>
#include <paludis/util/log.hh>
#include <paludis/util/join.hh>
#include <paludis/util/wrapped_forward_iterator-impl.hh>
+#include <paludis/util/simple_visitor_cast.hh>
#include <paludis/environment.hh>
#include <paludis/notifier_callback.hh>
#include <paludis/dep_spec_flattener.hh>
@@ -66,19 +68,22 @@ namespace paludis
struct Implementation<Resolver>
{
const Environment * const env;
+ const ResolverFunctions fns;
+
ResolutionsByQPN_SMap resolutions_by_qpn_s;
InitialConstraints initial_constraints;
OrderedResolutionsList ordered_resolutions;
- Implementation(const Environment * const e) :
- env(e)
+ Implementation(const Environment * const e, const ResolverFunctions & f) :
+ env(e),
+ fns(f)
{
}
};
}
-Resolver::Resolver(const Environment * const e) :
- PrivateImplementationPattern<Resolver>(new Implementation<Resolver>(e))
+Resolver::Resolver(const Environment * const e, const ResolverFunctions & f) :
+ PrivateImplementationPattern<Resolver>(new Implementation<Resolver>(e, f))
{
}
@@ -248,9 +253,9 @@ Resolver::_same_slot(const std::tr1::shared_ptr<const PackageID> & a,
}
void
-Resolver::add_target(const PackageDepSpec & spec, const UseInstalled use_installed)
+Resolver::add_target_with_reason(const PackageDepSpec & spec, const std::tr1::shared_ptr<const Reason> & reason)
{
- Context context("When adding target '" + stringify(spec) + "':");
+ Context context("When adding target '" + stringify(spec) + "' with reason '" + stringify(*reason) + "':");
_imp->env->trigger_notifier_callback(NotifierCallbackResolverStepEvent());
std::list<QPN_S> qpn_s_s;
@@ -265,14 +270,20 @@ Resolver::add_target(const PackageDepSpec & spec, const UseInstalled use_install
+ stringify(*qpn_s) + "':");
const std::tr1::shared_ptr<Resolution> dep_resolution(_resolution_for_qpn_s(*qpn_s, true));
- const std::tr1::shared_ptr<Constraint> constraint(_make_constraint_from_target(spec, use_installed));
+ const std::tr1::shared_ptr<Constraint> constraint(_make_constraint_from_target(spec, reason));
_apply_resolution_constraint(*qpn_s, dep_resolution, constraint);
}
}
void
-Resolver::add_set(const SetName & set_name, const UseInstalled use_installed)
+Resolver::add_target(const PackageDepSpec & spec)
+{
+ add_target_with_reason(spec, make_shared_ptr(new TargetReason));
+}
+
+void
+Resolver::add_target(const SetName & set_name)
{
Context context("When adding set target '" + stringify(set_name) + "':");
_imp->env->trigger_notifier_callback(NotifierCallbackResolverStepEvent());
@@ -284,9 +295,10 @@ Resolver::add_set(const SetName & set_name, const UseInstalled use_installed)
DepSpecFlattener<SetSpecTree, PackageDepSpec> flattener(_imp->env);
set->root()->accept(flattener);
+ const std::tr1::shared_ptr<Reason> reason(new SetReason(set_name, make_shared_ptr(new TargetReason)));
for (DepSpecFlattener<SetSpecTree, PackageDepSpec>::ConstIterator s(flattener.begin()), s_end(flattener.end()) ;
s != s_end ; ++s)
- add_target(**s, use_installed);
+ add_target_with_reason(**s, reason);
}
namespace
@@ -405,26 +417,28 @@ Resolver::qpn_s_from_id(const std::tr1::shared_ptr<const PackageID> & id) const
}
const std::tr1::shared_ptr<Constraint>
-Resolver::_make_constraint_from_target(const PackageDepSpec & spec, const UseInstalled use_installed) const
+Resolver::_make_constraint_from_target(const PackageDepSpec & spec, const std::tr1::shared_ptr<const Reason> & reason) const
{
return make_shared_ptr(new Constraint(make_named_values<Constraint>(
value_for<n::desire_strength>(ds_target),
- value_for<n::reason>(make_shared_ptr(new TargetReason)),
+ value_for<n::reason>(reason),
value_for<n::spec>(spec),
value_for<n::to_destination_slash>(true),
- value_for<n::use_installed>(use_installed)
+ value_for<n::use_installed>(_imp->fns.get_use_installed_fn()(spec, reason))
)));
}
const std::tr1::shared_ptr<Constraint>
Resolver::_make_constraint_from_dependency(const QPN_S & qpn_s, const SanitisedDependency & dep) const
{
+ const std::tr1::shared_ptr<DependencyReason> reason(new DependencyReason(qpn_s, dep));
+
return make_shared_ptr(new Constraint(make_named_values<Constraint>(
value_for<n::desire_strength>(_desire_strength_from_sanitised_dependency(qpn_s, dep)),
- value_for<n::reason>(make_shared_ptr(new DependencyReason(qpn_s, dep))),
+ value_for<n::reason>(reason),
value_for<n::spec>(dep.spec()),
value_for<n::to_destination_slash>(_dependency_to_destination_slash(qpn_s, dep)),
- value_for<n::use_installed>(ui_if_same)
+ value_for<n::use_installed>(_imp->fns.get_use_installed_fn()(dep.spec(), reason))
)));
}
@@ -628,6 +642,32 @@ Resolver::_care_about_dependency_spec(const QPN_S & qpn_s,
return _desire_strength_from_sanitised_dependency(qpn_s, dep) >= ds_recommendation;
}
+namespace
+{
+ struct GetDependencyReason
+ {
+ const DependencyReason * visit(const DependencyReason & r) const
+ {
+ return &r;
+ }
+
+ const DependencyReason * visit(const SetReason & r) const
+ {
+ return r.reason_for_set()->accept_returning<const DependencyReason *>(*this);
+ }
+
+ const DependencyReason * visit(const TargetReason &) const
+ {
+ return 0;
+ }
+
+ const DependencyReason * visit(const PresetReason &) const
+ {
+ return 0;
+ }
+ };
+}
+
void
Resolver::_resolve_arrows()
{
@@ -640,13 +680,15 @@ Resolver::_resolve_arrows()
c_end(i->second->constraints()->end()) ;
c != c_end ; ++c)
{
- if (! (*c)->reason()->if_dependency_reason())
+ GetDependencyReason gdr;
+ const DependencyReason * if_dependency_reason((*c)->reason()->accept_returning<const DependencyReason *>(gdr));
+ if (! if_dependency_reason)
continue;
- const QPN_S from_qpns((*c)->reason()->if_dependency_reason()->qpn_s());
+ const QPN_S from_qpns(if_dependency_reason->qpn_s());
const std::tr1::shared_ptr<Resolution> resolution(_resolution_for_qpn_s(from_qpns, false));
- if (_causes_pre_arrow(*(*c)->reason()->if_dependency_reason()))
+ if (_causes_pre_arrow(*if_dependency_reason))
resolution->arrows()->push_back(make_shared_ptr(new Arrow(make_named_values<Arrow>(
value_for<n::to_qpn_s>(i->first)
))));
@@ -918,12 +960,14 @@ const std::tr1::shared_ptr<const Constraint>
Resolver::_make_constraint_for_preloading(
const std::tr1::shared_ptr<const Decision> & d) const
{
+ const std::tr1::shared_ptr<PresetReason> reason(new PresetReason);
+
return make_shared_ptr(new Constraint(make_named_values<Constraint>(
value_for<n::desire_strength>(ds_none),
- value_for<n::reason>(make_shared_ptr(new TargetReason)),
+ value_for<n::reason>(reason),
value_for<n::spec>(d->package_id()->uniquely_identifying_spec()),
value_for<n::to_destination_slash>(false),
- value_for<n::use_installed>(ui_if_possible)
+ value_for<n::use_installed>(_imp->fns.get_use_installed_fn()(d->package_id()->uniquely_identifying_spec(), reason))
)));
}
diff --git a/paludis/resolver/resolver.hh b/paludis/resolver/resolver.hh
index 3fb6ee6..fc0aa7a 100644
--- a/paludis/resolver/resolver.hh
+++ b/paludis/resolver/resolver.hh
@@ -30,6 +30,7 @@
#include <paludis/resolver/use_installed-fwd.hh>
#include <paludis/resolver/desire_strength-fwd.hh>
#include <paludis/resolver/destinations-fwd.hh>
+#include <paludis/resolver/resolver_functions-fwd.hh>
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/util/wrapped_forward_iterator-fwd.hh>
#include <paludis/package_id-fwd.hh>
@@ -57,7 +58,8 @@ namespace paludis
const std::tr1::shared_ptr<Resolution> _resolution_for_qpn_s(const QPN_S &) const;
const std::tr1::shared_ptr<Constraint> _make_constraint_from_target(
- const PackageDepSpec &, const UseInstalled) const;
+ const PackageDepSpec &,
+ const std::tr1::shared_ptr<const Reason> &) const;
const std::tr1::shared_ptr<Constraint> _make_constraint_from_dependency(
const QPN_S &, const SanitisedDependency &) const;
@@ -149,11 +151,14 @@ namespace paludis
const std::tr1::shared_ptr<const PackageID> & b) const;
public:
- Resolver(const Environment * const);
+ Resolver(
+ const Environment * const,
+ const ResolverFunctions &);
~Resolver();
- void add_target(const PackageDepSpec &, const UseInstalled);
- void add_set(const SetName &, const UseInstalled);
+ void add_target_with_reason(const PackageDepSpec &, const std::tr1::shared_ptr<const Reason> &);
+ void add_target(const PackageDepSpec &);
+ void add_target(const SetName &);
void copy_initial_constraints_from(const Resolver &);
void add_initial_constraint(const QPN_S &, const std::tr1::shared_ptr<const Constraint> &);
diff --git a/paludis/resolver/resolver_functions-fwd.hh b/paludis/resolver/resolver_functions-fwd.hh
new file mode 100644
index 0000000..a33bb62
--- /dev/null
+++ b/paludis/resolver/resolver_functions-fwd.hh
@@ -0,0 +1,31 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_RESOLVER_RESOLVER_FUNCTIONS_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_RESOLVER_RESOLVER_FUNCTIONS_FWD_HH 1
+
+namespace paludis
+{
+ namespace resolver
+ {
+ struct ResolverFunctions;
+ }
+}
+
+#endif
diff --git a/paludis/resolver/resolver_functions.hh b/paludis/resolver/resolver_functions.hh
new file mode 100644
index 0000000..b4b3e70
--- /dev/null
+++ b/paludis/resolver/resolver_functions.hh
@@ -0,0 +1,50 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_RESOLVER_RESOLVER_FUNCTIONS_HH
+#define PALUDIS_GUARD_PALUDIS_RESOLVER_RESOLVER_FUNCTIONS_HH 1
+
+#include <paludis/resolver/resolver_functions-fwd.hh>
+#include <paludis/resolver/use_installed-fwd.hh>
+#include <paludis/resolver/resolution-fwd.hh>
+#include <paludis/resolver/qpn_s-fwd.hh>
+#include <paludis/resolver/reason-fwd.hh>
+#include <paludis/util/named_value.hh>
+#include <tr1/functional>
+
+namespace paludis
+{
+ namespace n
+ {
+ struct get_use_installed_fn;
+ }
+
+ namespace resolver
+ {
+ typedef std::tr1::function<UseInstalled (
+ const PackageDepSpec &, const std::tr1::shared_ptr<const Reason> &)> GetUseInstalledFunction;
+
+ struct ResolverFunctions
+ {
+ NamedValue<n::get_use_installed_fn, GetUseInstalledFunction> get_use_installed_fn;
+ };
+ }
+}
+
+#endif
diff --git a/src/clients/cave/cmd_resolve.cc b/src/clients/cave/cmd_resolve.cc
index 7380ca3..bb57a88 100644
--- a/src/clients/cave/cmd_resolve.cc
+++ b/src/clients/cave/cmd_resolve.cc
@@ -25,10 +25,13 @@
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/mutex.hh>
#include <paludis/util/stringify.hh>
+#include <paludis/util/make_named_values.hh>
#include <paludis/args/do_help.hh>
#include <paludis/resolver/resolver.hh>
#include <paludis/resolver/resolution.hh>
#include <paludis/resolver/decision.hh>
+#include <paludis/resolver/resolver_functions.hh>
+#include <paludis/resolver/reason.hh>
#include <paludis/user_dep_spec.hh>
#include <paludis/notifier_callback.hh>
@@ -36,13 +39,12 @@
#include <cstdlib>
using namespace paludis;
+using namespace paludis::resolver;
using namespace cave;
using std::cout;
using std::endl;
-using resolver::Resolver;
-
namespace
{
struct ResolveCommandLine :
@@ -101,10 +103,10 @@ namespace
// args::StringSetArg a_skip_until_phase;
// args::EnumArg a_change_phases_for;
-// args::ArgsGroup g_reinstall_options;
-// args::EnumArg a_reinstall_targets;
-// args::EnumArg a_reinstall;
-// args::EnumArg a_reinstall_scm;
+ args::ArgsGroup g_reinstall_options;
+ args::EnumArg a_reinstall_targets;
+ args::EnumArg a_reinstall;
+ args::EnumArg a_reinstall_scm;
// args::SwitchArg a_reinstall_for_removals;
// args::ArgsGroup g_slot_options;
@@ -226,42 +228,42 @@ namespace
// ("last", "Only the last package on the list"),
// "all"),
//
-// g_reinstall_options(this, "Reinstall Options", "Control whether packages are reinstalled."),
-// a_reinstall_targets(&g_reinstall_options, "reinstall-targets", 'R',
-// "Select whether to reinstall target packages",
-// args::EnumArg::EnumArgOptions
-// ("auto", 'x', "If the target is a set, if-necessary, otherwise always")
-// ("always", 'a', "Always")
-// ("unless-transient", 't', "Unless the target is transient (e.g. from 'importare')"
-// " (default if --everything)")
-// ("unless-same", 's', "Unless the target is the same (version, option flags)")
-// ("unless-same-version", 'v', "Unless the target is the same version")
-// ("if-necessary", 'i', "If necessary")
-// ("never", 'n', "Never"),
-// "auto"
-// ),
-// a_reinstall(&g_reinstall_options, "reinstall", 'r',
-// "Select whether to reinstall packages that are not targets",
-// args::EnumArg::EnumArgOptions
-// ("always", 'a', "Always")
-// ("unless-transient", 't', "Unless the target is transient (e.g. from 'importare')"
-// " (default if --everything)")
-// ("unless-same", 's', "Unless the target is the same (version, option flags)"
-// " (default if --complete)")
-// ("unless-same-version", 'v', "Unless the target is the same version")
-// ("if-necessary", 'i', "If necessary")
-// ("never", 'n', "Never"),
-// "if-necessary"
-// ),
-// a_reinstall_scm(&g_reinstall_options, "reinstall-scm", 's',
-// "Select whether to reinstall SCM packages that would otherwise not be reinstalled",
-// args::EnumArg::EnumArgOptions
-// ("always", 'a', "Always")
-// ("daily", 'd', "If they were installed more than a day ago")
-// ("weekly", 'w', "If they were installed more than a week ago")
-// ("never", 'n', "Never"),
-// "weekly"
-// ),
+ g_reinstall_options(this, "Reinstall Options", "Control whether packages are reinstalled."),
+ a_reinstall_targets(&g_reinstall_options, "reinstall-targets", 'R',
+ "Select whether to reinstall target packages",
+ args::EnumArg::EnumArgOptions
+ ("auto", 'x', "If the target is a set, if-necessary, otherwise always")
+ ("always", 'a', "Always")
+ ("unless-transient", 't', "Unless the target is transient (e.g. from 'importare')"
+ " (default if --everything)")
+ ("unless-same", 's', "Unless the target is the same (version, option flags)")
+ ("unless-same-version", 'v', "Unless the target is the same version")
+ ("if-necessary", 'i', "If necessary")
+ ("never", 'n', "Never"),
+ "auto"
+ ),
+ a_reinstall(&g_reinstall_options, "reinstall", 'r',
+ "Select whether to reinstall packages that are not targets",
+ args::EnumArg::EnumArgOptions
+ ("always", 'a', "Always")
+ ("unless-transient", 't', "Unless the target is transient (e.g. from 'importare')"
+ " (default if --everything)")
+ ("unless-same", 's', "Unless the target is the same (version, option flags)"
+ " (default if --complete)")
+ ("unless-same-version", 'v', "Unless the target is the same version")
+ ("if-necessary", 'i', "If necessary")
+ ("never", 'n', "Never"),
+ "if-necessary"
+ ),
+ a_reinstall_scm(&g_reinstall_options, "reinstall-scm", 's',
+ "Select whether to reinstall SCM packages that would otherwise not be reinstalled",
+ args::EnumArg::EnumArgOptions
+ ("always", 'a', "Always")
+ ("daily", 'd', "If they were installed more than a day ago")
+ ("weekly", 'w', "If they were installed more than a week ago")
+ ("never", 'n', "Never"),
+ "weekly"
+ ),
// a_reinstall_for_removals(&g_reinstall_options, "reinstall-for-removals", '\0',
// "Select whether to rebuild packages if rebuilding would avoid an unsafe removal", true),
//
@@ -428,8 +430,7 @@ namespace
try
{
resolver->add_target(parse_user_package_dep_spec(*p, env.get(),
- UserPackageDepSpecOptions() + updso_throw_if_set),
- resolver::ui_never);
+ UserPackageDepSpecOptions() + updso_throw_if_set));
if (seen_sets)
throw args::DoHelp("Cannot specify both set and package targets");
seen_packages = true;
@@ -441,7 +442,7 @@ namespace
if (seen_sets)
throw args::DoHelp("Cannot specify multiple set targets");
- resolver->add_set(SetName(*p), resolver::ui_if_same);
+ resolver->add_target(SetName(*p));
seen_sets = true;
}
}
@@ -475,6 +476,36 @@ namespace
if (cmdline.a_dump.specified())
resolver->dump(std::cerr, cmdline.a_dump_dependencies.specified());
}
+
+ struct UseInstalledVisitor
+ {
+ UseInstalled visit(const DependencyReason &) const
+ {
+ return ui_if_same;
+ }
+
+ UseInstalled visit(const TargetReason &) const
+ {
+ return ui_never;
+ }
+
+ UseInstalled visit(const PresetReason &) const
+ {
+ return ui_if_possible;
+ }
+
+ UseInstalled visit(const SetReason &) const
+ {
+ return ui_if_same;
+ }
+ };
+
+ UseInstalled use_installed_fn(const ResolveCommandLine &, const PackageDepSpec &,
+ const std::tr1::shared_ptr<const Reason> & reason)
+ {
+ UseInstalledVisitor v;
+ return reason->accept_returning<UseInstalled>(v);
+ }
}
bool
@@ -500,7 +531,11 @@ ResolveCommand::run(
int retcode(0);
- std::tr1::shared_ptr<Resolver> resolver(new Resolver(env.get()));
+ ResolverFunctions resolver_functions(make_named_values<ResolverFunctions>(
+ value_for<n::get_use_installed_fn>(std::tr1::bind(&use_installed_fn,
+ std::tr1::cref(cmdline), std::tr1::placeholders::_1, std::tr1::placeholders::_2))
+ ));
+ std::tr1::shared_ptr<Resolver> resolver(new Resolver(env.get(), resolver_functions));
try
{
while (true)