diff options
author | 2010-08-06 20:54:54 +0100 | |
---|---|---|
committer | 2010-08-08 10:53:06 +0100 | |
commit | 8ef0fd8929c0a6a16ff450565b811c9636a695c4 (patch) | |
tree | e15d0d005134e06c424a3a55e5a2f5cadb03445a | |
parent | ea6612acb9d1ccbbe9fbf784655b70ac2b694b0b (diff) | |
download | paludis-8ef0fd8929c0a6a16ff450565b811c9636a695c4.tar.gz paludis-8ef0fd8929c0a6a16ff450565b811c9636a695c4.tar.xz |
ConfirmHelper
-rw-r--r-- | paludis/resolver/Makefile.am | 2 | ||||
-rw-r--r-- | paludis/resolver/confirm_helper-fwd.hh | 31 | ||||
-rw-r--r-- | paludis/resolver/confirm_helper.cc | 185 | ||||
-rw-r--r-- | paludis/resolver/confirm_helper.hh | 58 | ||||
-rw-r--r-- | paludis/resolver/resolver_test.cc | 13 | ||||
-rw-r--r-- | paludis/resolver/resolver_test.hh | 6 | ||||
-rw-r--r-- | src/clients/cave/resolve_common.cc | 148 |
7 files changed, 302 insertions, 141 deletions
diff --git a/paludis/resolver/Makefile.am b/paludis/resolver/Makefile.am index 2a7b6f7a6..f184a60fc 100644 --- a/paludis/resolver/Makefile.am +++ b/paludis/resolver/Makefile.am @@ -35,6 +35,7 @@ noinst_HEADERS = \ can_use_helper.hh can_use_helper-fwd.hh \ change_by_resolvent.hh change_by_resolvent-fwd.hh \ change_type.hh change_type-fwd.hh change_type-se.hh \ + confirm_helper.hh confirm_helper-fwd.hh \ constraint.hh constraint-fwd.hh \ decider.hh decider-fwd.hh \ decision.hh decision-fwd.hh \ @@ -75,6 +76,7 @@ libpaludisresolver_a_SOURCES = \ can_use_helper.cc \ change_by_resolvent.cc \ change_type.cc \ + confirm_helper.cc \ constraint.cc \ decider.cc \ decision.cc \ diff --git a/paludis/resolver/confirm_helper-fwd.hh b/paludis/resolver/confirm_helper-fwd.hh new file mode 100644 index 000000000..55898cbc6 --- /dev/null +++ b/paludis/resolver/confirm_helper-fwd.hh @@ -0,0 +1,31 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 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_CONFIRM_HELPER_FWD_HH +#define PALUDIS_GUARD_PALUDIS_RESOLVER_CONFIRM_HELPER_FWD_HH 1 + +namespace paludis +{ + namespace resolver + { + struct ConfirmHelper; + } +} + +#endif diff --git a/paludis/resolver/confirm_helper.cc b/paludis/resolver/confirm_helper.cc new file mode 100644 index 000000000..8edba86c7 --- /dev/null +++ b/paludis/resolver/confirm_helper.cc @@ -0,0 +1,185 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 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 + */ + +#include <paludis/resolver/confirm_helper.hh> +#include <paludis/resolver/reason.hh> +#include <paludis/resolver/constraint.hh> +#include <paludis/resolver/resolvent.hh> +#include <paludis/resolver/resolution.hh> +#include <paludis/resolver/decision.hh> +#include <paludis/resolver/required_confirmations.hh> +#include <paludis/util/pimp-impl.hh> +#include <paludis/util/make_null_shared_ptr.hh> +#include <paludis/dep_spec.hh> +#include <paludis/package_id.hh> +#include <paludis/package_dep_spec_collection.hh> + +using namespace paludis; +using namespace paludis::resolver; + +namespace paludis +{ + template <> + struct Imp<ConfirmHelper> + { + const Environment * const env; + PackageDepSpecCollection permit_downgrade_specs; + PackageDepSpecCollection permit_old_version_specs; + PackageDepSpecCollection allowed_to_break_specs; + bool allowed_to_break_system; + + Imp(const Environment * const e) : + env(e), + allowed_to_break_system(false) + { + } + }; +} + +ConfirmHelper::ConfirmHelper(const Environment * const e) : + Pimp<ConfirmHelper>(e) +{ +} + +ConfirmHelper::~ConfirmHelper() = default; + +void +ConfirmHelper::add_permit_downgrade_spec(const PackageDepSpec & spec) +{ + _imp->permit_downgrade_specs.insert(spec); +} + +void +ConfirmHelper::add_permit_old_version_spec(const PackageDepSpec & spec) +{ + _imp->permit_old_version_specs.insert(spec); +} + +void +ConfirmHelper::add_allowed_to_break_spec(const PackageDepSpec & spec) +{ + _imp->allowed_to_break_specs.insert(spec); +} + +void +ConfirmHelper::set_allowed_to_break_system(const bool b) +{ + _imp->allowed_to_break_system = b; +} + +namespace +{ + struct ConfirmVisitor + { + const Environment * const env; + const PackageDepSpecCollection & permit_downgrade_specs; + const PackageDepSpecCollection & permit_old_version_specs; + const PackageDepSpecCollection & allowed_to_break_specs; + const bool allowed_to_break_system; + const std::shared_ptr<const PackageID> id; + + bool visit(const DowngradeConfirmation &) const + { + if (id) + if (permit_downgrade_specs.match_any(env, id, { })) + return true; + + return false; + } + + bool visit(const NotBestConfirmation &) const + { + if (id) + if (permit_old_version_specs.match_any(env, id, { })) + return true; + + return false; + } + + bool visit(const BreakConfirmation &) const + { + if (id) + if (allowed_to_break_specs.match_any(env, id, { })) + return true; + + return false; + } + + bool visit(const RemoveSystemPackageConfirmation &) const + { + return allowed_to_break_system; + } + + bool visit(const MaskedConfirmation &) const + { + return false; + } + + bool visit(const ChangedChoicesConfirmation &) const + { + return false; + } + }; + + struct IDVisitor + { + std::shared_ptr<const PackageID> visit(const ChangesToMakeDecision & decision) const + { + return decision.origin_id(); + } + + std::shared_ptr<const PackageID> visit(const BreakDecision & decision) const + { + return decision.existing_id(); + } + + std::shared_ptr<const PackageID> visit(const ExistingNoChangeDecision & decision) const + { + return decision.existing_id(); + } + + std::shared_ptr<const PackageID> visit(const NothingNoChangeDecision &) const + { + return make_null_shared_ptr(); + } + + std::shared_ptr<const PackageID> visit(const RemoveDecision &) const + { + return make_null_shared_ptr(); + } + + std::shared_ptr<const PackageID> visit(const UnableToMakeDecision &) const + { + return make_null_shared_ptr(); + } + }; +} + +bool +ConfirmHelper::operator() ( + const std::shared_ptr<const Resolution> & resolution, + const std::shared_ptr<const RequiredConfirmation> & confirmation) const +{ + auto id(resolution->decision()->accept_returning<std::shared_ptr<const PackageID> >(IDVisitor())); + return confirmation->accept_returning<bool>(ConfirmVisitor{_imp->env, _imp->permit_downgrade_specs, + _imp->permit_old_version_specs, _imp->allowed_to_break_specs, _imp->allowed_to_break_system, id}); +} + +template class Pimp<ConfirmHelper>; + diff --git a/paludis/resolver/confirm_helper.hh b/paludis/resolver/confirm_helper.hh new file mode 100644 index 000000000..2ecc88781 --- /dev/null +++ b/paludis/resolver/confirm_helper.hh @@ -0,0 +1,58 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 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_CONFIRM_HELPER_HH +#define PALUDIS_GUARD_PALUDIS_RESOLVER_CONFIRM_HELPER_HH 1 + +#include <paludis/resolver/confirm_helper-fwd.hh> +#include <paludis/resolver/resolution-fwd.hh> +#include <paludis/resolver/required_confirmations-fwd.hh> +#include <paludis/util/pimp.hh> +#include <paludis/util/attributes.hh> +#include <paludis/dep_spec-fwd.hh> +#include <paludis/environment-fwd.hh> +#include <paludis/package_id-fwd.hh> +#include <memory> + +namespace paludis +{ + namespace resolver + { + class PALUDIS_VISIBLE ConfirmHelper : + private Pimp<ConfirmHelper> + { + public: + explicit ConfirmHelper(const Environment * const); + ~ConfirmHelper(); + + void add_permit_downgrade_spec(const PackageDepSpec &); + void add_permit_old_version_spec(const PackageDepSpec &); + void add_allowed_to_break_spec(const PackageDepSpec &); + void set_allowed_to_break_system(const bool); + + bool operator() ( + const std::shared_ptr<const Resolution> &, + const std::shared_ptr<const RequiredConfirmation> &) const; + }; + } + + extern template class Pimp<resolver::ConfirmHelper>; +} + +#endif diff --git a/paludis/resolver/resolver_test.cc b/paludis/resolver/resolver_test.cc index 1141fa331..3ac6bfa5d 100644 --- a/paludis/resolver/resolver_test.cc +++ b/paludis/resolver/resolver_test.cc @@ -231,14 +231,6 @@ paludis::resolver::resolver_test::order_early_fn( return indeterminate; } -bool -paludis::resolver::resolver_test::confirm_fn( - const std::shared_ptr<const Resolution> &, - const std::shared_ptr<const RequiredConfirmation> &) -{ - return true; -} - const std::shared_ptr<ConstraintSequence> paludis::resolver::resolver_test::get_constraints_for_dependent_fn( const std::shared_ptr<const Resolution> &, @@ -331,7 +323,8 @@ ResolverTestCase::ResolverTestCase(const std::string & t, const std::string & s, allow_choice_changes_helper(&env), allowed_to_remove_helper(&env), always_via_binary_helper(&env), - can_use_helper(&env) + can_use_helper(&env), + confirm_helper(&env) { std::shared_ptr<Map<std::string, std::string> > keys(std::make_shared<Map<std::string, std::string>>()); keys->insert("format", "e"); @@ -381,7 +374,7 @@ ResolverTestCase::get_resolver_functions(InitialConstraints & initial_constraint n::allowed_to_remove_fn() = std::cref(allowed_to_remove_helper), n::always_via_binary_fn() = std::cref(always_via_binary_helper), n::can_use_fn() = std::cref(can_use_helper), - n::confirm_fn() = &confirm_fn, + n::confirm_fn() = std::cref(confirm_helper), n::find_repository_for_fn() = std::bind(&find_repository_for_fn, &env, std::placeholders::_1, std::placeholders::_2), n::get_constraints_for_dependent_fn() = &get_constraints_for_dependent_fn, diff --git a/paludis/resolver/resolver_test.hh b/paludis/resolver/resolver_test.hh index 743a20a59..47a8d6206 100644 --- a/paludis/resolver/resolver_test.hh +++ b/paludis/resolver/resolver_test.hh @@ -39,6 +39,7 @@ #include <paludis/resolver/allowed_to_remove_helper.hh> #include <paludis/resolver/always_via_binary_helper.hh> #include <paludis/resolver/can_use_helper.hh> +#include <paludis/resolver/confirm_helper.hh> #include <paludis/repositories/fake/fake_installed_repository.hh> #include <paludis/repositories/fake/fake_package_id.hh> @@ -133,10 +134,6 @@ namespace paludis Tribool order_early_fn( const std::shared_ptr<const Resolution> &); - bool confirm_fn( - const std::shared_ptr<const Resolution> &, - const std::shared_ptr<const RequiredConfirmation> &); - struct ResolverTestCase : test::TestCase { TestEnvironment env; @@ -149,6 +146,7 @@ namespace paludis AllowedToRemoveHelper allowed_to_remove_helper; AlwaysViaBinaryHelper always_via_binary_helper; CanUseHelper can_use_helper; + ConfirmHelper confirm_helper; ResolverTestCase(const std::string & group, const std::string & test_name, const std::string & eapi, const std::string & layout); diff --git a/src/clients/cave/resolve_common.cc b/src/clients/cave/resolve_common.cc index 97a32b488..0342784e3 100644 --- a/src/clients/cave/resolve_common.cc +++ b/src/clients/cave/resolve_common.cc @@ -69,6 +69,7 @@ #include <paludis/resolver/allowed_to_remove_helper.hh> #include <paludis/resolver/always_via_binary_helper.hh> #include <paludis/resolver/can_use_helper.hh> +#include <paludis/resolver/confirm_helper.hh> #include <paludis/user_dep_spec.hh> #include <paludis/notifier_callback.hh> @@ -1215,105 +1216,6 @@ namespace return indeterminate; } - struct ConfirmFnVisitor - { - const Environment * const env; - const ResolveCommandLineResolutionOptions & resolution_options; - const PackageDepSpecList & permit_downgrade; - const PackageDepSpecList & permit_old_version; - const PackageDepSpecList & allowed_to_break_specs; - const bool allowed_to_break_system; - const std::shared_ptr<const PackageID> id; - - ConfirmFnVisitor(const Environment * const e, - const ResolveCommandLineResolutionOptions & r, - const PackageDepSpecList & d, - const PackageDepSpecList & o, - const PackageDepSpecList & a, - const bool s, - const std::shared_ptr<const PackageID> & i) : - env(e), - resolution_options(r), - permit_downgrade(d), - permit_old_version(o), - allowed_to_break_specs(a), - allowed_to_break_system(s), - id(i) - { - } - - bool visit(const DowngradeConfirmation &) const - { - if (id) - for (PackageDepSpecList::const_iterator l(permit_downgrade.begin()), l_end(permit_downgrade.end()) ; - l != l_end ; ++l) - { - if (match_package(*env, *l, *id, { })) - return true; - } - - return false; - } - - bool visit(const NotBestConfirmation &) const - { - if (id) - for (PackageDepSpecList::const_iterator l(permit_old_version.begin()), l_end(permit_old_version.end()) ; - l != l_end ; ++l) - { - if (match_package(*env, *l, *id, { })) - return true; - } - - return false; - } - - bool visit(const BreakConfirmation &) const - { - if (id) - for (PackageDepSpecList::const_iterator l(allowed_to_break_specs.begin()), l_end(allowed_to_break_specs.end()) ; - l != l_end ; ++l) - { - if (match_package(*env, *l, *id, { })) - return true; - } - - return false; - } - - bool visit(const RemoveSystemPackageConfirmation &) const - { - return allowed_to_break_system; - } - - bool visit(const MaskedConfirmation &) const - { - return false; - } - - bool visit(const ChangedChoicesConfirmation &) const - { - return false; - } - }; - - bool confirm_fn( - const Environment * const env, - const ResolveCommandLineResolutionOptions & resolution_options, - const PackageDepSpecList & permit_downgrade, - const PackageDepSpecList & permit_old_version, - const PackageDepSpecList & allowed_to_break_specs, - const bool allowed_to_break_system, - const std::shared_ptr<const Resolution> & r, - const std::shared_ptr<const RequiredConfirmation> & c) - { - return c->accept_returning<bool>(ConfirmFnVisitor(env, resolution_options, permit_downgrade, permit_old_version, - allowed_to_break_specs, allowed_to_break_system, - r->decision()->accept_returning<std::pair<std::shared_ptr<const PackageID>, std::shared_ptr<const ChangedChoices> > >( - ChosenIDVisitor()).first - )); - } - const std::shared_ptr<ConstraintSequence> get_constraints_for_dependent_fn( const Environment * const env, const PackageDepSpecList & list, @@ -1722,20 +1624,10 @@ paludis::cave::resolve_common( int retcode(0); InitialConstraints initial_constraints; - PackageDepSpecList allowed_to_break_specs, remove_if_dependent_specs, + PackageDepSpecList remove_if_dependent_specs, less_restrictive_remove_blockers_specs, purge_specs, with, without, - permit_old_version, permit_downgrade, take, take_from, ignore, ignore_from, + take, take_from, ignore, ignore_from, favour, avoid, early, late, no_dependencies_from, no_blockers_from; - bool allowed_to_break_system(false); - - for (args::StringSetArg::ConstIterator i(resolution_options.a_uninstalls_may_break.begin_args()), - i_end(resolution_options.a_uninstalls_may_break.end_args()) ; - i != i_end ; ++i) - if (*i == "system") - allowed_to_break_system = true; - else - allowed_to_break_specs.push_back(parse_user_package_dep_spec(*i, env.get(), - { updso_allow_wildcards })); for (args::StringSetArg::ConstIterator i(resolution_options.a_remove_if_dependent.begin_args()), i_end(resolution_options.a_remove_if_dependent.end_args()) ; @@ -1827,18 +1719,6 @@ paludis::cave::resolve_common( no_blockers_from.push_back(parse_user_package_dep_spec(*i, env.get(), { updso_allow_wildcards })); - for (args::StringSetArg::ConstIterator i(resolution_options.a_permit_downgrade.begin_args()), - i_end(resolution_options.a_permit_downgrade.end_args()) ; - i != i_end ; ++i) - permit_downgrade.push_back(parse_user_package_dep_spec(*i, env.get(), - { updso_allow_wildcards })); - - for (args::StringSetArg::ConstIterator i(resolution_options.a_permit_old_version.begin_args()), - i_end(resolution_options.a_permit_old_version.end_args()) ; - i != i_end ; ++i) - permit_old_version.push_back(parse_user_package_dep_spec(*i, env.get(), - { updso_allow_wildcards })); - std::shared_ptr<Generator> binary_destinations; for (PackageDatabase::RepositoryConstIterator r(env->package_database()->begin_repositories()), r_end(env->package_database()->end_repositories()) ; @@ -1919,15 +1799,29 @@ paludis::cave::resolve_common( i != i_end ; ++i) can_use_helper.add_cannot_use_spec(parse_user_package_dep_spec(*i, env.get(), { updso_allow_wildcards })); + ConfirmHelper confirm_helper(env.get()); + for (args::StringSetArg::ConstIterator i(resolution_options.a_permit_downgrade.begin_args()), + i_end(resolution_options.a_permit_downgrade.end_args()) ; + i != i_end ; ++i) + confirm_helper.add_permit_downgrade_spec(parse_user_package_dep_spec(*i, env.get(), { updso_allow_wildcards })); + for (args::StringSetArg::ConstIterator i(resolution_options.a_permit_old_version.begin_args()), + i_end(resolution_options.a_permit_old_version.end_args()) ; + i != i_end ; ++i) + confirm_helper.add_permit_old_version_spec(parse_user_package_dep_spec(*i, env.get(), { updso_allow_wildcards })); + for (args::StringSetArg::ConstIterator i(resolution_options.a_uninstalls_may_break.begin_args()), + i_end(resolution_options.a_uninstalls_may_break.end_args()) ; + i != i_end ; ++i) + if (*i == "system") + confirm_helper.set_allowed_to_break_system(true); + else + confirm_helper.add_allowed_to_break_spec(parse_user_package_dep_spec(*i, env.get(), { updso_allow_wildcards })); + ResolverFunctions resolver_functions(make_named_values<ResolverFunctions>( n::allow_choice_changes_fn() = std::cref(allow_choice_changes_helper), n::allowed_to_remove_fn() = std::cref(allowed_to_remove_helper), n::always_via_binary_fn() = std::cref(always_via_binary_helper), n::can_use_fn() = std::cref(can_use_helper), - n::confirm_fn() = std::bind(&confirm_fn, - env.get(), std::cref(resolution_options), std::cref(permit_downgrade), - std::cref(permit_old_version), std::cref(allowed_to_break_specs), - allowed_to_break_system, _1, _2), + n::confirm_fn() = std::cref(confirm_helper), n::find_repository_for_fn() = std::bind(&find_repository_for_fn, env.get(), std::cref(resolution_options), _1, _2), n::get_constraints_for_dependent_fn() = std::bind(&get_constraints_for_dependent_fn, |