aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-12-06 21:10:05 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-12-06 23:25:05 +0000
commit17713e3263bd523cd60208e221f0cebdbad0f3af (patch)
treec375639137aa3c9809dd47c1ddf9607b7a9b28f0
parent0c705e0475a6ed144db7b6913493a643e49e20b6 (diff)
downloadpaludis-17713e3263bd523cd60208e221f0cebdbad0f3af.tar.gz
paludis-17713e3263bd523cd60208e221f0cebdbad0f3af.tar.xz
Refactor
-rw-r--r--paludis/resolver/Makefile.am11
-rw-r--r--paludis/resolver/any_child_score-fwd.hh36
-rw-r--r--paludis/resolver/any_child_score.cc31
-rw-r--r--paludis/resolver/any_child_score.hh30
-rw-r--r--paludis/resolver/any_child_score.se32
-rw-r--r--paludis/resolver/decider.cc32
-rw-r--r--paludis/resolver/decider.hh3
-rw-r--r--paludis/resolver/sanitised_dependencies.cc15
8 files changed, 165 insertions, 25 deletions
diff --git a/paludis/resolver/Makefile.am b/paludis/resolver/Makefile.am
index 8b21ff3..e3c5a7b 100644
--- a/paludis/resolver/Makefile.am
+++ b/paludis/resolver/Makefile.am
@@ -1,24 +1,28 @@
include $(top_srcdir)/misc/common-makefile.am
DISTCLEANFILES = \
+ any_child_score-se.hh any_child_score-se.cc \
destination_types-se.hh destination_types-se.cc \
failure_kinds-se.hh failure_kinds-se.cc \
sync_point-se.hh sync_point-se.cc \
use_existing-se.hh use_existing-se.cc
AM_CXXFLAGS = -I$(top_srcdir) @PALUDIS_CXXFLAGS@ @PALUDIS_CXXFLAGS_VISIBILITY@
EXTRA_DIST = \
+ any_child_score-se.hh any_child_score-se.cc any_child_score.se \
destination_types-se.hh destination_types-se.cc destination_types.se \
failure_kinds-se.hh failure_kinds-se.cc failure_kinds.se \
sync_point-se.hh sync_point-se.cc sync_point.se \
use_existing-se.hh use_existing-se.cc use_existing.se \
$(check_SCRIPTS)
BUILT_SOURCES = \
+ any_child_score-se.hh any_child_score-se.cc \
destination_types-se.hh destination_types-se.cc \
failure_kinds-se.hh failure_kinds-se.cc \
sync_point-se.hh sync_point-se.cc \
use_existing-se.hh use_existing-se.cc
noinst_HEADERS = \
+ any_child_score.hh any_child_score-fwd.hh any_child_score-se.hh \
arrow.hh arrow-fwd.hh \
constraint.hh constraint-fwd.hh \
job.hh job-fwd.hh \
@@ -45,6 +49,7 @@ noinst_HEADERS = \
use_existing.hh use_existing-fwd.hh use_existing-se.hh
libpaludisresolver_a_SOURCES = \
+ any_child_score.cc \
arrow.cc \
constraint.cc \
decider.cc \
@@ -217,3 +222,9 @@ destination_types-se.hh : destination_types.se $(top_srcdir)/misc/make_se.bash
destination_types-se.cc : destination_types.se $(top_srcdir)/misc/make_se.bash
if ! $(top_srcdir)/misc/make_se.bash --source $(srcdir)/destination_types.se > $@ ; then rm -f $@ ; exit 1 ; fi
+any_child_score-se.hh : any_child_score.se $(top_srcdir)/misc/make_se.bash
+ if ! $(top_srcdir)/misc/make_se.bash --header $(srcdir)/any_child_score.se > $@ ; then rm -f $@ ; exit 1 ; fi
+
+any_child_score-se.cc : any_child_score.se $(top_srcdir)/misc/make_se.bash
+ if ! $(top_srcdir)/misc/make_se.bash --source $(srcdir)/any_child_score.se > $@ ; then rm -f $@ ; exit 1 ; fi
+
diff --git a/paludis/resolver/any_child_score-fwd.hh b/paludis/resolver/any_child_score-fwd.hh
new file mode 100644
index 0000000..b90a539
--- /dev/null
+++ b/paludis/resolver/any_child_score-fwd.hh
@@ -0,0 +1,36 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 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_ANY_CHILD_SCORE_FWD_HH
+#define PALUDIS_GUARD_PALUDIS_RESOLVER_ANY_CHILD_SCORE_FWD_HH 1
+
+#include <paludis/util/attributes.hh>
+#include <iosfwd>
+
+namespace paludis
+{
+ namespace resolver
+ {
+
+#include <paludis/resolver/any_child_score-se.hh>
+
+ }
+}
+
+#endif
diff --git a/paludis/resolver/any_child_score.cc b/paludis/resolver/any_child_score.cc
new file mode 100644
index 0000000..ca3013f
--- /dev/null
+++ b/paludis/resolver/any_child_score.cc
@@ -0,0 +1,31 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 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/any_child_score.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/exception.hh>
+#include <istream>
+#include <ostream>
+
+using namespace paludis;
+using namespace paludis::resolver;
+
+#include <paludis/resolver/any_child_score-se.cc>
+
+
diff --git a/paludis/resolver/any_child_score.hh b/paludis/resolver/any_child_score.hh
new file mode 100644
index 0000000..61b116f
--- /dev/null
+++ b/paludis/resolver/any_child_score.hh
@@ -0,0 +1,30 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 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_ANY_CHILD_SCORE_HH
+#define PALUDIS_GUARD_PALUDIS_RESOLVER_ANY_CHILD_SCORE_HH 1
+
+#include <paludis/resolver/any_child_score-fwd.hh>
+
+namespace paludis
+{
+
+}
+
+#endif
diff --git a/paludis/resolver/any_child_score.se b/paludis/resolver/any_child_score.se
new file mode 100644
index 0000000..dba5ba4
--- /dev/null
+++ b/paludis/resolver/any_child_score.se
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+# vim: set sw=4 sts=4 et ft=sh :
+
+make_enum_AnyChildScore()
+{
+ prefix acs
+ namespace paludis::resolver
+
+ key acs_worse_than_worst "Worse than the worst option"
+ key acs_hate_hate_hate "Doesn't even exist"
+ key acs_exists "Exists"
+ key acs_could_install "Could install"
+ key acs_will_be_installing "Will be installing"
+ key acs_wrong_options_installed "Already installed, wrong options"
+ key acs_already_installed "Already installed"
+
+ want_destringify
+}
+
+make_enum_OperatorScore()
+{
+ prefix os
+ namespace paludis::resolver
+
+ key os_worse_than_worst "Worse than any option"
+ key os_less "<, <= etc"
+ key os_equal "=, =* etc"
+ key os_greater_or_none ">, >= etc, or no operator"
+
+ want_destringify
+}
+
diff --git a/paludis/resolver/decider.cc b/paludis/resolver/decider.cc
index fc9e175..1dfeb25 100644
--- a/paludis/resolver/decider.cc
+++ b/paludis/resolver/decider.cc
@@ -733,7 +733,7 @@ Decider::_initial_constraints_for(const Resolvent & r) const
return _imp->fns.get_initial_constraints_for_fn()(r);
}
-int
+std::pair<AnyChildScore, OperatorScore>
Decider::find_any_score(const Resolvent & our_resolvent, const SanitisedDependency & dep) const
{
Context context("When working out whether we'd like '" + stringify(dep.spec()) + "' because of '"
@@ -747,21 +747,21 @@ Decider::find_any_score(const Resolvent & our_resolvent, const SanitisedDependen
// note: make sure the worst_score declaration in
// AnyDepSpecChildHandler::commit in satitised_dependencies.cc
// matches this logic
- int operator_bias(0);
+ OperatorScore operator_bias(os_worse_than_worst);
if (spec.version_requirements_ptr() && ! spec.version_requirements_ptr()->empty())
{
- int score(-1);
+ OperatorScore score(os_worse_than_worst);
for (VersionRequirements::ConstIterator v(spec.version_requirements_ptr()->begin()),
v_end(spec.version_requirements_ptr()->end()) ;
v != v_end ; ++v)
{
- int local_score(0);
+ OperatorScore local_score(os_worse_than_worst);
switch (v->version_operator().value())
{
case vo_greater:
case vo_greater_equal:
- local_score = 9;
+ local_score = os_greater_or_none;
break;
case vo_equal:
@@ -769,20 +769,20 @@ Decider::find_any_score(const Resolvent & our_resolvent, const SanitisedDependen
case vo_nice_equal_star:
case vo_stupid_equal_star:
case vo_tilde_greater:
- local_score = 2;
+ local_score = os_equal;
break;
case vo_less_equal:
case vo_less:
- local_score = 1;
+ local_score = os_less;
break;
case last_vo:
- local_score = 1;
+ local_score = os_less;
break;
}
- if (score == -1)
+ if (score == os_worse_than_worst)
score = local_score;
else
switch (spec.version_requirements_mode())
@@ -805,7 +805,7 @@ Decider::find_any_score(const Resolvent & our_resolvent, const SanitisedDependen
{
/* don't bias no operator over a >= operator, so || ( >=foo-2 bar )
* still likes foo. */
- operator_bias = 9;
+ operator_bias = os_greater_or_none;
}
/* best: already installed */
@@ -814,7 +814,7 @@ Decider::find_any_score(const Resolvent & our_resolvent, const SanitisedDependen
generator::Matches(spec, MatchPackageOptions()) |
filter::InstalledAtRoot(FSEntry("/")))]);
if (! installed_ids->empty())
- return 50 + operator_bias;
+ return std::make_pair(acs_already_installed, operator_bias);
}
/* next: already installed, except with the wrong options */
@@ -824,7 +824,7 @@ Decider::find_any_score(const Resolvent & our_resolvent, const SanitisedDependen
generator::Matches(spec, MatchPackageOptions() + mpo_ignore_additional_requirements) |
filter::InstalledAtRoot(FSEntry("/")))]);
if (! installed_ids->empty())
- return 40 + operator_bias;
+ return std::make_pair(acs_wrong_options_installed, operator_bias);
}
const std::tr1::shared_ptr<const PackageID> id(resolution_for_resolvent(
@@ -843,7 +843,7 @@ Decider::find_any_score(const Resolvent & our_resolvent, const SanitisedDependen
{
ResolutionsByResolventMap::const_iterator i(_imp->resolutions_by_resolvent.find(*r));
if (i != _imp->resolutions_by_resolvent.end())
- return 30 + operator_bias;
+ return std::make_pair(acs_will_be_installing, operator_bias);
}
}
@@ -859,7 +859,7 @@ Decider::find_any_score(const Resolvent & our_resolvent, const SanitisedDependen
resolution->constraints()->add(*c);
const std::tr1::shared_ptr<Decision> decision(_try_to_find_decision_for(*r, resolution));
if (decision)
- return 20 + operator_bias;
+ return std::make_pair(acs_could_install, operator_bias);
}
}
@@ -869,11 +869,11 @@ Decider::find_any_score(const Resolvent & our_resolvent, const SanitisedDependen
generator::Matches(spec, MatchPackageOptions() + mpo_ignore_additional_requirements)
)]);
if (! ids->empty())
- return 10 + operator_bias;
+ return std::make_pair(acs_exists, operator_bias);
}
/* yay, people are depping upon packages that don't exist again. I SMELL A LESSPIPE. */
- return 0;
+ return std::make_pair(acs_hate_hate_hate, operator_bias);
}
namespace
diff --git a/paludis/resolver/decider.hh b/paludis/resolver/decider.hh
index dc66346..6a91003 100644
--- a/paludis/resolver/decider.hh
+++ b/paludis/resolver/decider.hh
@@ -34,6 +34,7 @@
#include <paludis/resolver/resolutions-fwd.hh>
#include <paludis/resolver/resolver_functions-fwd.hh>
#include <paludis/resolver/resolver-fwd.hh>
+#include <paludis/resolver/any_child_score-fwd.hh>
#include <paludis/util/attributes.hh>
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/dep_spec-fwd.hh>
@@ -179,7 +180,7 @@ namespace paludis
void add_target_with_reason(const PackageDepSpec &, const std::tr1::shared_ptr<const Reason> &);
- int find_any_score(const Resolvent &, const SanitisedDependency &) const;
+ std::pair<AnyChildScore, OperatorScore> find_any_score(const Resolvent &, const SanitisedDependency &) const;
const std::tr1::shared_ptr<const RewrittenSpec> rewrite_if_special(const PackageOrBlockDepSpec &,
const std::tr1::shared_ptr<const Resolvent> & maybe_from) const;
diff --git a/paludis/resolver/sanitised_dependencies.cc b/paludis/resolver/sanitised_dependencies.cc
index e0d1055..7dfc160 100644
--- a/paludis/resolver/sanitised_dependencies.cc
+++ b/paludis/resolver/sanitised_dependencies.cc
@@ -253,27 +253,26 @@ namespace
{
/* we've got a choice of groups of packages. pick the best score, left to right. */
std::list<std::list<PackageOrBlockDepSpec> >::const_iterator g_best(child_groups.end());
- int best_score(-1);
+ std::pair<AnyChildScore, OperatorScore> best_score(acs_worse_than_worst, os_worse_than_worst);
for (std::list<std::list<PackageOrBlockDepSpec> >::const_iterator g(child_groups.begin()),
g_end(child_groups.end()) ;
g != g_end ; ++g)
{
- // should match Decider::find_any_score logic:
- // equivalent to an already installed spec with no
- // version operator
- int worst_score(59);
+ /* best possible, to get ( ) right */
+ std::pair<AnyChildScore, OperatorScore> worst_score(acs_already_installed, os_greater_or_none);
/* score of a group is the score of the worst child. */
for (std::list<PackageOrBlockDepSpec>::const_iterator h(g->begin()), h_end(g->end()) ;
h != h_end ; ++h)
{
- int score(decider.find_any_score(our_resolvent, make_sanitised(PackageOrBlockDepSpec(*h))));
- if ((-1 == worst_score) || (score < worst_score))
+ std::pair<AnyChildScore, OperatorScore> score(
+ decider.find_any_score(our_resolvent, make_sanitised(PackageOrBlockDepSpec(*h))));
+ if (score < worst_score)
worst_score = score;
}
- if ((best_score == -1) || (worst_score > best_score))
+ if (worst_score > best_score)
{
best_score = worst_score;
g_best = g;