diff options
author | 2010-08-06 21:12:36 +0100 | |
---|---|---|
committer | 2010-08-08 10:53:06 +0100 | |
commit | 5a8863f83642e85ca797d9e2efe943b3488d6654 (patch) | |
tree | 69f7e52cd0db9d85f663d9df5ad792ae0dee1344 | |
parent | 8ef0fd8929c0a6a16ff450565b811c9636a695c4 (diff) | |
download | paludis-5a8863f83642e85ca797d9e2efe943b3488d6654.tar.gz paludis-5a8863f83642e85ca797d9e2efe943b3488d6654.tar.xz |
FindRepositoryForHelper
-rw-r--r-- | paludis/resolver/Makefile.am | 2 | ||||
-rw-r--r-- | paludis/resolver/find_repository_for_helper-fwd.hh | 31 | ||||
-rw-r--r-- | paludis/resolver/find_repository_for_helper.cc | 132 | ||||
-rw-r--r-- | paludis/resolver/find_repository_for_helper.hh | 52 | ||||
-rw-r--r-- | paludis/resolver/resolver_test.cc | 15 | ||||
-rw-r--r-- | paludis/resolver/resolver_test.hh | 7 | ||||
-rw-r--r-- | src/clients/cave/resolve_common.cc | 57 |
7 files changed, 226 insertions, 70 deletions
diff --git a/paludis/resolver/Makefile.am b/paludis/resolver/Makefile.am index f184a60fc..f0b843893 100644 --- a/paludis/resolver/Makefile.am +++ b/paludis/resolver/Makefile.am @@ -42,6 +42,7 @@ noinst_HEADERS = \ decisions.hh decisions-fwd.hh \ destination.hh destination-fwd.hh \ destination_types.hh destination_types-fwd.hh destination_types-se.hh \ + find_repository_for_helper.hh find_repository_for_helper-fwd.hh \ job.hh job-fwd.hh \ job_list.hh job_list-fwd.hh \ job_lists.hh job_lists-fwd.hh \ @@ -83,6 +84,7 @@ libpaludisresolver_a_SOURCES = \ decisions.cc \ destination.cc \ destination_types.cc \ + find_repository_for_helper.cc \ job.cc \ job_list.cc \ job_lists.cc \ diff --git a/paludis/resolver/find_repository_for_helper-fwd.hh b/paludis/resolver/find_repository_for_helper-fwd.hh new file mode 100644 index 000000000..30f4d7db6 --- /dev/null +++ b/paludis/resolver/find_repository_for_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_FIND_REPOSITORY_FOR_HELPER_FWD_HH +#define PALUDIS_GUARD_PALUDIS_RESOLVER_FIND_REPOSITORY_FOR_HELPER_FWD_HH 1 + +namespace paludis +{ + namespace resolver + { + struct FindRepositoryForHelper; + } +} + +#endif diff --git a/paludis/resolver/find_repository_for_helper.cc b/paludis/resolver/find_repository_for_helper.cc new file mode 100644 index 000000000..6c548fc37 --- /dev/null +++ b/paludis/resolver/find_repository_for_helper.cc @@ -0,0 +1,132 @@ +/* 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/find_repository_for_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/util/pimp-impl.hh> +#include <paludis/util/simple_visitor_cast.hh> +#include <paludis/util/exception.hh> +#include <paludis/util/stringify.hh> +#include <paludis/dep_spec.hh> +#include <paludis/package_id.hh> +#include <paludis/metadata_key.hh> +#include <paludis/package_dep_spec_collection.hh> +#include <paludis/environment.hh> +#include <paludis/package_database.hh> +#include <paludis/repository.hh> + +using namespace paludis; +using namespace paludis::resolver; + +namespace paludis +{ + template <> + struct Imp<FindRepositoryForHelper> + { + const Environment * const env; + + Imp(const Environment * const e) : + env(e) + { + } + }; +} + +FindRepositoryForHelper::FindRepositoryForHelper(const Environment * const e) : + Pimp<FindRepositoryForHelper>(e) +{ +} + +FindRepositoryForHelper::~FindRepositoryForHelper() = default; + +namespace +{ + bool is_fake(const std::shared_ptr<const Repository> & repo) + { + return repo->format_key() && repo->format_key()->value() == "installed_fake"; + } +} + +const std::shared_ptr<const Repository> +FindRepositoryForHelper::operator() ( + const std::shared_ptr<const Resolution> & resolution, + const ChangesToMakeDecision & decision) const +{ + std::shared_ptr<const Repository> result; + + for (auto r(_imp->env->package_database()->begin_repositories()), + r_end(_imp->env->package_database()->end_repositories()) ; + r != r_end ; ++r) + { + switch (resolution->resolvent().destination_type()) + { + case dt_install_to_slash: + if ((! (*r)->installed_root_key()) || ((*r)->installed_root_key()->value() != FSEntry("/"))) + continue; + break; + + case dt_install_to_chroot: + if ((! (*r)->installed_root_key()) || ((*r)->installed_root_key()->value() == FSEntry("/"))) + continue; + break; + + case dt_create_binary: + if ((*r)->installed_root_key()) + continue; + break; + + case last_dt: + break; + } + + if ((*r)->destination_interface() && + (*r)->destination_interface()->is_suitable_destination_for(*decision.origin_id())) + { + if (result) + { + if (is_fake(*r) && ! is_fake(result)) + { + } + else if (is_fake(result) && ! is_fake(*r)) + { + result = *r; + } + else + throw ConfigurationError("For '" + stringify(*decision.origin_id()) + + "' with destination type " + stringify(resolution->resolvent().destination_type()) + + ", don't know whether to install to ::" + stringify(result->name()) + + " or ::" + stringify((*r)->name())); + } + else + result = *r; + } + } + + if (! result) + throw ConfigurationError("No repository suitable for '" + stringify(*decision.origin_id()) + + "' with destination type " + stringify(resolution->resolvent().destination_type()) + " has been configured"); + return result; +} + +template class Pimp<FindRepositoryForHelper>; + diff --git a/paludis/resolver/find_repository_for_helper.hh b/paludis/resolver/find_repository_for_helper.hh new file mode 100644 index 000000000..af4bd8bbe --- /dev/null +++ b/paludis/resolver/find_repository_for_helper.hh @@ -0,0 +1,52 @@ +/* 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_FIND_REPOSITORY_FOR_HELPER_HH +#define PALUDIS_GUARD_PALUDIS_RESOLVER_FIND_REPOSITORY_FOR_HELPER_HH 1 + +#include <paludis/resolver/find_repository_for_helper-fwd.hh> +#include <paludis/resolver/resolution-fwd.hh> +#include <paludis/resolver/decision-fwd.hh> +#include <paludis/util/pimp.hh> +#include <paludis/util/attributes.hh> +#include <paludis/environment-fwd.hh> +#include <paludis/repository-fwd.hh> +#include <memory> + +namespace paludis +{ + namespace resolver + { + class PALUDIS_VISIBLE FindRepositoryForHelper : + private Pimp<FindRepositoryForHelper> + { + public: + explicit FindRepositoryForHelper(const Environment * const); + ~FindRepositoryForHelper(); + + const std::shared_ptr<const Repository> operator() ( + const std::shared_ptr<const Resolution> &, + const ChangesToMakeDecision &) const; + }; + } + + extern template class Pimp<resolver::FindRepositoryForHelper>; +} + +#endif diff --git a/paludis/resolver/resolver_test.cc b/paludis/resolver/resolver_test.cc index 3ac6bfa5d..141004ffe 100644 --- a/paludis/resolver/resolver_test.cc +++ b/paludis/resolver/resolver_test.cc @@ -195,15 +195,6 @@ paludis::resolver::resolver_test::get_use_existing_nothing_fn( return std::make_pair(ue_never, false); } -const std::shared_ptr<const Repository> -paludis::resolver::resolver_test::find_repository_for_fn( - const Environment * const env, - const std::shared_ptr<const Resolution> &, - const ChangesToMakeDecision &) -{ - return env->package_database()->fetch_repository(RepositoryName("installed")); -} - bool paludis::resolver::resolver_test::remove_if_dependent_fn( const std::shared_ptr<const QualifiedPackageNameSet> & s, @@ -324,7 +315,8 @@ ResolverTestCase::ResolverTestCase(const std::string & t, const std::string & s, allowed_to_remove_helper(&env), always_via_binary_helper(&env), can_use_helper(&env), - confirm_helper(&env) + confirm_helper(&env), + find_repository_for_helper(&env) { std::shared_ptr<Map<std::string, std::string> > keys(std::make_shared<Map<std::string, std::string>>()); keys->insert("format", "e"); @@ -375,8 +367,7 @@ ResolverTestCase::get_resolver_functions(InitialConstraints & initial_constraint n::always_via_binary_fn() = std::cref(always_via_binary_helper), n::can_use_fn() = std::cref(can_use_helper), 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::find_repository_for_fn() = std::cref(find_repository_for_helper), n::get_constraints_for_dependent_fn() = &get_constraints_for_dependent_fn, n::get_constraints_for_purge_fn() = &get_constraints_for_purge_fn, n::get_constraints_for_via_binary_fn() = &get_constraints_for_via_binary_fn, diff --git a/paludis/resolver/resolver_test.hh b/paludis/resolver/resolver_test.hh index 47a8d6206..aa21978c6 100644 --- a/paludis/resolver/resolver_test.hh +++ b/paludis/resolver/resolver_test.hh @@ -40,6 +40,7 @@ #include <paludis/resolver/always_via_binary_helper.hh> #include <paludis/resolver/can_use_helper.hh> #include <paludis/resolver/confirm_helper.hh> +#include <paludis/resolver/find_repository_for_helper.hh> #include <paludis/repositories/fake/fake_installed_repository.hh> #include <paludis/repositories/fake/fake_package_id.hh> @@ -106,11 +107,6 @@ namespace paludis const PackageDepSpec &, const std::shared_ptr<const Reason> &); - const std::shared_ptr<const Repository> find_repository_for_fn( - const Environment * const, - const std::shared_ptr<const Resolution> &, - const ChangesToMakeDecision &); - FilteredGenerator make_destination_filtered_generator_fn(const Generator &, const std::shared_ptr<const Resolution> &); @@ -147,6 +143,7 @@ namespace paludis AlwaysViaBinaryHelper always_via_binary_helper; CanUseHelper can_use_helper; ConfirmHelper confirm_helper; + FindRepositoryForHelper find_repository_for_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 0342784e3..dcc28eb18 100644 --- a/src/clients/cave/resolve_common.cc +++ b/src/clients/cave/resolve_common.cc @@ -70,6 +70,7 @@ #include <paludis/resolver/always_via_binary_helper.hh> #include <paludis/resolver/can_use_helper.hh> #include <paludis/resolver/confirm_helper.hh> +#include <paludis/resolver/find_repository_for_helper.hh> #include <paludis/user_dep_spec.hh> #include <paludis/notifier_callback.hh> @@ -1025,57 +1026,6 @@ namespace return si_ignore; } - const std::shared_ptr<const Repository> - find_repository_for_fn(const Environment * const env, - const ResolveCommandLineResolutionOptions &, - const std::shared_ptr<const Resolution> & resolution, - const ChangesToMakeDecision & decision) - { - std::shared_ptr<const Repository> result; - for (PackageDatabase::RepositoryConstIterator r(env->package_database()->begin_repositories()), - r_end(env->package_database()->end_repositories()) ; - r != r_end ; ++r) - { - switch (resolution->resolvent().destination_type()) - { - case dt_install_to_slash: - if ((! (*r)->installed_root_key()) || ((*r)->installed_root_key()->value() != FSEntry("/"))) - continue; - break; - - case dt_install_to_chroot: - if ((! (*r)->installed_root_key()) || ((*r)->installed_root_key()->value() == FSEntry("/"))) - continue; - break; - - case dt_create_binary: - if ((*r)->installed_root_key()) - continue; - break; - - case last_dt: - break; - } - - if ((*r)->destination_interface() && - (*r)->destination_interface()->is_suitable_destination_for(*decision.origin_id())) - { - if (result) - throw ConfigurationError("For '" + stringify(*decision.origin_id()) - + "' with destination type " + stringify(resolution->resolvent().destination_type()) - + ", don't know whether to install to ::" + stringify(result->name()) - + " or ::" + stringify((*r)->name())); - else - result = *r; - } - } - - if (! result) - throw ConfigurationError("No repository suitable for '" + stringify(*decision.origin_id()) - + "' with destination type " + stringify(resolution->resolvent().destination_type()) + " has been configured"); - return result; - } - Filter make_destination_filter_fn(const Resolvent & resolvent) { switch (resolvent.destination_type()) @@ -1816,14 +1766,15 @@ paludis::cave::resolve_common( else confirm_helper.add_allowed_to_break_spec(parse_user_package_dep_spec(*i, env.get(), { updso_allow_wildcards })); + FindRepositoryForHelper find_repository_for_helper(env.get()); + 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::cref(confirm_helper), - n::find_repository_for_fn() = std::bind(&find_repository_for_fn, - env.get(), std::cref(resolution_options), _1, _2), + n::find_repository_for_fn() = std::cref(find_repository_for_helper), n::get_constraints_for_dependent_fn() = std::bind(&get_constraints_for_dependent_fn, env.get(), std::cref(less_restrictive_remove_blockers_specs), _1, _2, _3), n::get_constraints_for_purge_fn() = std::bind(&get_constraints_for_purge_fn, |