aboutsummaryrefslogtreecommitdiff
path: root/paludis
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-07 15:34:05 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-08 10:53:07 +0100
commit3a05acca946f4a14096a14e77f3af76e67c9fa84 (patch)
tree7e17835ba688a4ca075a50cdc1c87d8d79736240 /paludis
parent33ea45ba2c2ca7cf11f78990f890e1cce546bccc (diff)
downloadpaludis-3a05acca946f4a14096a14e77f3af76e67c9fa84.tar.gz
paludis-3a05acca946f4a14096a14e77f3af76e67c9fa84.tar.xz
OrderEarlyHelper
Diffstat (limited to 'paludis')
-rw-r--r--paludis/resolver/Makefile.am4
-rw-r--r--paludis/resolver/confirm_helper.cc36
-rw-r--r--paludis/resolver/decision_utils-fwd.hh37
-rw-r--r--paludis/resolver/decision_utils.cc68
-rw-r--r--paludis/resolver/decision_utils.hh25
-rw-r--r--paludis/resolver/order_early_helper-fwd.hh31
-rw-r--r--paludis/resolver/order_early_helper.cc85
-rw-r--r--paludis/resolver/order_early_helper.hh55
-rw-r--r--paludis/resolver/resolver_test.cc10
-rw-r--r--paludis/resolver/resolver_test.hh5
10 files changed, 311 insertions, 45 deletions
diff --git a/paludis/resolver/Makefile.am b/paludis/resolver/Makefile.am
index aebe33336..a60c43a8b 100644
--- a/paludis/resolver/Makefile.am
+++ b/paludis/resolver/Makefile.am
@@ -39,6 +39,7 @@ noinst_HEADERS = \
constraint.hh constraint-fwd.hh \
decider.hh decider-fwd.hh \
decision.hh decision-fwd.hh \
+ decision_utils.hh decision_utils-fwd.hh \
decisions.hh decisions-fwd.hh \
destination.hh destination-fwd.hh \
destination_types.hh destination_types-fwd.hh destination_types-se.hh \
@@ -54,6 +55,7 @@ noinst_HEADERS = \
job_state.hh job_state-fwd.hh \
labels_classifier.hh labels_classifier-fwd.hh \
nag.hh nag-fwd.hh \
+ order_early_helper.hh order_early_helper-fwd.hh \
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 \
@@ -87,6 +89,7 @@ libpaludisresolver_a_SOURCES = \
constraint.cc \
decider.cc \
decision.cc \
+ decision_utils.cc \
decisions.cc \
destination.cc \
destination_types.cc \
@@ -102,6 +105,7 @@ libpaludisresolver_a_SOURCES = \
job_state.cc \
labels_classifier.cc \
nag.cc \
+ order_early_helper.cc \
orderer.cc \
orderer_notes.cc \
package_or_block_dep_spec.cc \
diff --git a/paludis/resolver/confirm_helper.cc b/paludis/resolver/confirm_helper.cc
index 8edba86c7..3a531b58d 100644
--- a/paludis/resolver/confirm_helper.cc
+++ b/paludis/resolver/confirm_helper.cc
@@ -24,6 +24,7 @@
#include <paludis/resolver/resolution.hh>
#include <paludis/resolver/decision.hh>
#include <paludis/resolver/required_confirmations.hh>
+#include <paludis/resolver/decision_utils.hh>
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/make_null_shared_ptr.hh>
#include <paludis/dep_spec.hh>
@@ -136,39 +137,6 @@ namespace
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
@@ -176,7 +144,7 @@ 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()));
+ auto id(get_decided_id_or_null(resolution->decision()));
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});
}
diff --git a/paludis/resolver/decision_utils-fwd.hh b/paludis/resolver/decision_utils-fwd.hh
new file mode 100644
index 000000000..eb8643aa0
--- /dev/null
+++ b/paludis/resolver/decision_utils-fwd.hh
@@ -0,0 +1,37 @@
+/* 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_DECISION_UTILS_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_RESOLVER_DECISION_UTILS_FWD_HH 1
+
+#include <paludis/util/attributes.hh>
+#include <paludis/resolver/decision-fwd.hh>
+#include <paludis/package_id-fwd.hh>
+#include <memory>
+
+namespace paludis
+{
+ namespace resolver
+ {
+ const std::shared_ptr<const PackageID> get_decided_id_or_null(
+ const std::shared_ptr<const Decision> &) PALUDIS_ATTRIBUTE((warn_unused_result)) PALUDIS_VISIBLE;
+ }
+}
+
+#endif
diff --git a/paludis/resolver/decision_utils.cc b/paludis/resolver/decision_utils.cc
new file mode 100644
index 000000000..4633cbb53
--- /dev/null
+++ b/paludis/resolver/decision_utils.cc
@@ -0,0 +1,68 @@
+/* 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/decision_utils.hh>
+#include <paludis/resolver/decision.hh>
+#include <paludis/util/make_null_shared_ptr.hh>
+
+using namespace paludis;
+using namespace paludis::resolver;
+
+namespace
+{
+ 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();
+ }
+ };
+}
+
+const std::shared_ptr<const PackageID>
+paludis::resolver::get_decided_id_or_null(const std::shared_ptr<const Decision> & decision)
+{
+ return decision->accept_returning<std::shared_ptr<const PackageID> >(IDVisitor());
+}
+
diff --git a/paludis/resolver/decision_utils.hh b/paludis/resolver/decision_utils.hh
new file mode 100644
index 000000000..e3d6f8a5a
--- /dev/null
+++ b/paludis/resolver/decision_utils.hh
@@ -0,0 +1,25 @@
+/* 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_DECISION_UTILS_HH
+#define PALUDIS_GUARD_PALUDIS_RESOLVER_DECISION_UTILS_HH 1
+
+#include <paludis/resolver/decision_utils-fwd.hh>
+
+#endif
diff --git a/paludis/resolver/order_early_helper-fwd.hh b/paludis/resolver/order_early_helper-fwd.hh
new file mode 100644
index 000000000..6e697a287
--- /dev/null
+++ b/paludis/resolver/order_early_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_ORDER_EARLY_HELPER_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_RESOLVER_ORDER_EARLY_HELPER_FWD_HH 1
+
+namespace paludis
+{
+ namespace resolver
+ {
+ struct OrderEarlyHelper;
+ }
+}
+
+#endif
diff --git a/paludis/resolver/order_early_helper.cc b/paludis/resolver/order_early_helper.cc
new file mode 100644
index 000000000..2ea967ef0
--- /dev/null
+++ b/paludis/resolver/order_early_helper.cc
@@ -0,0 +1,85 @@
+/* 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/order_early_helper.hh>
+#include <paludis/resolver/resolvent.hh>
+#include <paludis/resolver/resolution.hh>
+#include <paludis/resolver/decision.hh>
+#include <paludis/resolver/decision_utils.hh>
+#include <paludis/util/pimp-impl.hh>
+#include <paludis/util/tribool.hh>
+#include <paludis/dep_spec.hh>
+#include <paludis/package_dep_spec_collection.hh>
+
+using namespace paludis;
+using namespace paludis::resolver;
+
+namespace paludis
+{
+ template <>
+ struct Imp<OrderEarlyHelper>
+ {
+ const Environment * const env;
+ PackageDepSpecCollection early_specs;
+ PackageDepSpecCollection late_specs;
+
+ Imp(const Environment * const e) :
+ env(e)
+ {
+ }
+ };
+}
+
+OrderEarlyHelper::OrderEarlyHelper(const Environment * const e) :
+ Pimp<OrderEarlyHelper>(e)
+{
+}
+
+OrderEarlyHelper::~OrderEarlyHelper() = default;
+
+void
+OrderEarlyHelper::add_early_spec(const PackageDepSpec & spec)
+{
+ _imp->early_specs.insert(spec);
+}
+
+void
+OrderEarlyHelper::add_late_spec(const PackageDepSpec & spec)
+{
+ _imp->late_specs.insert(spec);
+}
+
+Tribool
+OrderEarlyHelper::operator() (const std::shared_ptr<const Resolution> & resolution) const
+{
+ auto id(get_decided_id_or_null(resolution->decision()));
+
+ if (id)
+ {
+ if (_imp->early_specs.match_any(_imp->env, id, { }))
+ return true;
+ if (_imp->late_specs.match_any(_imp->env, id, { }))
+ return false;
+ }
+
+ return indeterminate;
+}
+
+template class Pimp<OrderEarlyHelper>;
+
diff --git a/paludis/resolver/order_early_helper.hh b/paludis/resolver/order_early_helper.hh
new file mode 100644
index 000000000..fe3ad3577
--- /dev/null
+++ b/paludis/resolver/order_early_helper.hh
@@ -0,0 +1,55 @@
+/* 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_ORDER_EARLY_HELPER_HH
+#define PALUDIS_GUARD_PALUDIS_RESOLVER_ORDER_EARLY_HELPER_HH 1
+
+#include <paludis/resolver/order_early_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/package_id-fwd.hh>
+#include <paludis/dep_spec-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <memory>
+
+namespace paludis
+{
+ namespace resolver
+ {
+ class PALUDIS_VISIBLE OrderEarlyHelper :
+ private Pimp<OrderEarlyHelper>
+ {
+ public:
+ explicit OrderEarlyHelper(const Environment * const);
+ ~OrderEarlyHelper();
+
+ void add_early_spec(const PackageDepSpec &);
+ void add_late_spec(const PackageDepSpec &);
+
+ Tribool operator() (
+ const std::shared_ptr<const Resolution> &) const;
+ };
+ }
+
+ extern template class Pimp<resolver::OrderEarlyHelper>;
+}
+
+#endif
diff --git a/paludis/resolver/resolver_test.cc b/paludis/resolver/resolver_test.cc
index c51659294..bf4302a52 100644
--- a/paludis/resolver/resolver_test.cc
+++ b/paludis/resolver/resolver_test.cc
@@ -188,13 +188,6 @@ paludis::resolver::resolver_test::get_use_existing_nothing_fn(
return std::make_pair(ue_never, false);
}
-Tribool
-paludis::resolver::resolver_test::order_early_fn(
- const std::shared_ptr<const Resolution> &)
-{
- return indeterminate;
-}
-
ResolverTestCase::ResolverTestCase(const std::string & t, const std::string & s, const std::string & e,
const std::string & l) :
TestCase(s),
@@ -208,6 +201,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),
+ order_early_helper(&env),
prefer_or_avoid_helper(&env),
remove_if_dependent_helper(&env)
{
@@ -275,7 +269,7 @@ ResolverTestCase::get_resolver_functions(InitialConstraints & initial_constraint
n::make_destination_filtered_generator_fn() = &make_destination_filtered_generator_fn,
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::order_early_fn() = std::cref(order_early_helper),
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 80420ca45..8f979cb74 100644
--- a/paludis/resolver/resolver_test.hh
+++ b/paludis/resolver/resolver_test.hh
@@ -45,6 +45,7 @@
#include <paludis/resolver/get_constraints_for_purge_helper.hh>
#include <paludis/resolver/get_constraints_for_via_binary_helper.hh>
#include <paludis/resolver/get_destination_types_for_error_helper.hh>
+#include <paludis/resolver/order_early_helper.hh>
#include <paludis/resolver/remove_if_dependent_helper.hh>
#include <paludis/resolver/prefer_or_avoid_helper.hh>
@@ -105,9 +106,6 @@ namespace paludis
Filter make_unmaskable_filter_fn(
const std::shared_ptr<const Resolution> &);
- Tribool order_early_fn(
- const std::shared_ptr<const Resolution> &);
-
struct ResolverTestCase : test::TestCase
{
TestEnvironment env;
@@ -124,6 +122,7 @@ namespace paludis
GetConstraintsForPurgeHelper get_constraints_for_purge_helper;
GetConstraintsForViaBinaryHelper get_constraints_for_via_binary_helper;
GetDestinationTypesForErrorHelper get_destination_types_for_error_helper;
+ OrderEarlyHelper order_early_helper;
PreferOrAvoidHelper prefer_or_avoid_helper;
RemoveIfDependentHelper remove_if_dependent_helper;