aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-07 14:59:58 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-08 10:53:07 +0100
commit33ea45ba2c2ca7cf11f78990f890e1cce546bccc (patch)
treead67e1c1078e1adb4c0b0964ac5cdd3ecc2aa47f
parent4f3ae9c127c9865056a598b46716c8d12cdd6676 (diff)
downloadpaludis-33ea45ba2c2ca7cf11f78990f890e1cce546bccc.tar.gz
paludis-33ea45ba2c2ca7cf11f78990f890e1cce546bccc.tar.xz
PreferOrAvoidHelper
-rw-r--r--paludis/resolver/Makefile.am2
-rw-r--r--paludis/resolver/prefer_or_avoid_helper-fwd.hh31
-rw-r--r--paludis/resolver/prefer_or_avoid_helper.cc78
-rw-r--r--paludis/resolver/prefer_or_avoid_helper.hh53
-rw-r--r--paludis/resolver/resolver_TEST_any.cc13
-rw-r--r--paludis/resolver/resolver_test.cc17
-rw-r--r--paludis/resolver/resolver_test.hh7
-rw-r--r--src/clients/cave/resolve_common.cc67
8 files changed, 190 insertions, 78 deletions
diff --git a/paludis/resolver/Makefile.am b/paludis/resolver/Makefile.am
index 93acab3..aebe333 100644
--- a/paludis/resolver/Makefile.am
+++ b/paludis/resolver/Makefile.am
@@ -57,6 +57,7 @@ noinst_HEADERS = \
orderer.hh orderer-fwd.hh \
orderer_notes.hh orderer_notes-fwd.hh \
package_or_block_dep_spec.hh package_or_block_dep_spec-fwd.hh \
+ prefer_or_avoid_helper.hh prefer_or_avoid_helper-fwd.hh \
reason.hh reason-fwd.hh \
remove_if_dependent_helper.hh remove_if_dependent_helper-fwd.hh \
required_confirmations.hh required_confirmations-fwd.hh \
@@ -104,6 +105,7 @@ libpaludisresolver_a_SOURCES = \
orderer.cc \
orderer_notes.cc \
package_or_block_dep_spec.cc \
+ prefer_or_avoid_helper.cc \
reason.cc \
remove_if_dependent_helper.cc \
required_confirmations.cc \
diff --git a/paludis/resolver/prefer_or_avoid_helper-fwd.hh b/paludis/resolver/prefer_or_avoid_helper-fwd.hh
new file mode 100644
index 0000000..b7c9e8e
--- /dev/null
+++ b/paludis/resolver/prefer_or_avoid_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_PREFER_OR_AVOID_HELPER_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_RESOLVER_PREFER_OR_AVOID_HELPER_FWD_HH 1
+
+namespace paludis
+{
+ namespace resolver
+ {
+ struct PreferOrAvoidHelper;
+ }
+}
+
+#endif
diff --git a/paludis/resolver/prefer_or_avoid_helper.cc b/paludis/resolver/prefer_or_avoid_helper.cc
new file mode 100644
index 0000000..77afc1c
--- /dev/null
+++ b/paludis/resolver/prefer_or_avoid_helper.cc
@@ -0,0 +1,78 @@
+/* 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/prefer_or_avoid_helper.hh>
+#include <paludis/util/pimp-impl.hh>
+#include <paludis/util/hashes.hh>
+#include <paludis/util/tribool.hh>
+#include <paludis/name.hh>
+#include <unordered_set>
+
+using namespace paludis;
+using namespace paludis::resolver;
+
+namespace paludis
+{
+ template <>
+ struct Imp<PreferOrAvoidHelper>
+ {
+ const Environment * const env;
+ std::unordered_set<QualifiedPackageName, Hash<QualifiedPackageName> > prefer_names;
+ std::unordered_set<QualifiedPackageName, Hash<QualifiedPackageName> > avoid_names;
+
+ Imp(const Environment * const e) :
+ env(e)
+ {
+ }
+ };
+}
+
+PreferOrAvoidHelper::PreferOrAvoidHelper(const Environment * const e) :
+ Pimp<PreferOrAvoidHelper>(e)
+{
+}
+
+PreferOrAvoidHelper::~PreferOrAvoidHelper() = default;
+
+void
+PreferOrAvoidHelper::add_prefer_name(const QualifiedPackageName & name)
+{
+ _imp->prefer_names.insert(name);
+}
+
+void
+PreferOrAvoidHelper::add_avoid_name(const QualifiedPackageName & name)
+{
+ _imp->avoid_names.insert(name);
+}
+
+Tribool
+PreferOrAvoidHelper::operator() (const QualifiedPackageName & n) const
+{
+ if (_imp->prefer_names.end() != _imp->prefer_names.find(n))
+ return true;
+
+ if (_imp->avoid_names.end() != _imp->avoid_names.find(n))
+ return false;
+
+ return indeterminate;
+}
+
+template class Pimp<PreferOrAvoidHelper>;
+
diff --git a/paludis/resolver/prefer_or_avoid_helper.hh b/paludis/resolver/prefer_or_avoid_helper.hh
new file mode 100644
index 0000000..dacd029
--- /dev/null
+++ b/paludis/resolver/prefer_or_avoid_helper.hh
@@ -0,0 +1,53 @@
+/* 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_PREFER_OR_AVOID_HELPER_HH
+#define PALUDIS_GUARD_PALUDIS_RESOLVER_PREFER_OR_AVOID_HELPER_HH 1
+
+#include <paludis/resolver/prefer_or_avoid_helper-fwd.hh>
+#include <paludis/resolver/resolution-fwd.hh>
+#include <paludis/util/pimp.hh>
+#include <paludis/util/attributes.hh>
+#include <paludis/util/tribool-fwd.hh>
+#include <paludis/name-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <memory>
+
+namespace paludis
+{
+ namespace resolver
+ {
+ class PALUDIS_VISIBLE PreferOrAvoidHelper :
+ private Pimp<PreferOrAvoidHelper>
+ {
+ public:
+ explicit PreferOrAvoidHelper(const Environment * const);
+ ~PreferOrAvoidHelper();
+
+ void add_prefer_name(const QualifiedPackageName &);
+ void add_avoid_name(const QualifiedPackageName &);
+
+ Tribool operator() (const QualifiedPackageName &) const;
+ };
+ }
+
+ extern template class Pimp<resolver::PreferOrAvoidHelper>;
+}
+
+#endif
diff --git a/paludis/resolver/resolver_TEST_any.cc b/paludis/resolver/resolver_TEST_any.cc
index c189c9b..8e17997 100644
--- a/paludis/resolver/resolver_TEST_any.cc
+++ b/paludis/resolver/resolver_TEST_any.cc
@@ -162,10 +162,15 @@ namespace test_cases
a(aa),
b(bb)
{
- if (! a.is_indeterminate())
- prefer_or_avoid_names->insert(QualifiedPackageName("preferences/dep-a"), a.is_true());
- if (! b.is_indeterminate())
- prefer_or_avoid_names->insert(QualifiedPackageName("preferences/dep-b"), b.is_true());
+ if (a.is_true())
+ prefer_or_avoid_helper.add_prefer_name(QualifiedPackageName("preferences/dep-a"));
+ else if (a.is_false())
+ prefer_or_avoid_helper.add_avoid_name(QualifiedPackageName("preferences/dep-a"));
+
+ if (b.is_true())
+ prefer_or_avoid_helper.add_prefer_name(QualifiedPackageName("preferences/dep-b"));
+ else if (b.is_false())
+ prefer_or_avoid_helper.add_avoid_name(QualifiedPackageName("preferences/dep-b"));
}
void run()
diff --git a/paludis/resolver/resolver_test.cc b/paludis/resolver/resolver_test.cc
index c2f586b..c516592 100644
--- a/paludis/resolver/resolver_test.cc
+++ b/paludis/resolver/resolver_test.cc
@@ -189,18 +189,6 @@ paludis::resolver::resolver_test::get_use_existing_nothing_fn(
}
Tribool
-paludis::resolver::resolver_test::prefer_or_avoid_fn(
- const std::shared_ptr<const Map<QualifiedPackageName, bool> > & s,
- const QualifiedPackageName & q)
-{
- const Map<QualifiedPackageName, bool>::ConstIterator r(s->find(q));
- if (s->end() != r)
- return Tribool(r->second);
- else
- return indeterminate;
-}
-
-Tribool
paludis::resolver::resolver_test::order_early_fn(
const std::shared_ptr<const Resolution> &)
{
@@ -210,7 +198,6 @@ paludis::resolver::resolver_test::order_early_fn(
ResolverTestCase::ResolverTestCase(const std::string & t, const std::string & s, const std::string & e,
const std::string & l) :
TestCase(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),
@@ -221,6 +208,7 @@ ResolverTestCase::ResolverTestCase(const std::string & t, const std::string & s,
get_constraints_for_purge_helper(&env),
get_constraints_for_via_binary_helper(&env),
get_destination_types_for_error_helper(&env),
+ prefer_or_avoid_helper(&env),
remove_if_dependent_helper(&env)
{
std::shared_ptr<Map<std::string, std::string> > keys(std::make_shared<Map<std::string, std::string>>());
@@ -288,8 +276,7 @@ ResolverTestCase::get_resolver_functions(InitialConstraints & initial_constraint
n::make_origin_filtered_generator_fn() = &make_origin_filtered_generator_fn,
n::make_unmaskable_filter_fn() = &make_unmaskable_filter_fn,
n::order_early_fn() = &order_early_fn,
- n::prefer_or_avoid_fn() = std::bind(&prefer_or_avoid_fn,
- prefer_or_avoid_names, std::placeholders::_1),
+ n::prefer_or_avoid_fn() = std::cref(prefer_or_avoid_helper),
n::remove_if_dependent_fn() = std::cref(remove_if_dependent_helper)
);
}
diff --git a/paludis/resolver/resolver_test.hh b/paludis/resolver/resolver_test.hh
index ff28bf8..80420ca 100644
--- a/paludis/resolver/resolver_test.hh
+++ b/paludis/resolver/resolver_test.hh
@@ -46,6 +46,7 @@
#include <paludis/resolver/get_constraints_for_via_binary_helper.hh>
#include <paludis/resolver/get_destination_types_for_error_helper.hh>
#include <paludis/resolver/remove_if_dependent_helper.hh>
+#include <paludis/resolver/prefer_or_avoid_helper.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
#include <paludis/repositories/fake/fake_package_id.hh>
@@ -104,10 +105,6 @@ namespace paludis
Filter make_unmaskable_filter_fn(
const std::shared_ptr<const Resolution> &);
- Tribool prefer_or_avoid_fn(
- const std::shared_ptr<const Map<QualifiedPackageName, bool> > &,
- const QualifiedPackageName &);
-
Tribool order_early_fn(
const std::shared_ptr<const Resolution> &);
@@ -116,7 +113,6 @@ namespace paludis
TestEnvironment env;
std::shared_ptr<Repository> repo, inst_repo;
std::shared_ptr<FakeInstalledRepository> fake_inst_repo;
- std::shared_ptr<Map<QualifiedPackageName, bool> > prefer_or_avoid_names;
AllowChoiceChangesHelper allow_choice_changes_helper;
AllowedToRemoveHelper allowed_to_remove_helper;
@@ -128,6 +124,7 @@ namespace paludis
GetConstraintsForPurgeHelper get_constraints_for_purge_helper;
GetConstraintsForViaBinaryHelper get_constraints_for_via_binary_helper;
GetDestinationTypesForErrorHelper get_destination_types_for_error_helper;
+ PreferOrAvoidHelper prefer_or_avoid_helper;
RemoveIfDependentHelper remove_if_dependent_helper;
ResolverTestCase(const std::string & group, const std::string & test_name, const std::string & eapi,
diff --git a/src/clients/cave/resolve_common.cc b/src/clients/cave/resolve_common.cc
index 9522df6..4bf100f 100644
--- a/src/clients/cave/resolve_common.cc
+++ b/src/clients/cave/resolve_common.cc
@@ -76,6 +76,7 @@
#include <paludis/resolver/get_constraints_for_via_binary_helper.hh>
#include <paludis/resolver/get_destination_types_for_error_helper.hh>
#include <paludis/resolver/remove_if_dependent_helper.hh>
+#include <paludis/resolver/prefer_or_avoid_helper.hh>
#include <paludis/user_dep_spec.hh>
#include <paludis/notifier_callback.hh>
@@ -1064,45 +1065,6 @@ namespace
return false;
}
- bool prefer_or_avoid_one(const Environment * const, const QualifiedPackageName & q, const PackageDepSpec & s)
- {
- Context context("When working out whether we favour or avoid '" + stringify(q) + "' due to '"
- + stringify(s) + "':");
-
- if (! package_dep_spec_has_properties(s, make_named_values<PackageDepSpecProperties>(
- n::has_additional_requirements() = false,
- n::has_category_name_part() = false,
- n::has_from_repository() = false,
- n::has_in_repository() = false,
- n::has_installable_to_path() = false,
- n::has_installable_to_repository() = false,
- n::has_installed_at_path() = false,
- n::has_package() = true,
- n::has_package_name_part() = false,
- n::has_slot_requirement() = false,
- n::has_tag() = indeterminate,
- n::has_version_requirements() = false
- )))
- throw args::DoHelp("'" + stringify(s) + "' is not a simple cat/pkg");
- return *s.package_ptr() == q;
- }
-
- Tribool prefer_or_avoid_fn(
- const Environment * const env,
- const ResolveCommandLineResolutionOptions &,
- const PackageDepSpecList & favour,
- const PackageDepSpecList & avoid,
- const QualifiedPackageName & q)
- {
- if (favour.end() != std::find_if(favour.begin(), favour.end(),
- std::bind(&prefer_or_avoid_one, env, q, std::placeholders::_1)))
- return true;
- if (avoid.end() != std::find_if(avoid.begin(), avoid.end(),
- std::bind(&prefer_or_avoid_one, env, q, std::placeholders::_1)))
- return false;
- return indeterminate;
- }
-
struct ChosenIDVisitor
{
const std::pair<std::shared_ptr<const PackageID>, std::shared_ptr<const ChangedChoices> > visit(
@@ -1477,7 +1439,7 @@ paludis::cave::resolve_common(
InitialConstraints initial_constraints;
PackageDepSpecList with, without, take, take_from, ignore, ignore_from,
- favour, avoid, early, late, no_dependencies_from, no_blockers_from;
+ early, late, no_dependencies_from, no_blockers_from;
for (args::StringSetArg::ConstIterator i(resolution_options.a_without.begin_args()),
i_end(resolution_options.a_without.end_args()) ;
@@ -1515,18 +1477,6 @@ paludis::cave::resolve_common(
ignore_from.push_back(parse_user_package_dep_spec(*i, env.get(),
{ updso_allow_wildcards }));
- for (args::StringSetArg::ConstIterator i(resolution_options.a_favour.begin_args()),
- i_end(resolution_options.a_favour.end_args()) ;
- i != i_end ; ++i)
- favour.push_back(parse_user_package_dep_spec(*i, env.get(),
- { updso_allow_wildcards }));
-
- for (args::StringSetArg::ConstIterator i(resolution_options.a_avoid.begin_args()),
- i_end(resolution_options.a_avoid.end_args()) ;
- i != i_end ; ++i)
- avoid.push_back(parse_user_package_dep_spec(*i, env.get(),
- { updso_allow_wildcards }));
-
for (args::StringSetArg::ConstIterator i(resolution_options.a_early.begin_args()),
i_end(resolution_options.a_early.end_args()) ;
i != i_end ; ++i)
@@ -1676,6 +1626,16 @@ paludis::cave::resolve_common(
throw args::DoHelp("Don't understand argument '" + resolution_options.a_make.argument() + "' to '--"
+ resolution_options.a_make.long_name() + "'");
+ PreferOrAvoidHelper prefer_or_avoid_helper(env.get());
+ for (args::StringSetArg::ConstIterator i(resolution_options.a_favour.begin_args()),
+ i_end(resolution_options.a_favour.end_args()) ;
+ i != i_end ; ++i)
+ prefer_or_avoid_helper.add_prefer_name(QualifiedPackageName(*i));
+ for (args::StringSetArg::ConstIterator i(resolution_options.a_avoid.begin_args()),
+ i_end(resolution_options.a_avoid.end_args()) ;
+ i != i_end ; ++i)
+ prefer_or_avoid_helper.add_avoid_name(QualifiedPackageName(*i));
+
RemoveIfDependentHelper remove_if_dependent_helper(env.get());
for (args::StringSetArg::ConstIterator i(resolution_options.a_remove_if_dependent.begin_args()),
i_end(resolution_options.a_remove_if_dependent.end_args()) ;
@@ -1712,8 +1672,7 @@ paludis::cave::resolve_common(
env.get(), std::cref(resolution_options), _1),
n::order_early_fn() = std::bind(&order_early_fn,
env.get(), std::cref(resolution_options), std::cref(early), std::cref(late), _1),
- n::prefer_or_avoid_fn() = std::bind(&prefer_or_avoid_fn,
- env.get(), std::cref(resolution_options), std::cref(favour), std::cref(avoid), _1),
+ n::prefer_or_avoid_fn() = std::cref(prefer_or_avoid_helper),
n::remove_if_dependent_fn() = std::cref(remove_if_dependent_helper)
));