diff options
author | 2010-08-06 20:09:01 +0100 | |
---|---|---|
committer | 2010-08-08 10:53:06 +0100 | |
commit | ea6612acb9d1ccbbe9fbf784655b70ac2b694b0b (patch) | |
tree | 1783b861f8ffe7851b8924caa25e636f8f4c6816 | |
parent | 533dd974bd06e622e3ddc63d9d1f47d005068f2e (diff) | |
download | paludis-ea6612acb9d1ccbbe9fbf784655b70ac2b694b0b.tar.gz paludis-ea6612acb9d1ccbbe9fbf784655b70ac2b694b0b.tar.xz |
CanUseHelper
-rw-r--r-- | paludis/resolver/Makefile.am | 2 | ||||
-rw-r--r-- | paludis/resolver/can_use_helper-fwd.hh | 31 | ||||
-rw-r--r-- | paludis/resolver/can_use_helper.cc | 65 | ||||
-rw-r--r-- | paludis/resolver/can_use_helper.hh | 51 | ||||
-rw-r--r-- | paludis/resolver/resolver_test.cc | 12 | ||||
-rw-r--r-- | paludis/resolver/resolver_test.hh | 5 | ||||
-rw-r--r-- | src/clients/cave/resolve_common.cc | 26 |
7 files changed, 163 insertions, 29 deletions
diff --git a/paludis/resolver/Makefile.am b/paludis/resolver/Makefile.am index 66493df51..2a7b6f7a6 100644 --- a/paludis/resolver/Makefile.am +++ b/paludis/resolver/Makefile.am @@ -32,6 +32,7 @@ noinst_HEADERS = \ allowed_to_remove_helper.hh allowed_to_remove_helper-fwd.hh \ always_via_binary_helper.hh always_via_binary_helper-fwd.hh \ any_child_score.hh any_child_score-fwd.hh any_child_score-se.hh \ + 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 \ constraint.hh constraint-fwd.hh \ @@ -71,6 +72,7 @@ libpaludisresolver_a_SOURCES = \ allowed_to_remove_helper.cc \ always_via_binary_helper.cc \ any_child_score.cc \ + can_use_helper.cc \ change_by_resolvent.cc \ change_type.cc \ constraint.cc \ diff --git a/paludis/resolver/can_use_helper-fwd.hh b/paludis/resolver/can_use_helper-fwd.hh new file mode 100644 index 000000000..7c4f629e3 --- /dev/null +++ b/paludis/resolver/can_use_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_CAN_USE_HELPER_FWD_HH +#define PALUDIS_GUARD_PALUDIS_RESOLVER_CAN_USE_HELPER_FWD_HH 1 + +namespace paludis +{ + namespace resolver + { + struct CanUseHelper; + } +} + +#endif diff --git a/paludis/resolver/can_use_helper.cc b/paludis/resolver/can_use_helper.cc new file mode 100644 index 000000000..af5e1b046 --- /dev/null +++ b/paludis/resolver/can_use_helper.cc @@ -0,0 +1,65 @@ +/* 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/can_use_helper.hh> +#include <paludis/util/pimp-impl.hh> +#include <paludis/util/options.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<CanUseHelper> + { + const Environment * const env; + PackageDepSpecCollection cannot_use_specs; + + Imp(const Environment * const e) : + env(e) + { + } + }; +} + +CanUseHelper::CanUseHelper(const Environment * const e) : + Pimp<CanUseHelper>(e) +{ +} + +CanUseHelper::~CanUseHelper() = default; + +void +CanUseHelper::add_cannot_use_spec(const PackageDepSpec & spec) +{ + _imp->cannot_use_specs.insert(spec); +} + +bool +CanUseHelper::operator() (const std::shared_ptr<const PackageID> & id) const +{ + return ! _imp->cannot_use_specs.match_any(_imp->env, id, { }); +} + +template class Pimp<CanUseHelper>; + diff --git a/paludis/resolver/can_use_helper.hh b/paludis/resolver/can_use_helper.hh new file mode 100644 index 000000000..c1b5337b5 --- /dev/null +++ b/paludis/resolver/can_use_helper.hh @@ -0,0 +1,51 @@ +/* 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_CAN_USE_HELPER_HH +#define PALUDIS_GUARD_PALUDIS_RESOLVER_CAN_USE_HELPER_HH 1 + +#include <paludis/resolver/can_use_helper-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 CanUseHelper : + private Pimp<CanUseHelper> + { + public: + explicit CanUseHelper(const Environment * const); + ~CanUseHelper(); + + void add_cannot_use_spec(const PackageDepSpec &); + + bool operator() (const std::shared_ptr<const PackageID> &) const; + }; + } + + extern template class Pimp<resolver::CanUseHelper>; +} + +#endif diff --git a/paludis/resolver/resolver_test.cc b/paludis/resolver/resolver_test.cc index fea4b4a51..1141fa331 100644 --- a/paludis/resolver/resolver_test.cc +++ b/paludis/resolver/resolver_test.cc @@ -323,13 +323,6 @@ paludis::resolver::resolver_test::get_constraints_for_via_binary_fn( return result; } -bool -paludis::resolver::resolver_test::can_use_fn( - const std::shared_ptr<const PackageID> &) -{ - return true; -} - ResolverTestCase::ResolverTestCase(const std::string & t, const std::string & s, const std::string & e, const std::string & l) : TestCase(s), @@ -337,7 +330,8 @@ ResolverTestCase::ResolverTestCase(const std::string & t, const std::string & s, prefer_or_avoid_names(std::make_shared<Map<QualifiedPackageName, bool>>()), allow_choice_changes_helper(&env), allowed_to_remove_helper(&env), - always_via_binary_helper(&env) + always_via_binary_helper(&env), + can_use_helper(&env) { std::shared_ptr<Map<std::string, std::string> > keys(std::make_shared<Map<std::string, std::string>>()); keys->insert("format", "e"); @@ -386,7 +380,7 @@ ResolverTestCase::get_resolver_functions(InitialConstraints & initial_constraint 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() = &can_use_fn, + n::can_use_fn() = std::cref(can_use_helper), n::confirm_fn() = &confirm_fn, n::find_repository_for_fn() = std::bind(&find_repository_for_fn, &env, std::placeholders::_1, std::placeholders::_2), diff --git a/paludis/resolver/resolver_test.hh b/paludis/resolver/resolver_test.hh index a43b788ac..743a20a59 100644 --- a/paludis/resolver/resolver_test.hh +++ b/paludis/resolver/resolver_test.hh @@ -38,6 +38,7 @@ #include <paludis/resolver/allow_choice_changes_helper.hh> #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/repositories/fake/fake_installed_repository.hh> #include <paludis/repositories/fake/fake_package_id.hh> @@ -136,9 +137,6 @@ namespace paludis const std::shared_ptr<const Resolution> &, const std::shared_ptr<const RequiredConfirmation> &); - bool can_use_fn( - const std::shared_ptr<const PackageID> &); - struct ResolverTestCase : test::TestCase { TestEnvironment env; @@ -150,6 +148,7 @@ namespace paludis AllowChoiceChangesHelper allow_choice_changes_helper; AllowedToRemoveHelper allowed_to_remove_helper; AlwaysViaBinaryHelper always_via_binary_helper; + CanUseHelper can_use_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 96255d582..97a32b488 100644 --- a/src/clients/cave/resolve_common.cc +++ b/src/clients/cave/resolve_common.cc @@ -68,6 +68,7 @@ #include <paludis/resolver/allow_choice_changes_helper.hh> #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/user_dep_spec.hh> #include <paludis/notifier_callback.hh> @@ -1408,14 +1409,6 @@ namespace return result; } - bool can_use_fn( - const Environment * const env, - const PackageDepSpecList & list, - const std::shared_ptr<const PackageID> & id) - { - return ! match_any(env, list, id); - } - void serialise_resolved(StringListStream & ser_stream, const Resolved & resolved) { Serialiser ser(ser_stream); @@ -1732,7 +1725,7 @@ paludis::cave::resolve_common( PackageDepSpecList allowed_to_break_specs, remove_if_dependent_specs, less_restrictive_remove_blockers_specs, purge_specs, with, without, permit_old_version, permit_downgrade, take, take_from, ignore, ignore_from, - favour, avoid, early, late, no_dependencies_from, no_blockers_from, not_usable_specs; + 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()), @@ -1846,12 +1839,6 @@ paludis::cave::resolve_common( permit_old_version.push_back(parse_user_package_dep_spec(*i, env.get(), { updso_allow_wildcards })); - for (args::StringSetArg::ConstIterator i(resolution_options.a_not_usable.begin_args()), - i_end(resolution_options.a_not_usable.end_args()) ; - i != i_end ; ++i) - not_usable_specs.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()) ; @@ -1926,12 +1913,17 @@ paludis::cave::resolve_common( always_via_binary_helper.add_always_via_binary_spec(parse_user_package_dep_spec(*i, env.get(), { updso_allow_wildcards })); #endif + CanUseHelper can_use_helper(env.get()); + for (args::StringSetArg::ConstIterator i(resolution_options.a_not_usable.begin_args()), + i_end(resolution_options.a_not_usable.end_args()) ; + i != i_end ; ++i) + can_use_helper.add_cannot_use_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::bind(&can_use_fn, - env.get(), std::cref(not_usable_specs), _1), + 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), |