aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-11-22 07:18:28 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-11-22 07:18:28 +0000
commit1aa9e2bfb063d848d8bd0a210515b7d4e9ad20ab (patch)
treefd14ea6ca53a284cf0e7e41fc09cdfdb236281eb
parent89de88e91763caf91700e0fef7e3f4b39dd5c812 (diff)
downloadpaludis-1aa9e2bfb063d848d8bd0a210515b7d4e9ad20ab.tar.gz
paludis-1aa9e2bfb063d848d8bd0a210515b7d4e9ad20ab.tar.xz
Don't consider packages in world as unused
-rw-r--r--paludis/repositories/fake/fake_installed_repository.cc2
-rw-r--r--paludis/repositories/fake/fake_repository.cc2
-rw-r--r--paludis/repositories/fake/fake_repository_base.cc29
-rw-r--r--paludis/repositories/fake/fake_repository_base.hh9
-rw-r--r--paludis/uninstall_list.cc163
-rw-r--r--paludis/uninstall_list_TEST.cc73
6 files changed, 185 insertions, 93 deletions
diff --git a/paludis/repositories/fake/fake_installed_repository.cc b/paludis/repositories/fake/fake_installed_repository.cc
index 9afa130..9117f6e 100644
--- a/paludis/repositories/fake/fake_installed_repository.cc
+++ b/paludis/repositories/fake/fake_installed_repository.cc
@@ -27,7 +27,7 @@ FakeInstalledRepository::FakeInstalledRepository(const RepositoryName & our_name
.installed_interface(this)
.mask_interface(this)
.news_interface(0)
- .sets_interface(0)
+ .sets_interface(this)
.syncable_interface(0)
.uninstallable_interface(0)
.use_interface(this)
diff --git a/paludis/repositories/fake/fake_repository.cc b/paludis/repositories/fake/fake_repository.cc
index f573ef0..b69bcb3 100644
--- a/paludis/repositories/fake/fake_repository.cc
+++ b/paludis/repositories/fake/fake_repository.cc
@@ -27,7 +27,7 @@ FakeRepository::FakeRepository(const RepositoryName & our_name) :
.installed_interface(0)
.mask_interface(this)
.news_interface(0)
- .sets_interface(0)
+ .sets_interface(this)
.syncable_interface(0)
.uninstallable_interface(0)
.use_interface(this)
diff --git a/paludis/repositories/fake/fake_repository_base.cc b/paludis/repositories/fake/fake_repository_base.cc
index efbec73..a846062 100644
--- a/paludis/repositories/fake/fake_repository_base.cc
+++ b/paludis/repositories/fake/fake_repository_base.cc
@@ -21,6 +21,7 @@
#include <paludis/repositories/fake/fake_repository_base.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/collection_concrete.hh>
+#include <paludis/util/iterator.hh>
#include <paludis/version_metadata.hh>
#include <paludis/portage_dep_parser.hh>
@@ -56,6 +57,9 @@ namespace paludis
/// Our metadata.
std::map<std::string, VersionMetadata::Pointer > metadata;
+ /// Our sets.
+ std::map<SetName, DepAtom::Pointer > sets;
+
/// (Empty) provides map.
const std::map<QualifiedPackageName, QualifiedPackageName> provide_map;
@@ -256,3 +260,28 @@ FakeRepositoryBase::do_use_expand_value(const UseFlagName & u) const
return u;
}
+void
+FakeRepositoryBase::add_package_set(const SetName & n, DepAtom::Pointer s)
+{
+ _imp->sets.insert(std::make_pair(n, s));
+}
+
+DepAtom::Pointer
+FakeRepositoryBase::do_package_set(const SetName & id) const
+{
+ std::map<SetName, DepAtom::Pointer >::const_iterator i(_imp->sets.find(id));
+ if (_imp->sets.end() == i)
+ return DepAtom::Pointer(0);
+ else
+ return i->second;
+}
+
+SetsCollection::ConstPointer
+FakeRepositoryBase::sets_list() const
+{
+ SetsCollection::Pointer result(new SetsCollection::Concrete);
+ std::copy(_imp->sets.begin(), _imp->sets.end(),
+ transform_inserter(result->inserter(), SelectFirst<SetName, DepAtom::Pointer>()));
+ return result;
+}
+
diff --git a/paludis/repositories/fake/fake_repository_base.hh b/paludis/repositories/fake/fake_repository_base.hh
index 287e7d6..c1e9530 100644
--- a/paludis/repositories/fake/fake_repository_base.hh
+++ b/paludis/repositories/fake/fake_repository_base.hh
@@ -43,6 +43,7 @@ namespace paludis
public Repository,
public RepositoryMaskInterface,
public RepositoryUseInterface,
+ public RepositorySetsInterface,
private PrivateImplementationPattern<FakeRepositoryBase>
{
protected:
@@ -87,6 +88,9 @@ namespace paludis
virtual bool do_is_licence(const std::string &) const;
+ virtual DepAtom::Pointer do_package_set(const SetName & id) const;
+ virtual SetsCollection::ConstPointer sets_list() const;
+
protected:
/**
* Constructor.
@@ -129,6 +133,11 @@ namespace paludis
}
/**
+ * Add a package set.
+ */
+ void add_package_set(const SetName &, DepAtom::Pointer);
+
+ /**
* A non-constant smart pointer to ourself.
*/
typedef CountedPtr<FakeRepositoryBase, count_policy::InternalCountTag> Pointer;
diff --git a/paludis/uninstall_list.cc b/paludis/uninstall_list.cc
index 022554e..5ce3c5b 100644
--- a/paludis/uninstall_list.cc
+++ b/paludis/uninstall_list.cc
@@ -80,6 +80,73 @@ namespace
return f.package == e;
}
};
+
+ struct IsWorld :
+ DepAtomVisitorTypes::ConstVisitor,
+ std::unary_function<PackageDatabaseEntry, bool>
+ {
+ const Environment * const env;
+ DepAtom::ConstPointer world;
+ const PackageDatabaseEntry * dbe;
+ bool matched;
+
+ IsWorld(const Environment * const e) :
+ env(e),
+ world(e->package_set(SetName("world"))),
+ matched(false)
+ {
+ }
+
+ bool operator() (const PackageDatabaseEntry & e)
+ {
+ dbe = &e;
+ matched = false;
+ world->accept(this);
+ return matched;
+ }
+
+ void visit(const AllDepAtom * const a)
+ {
+ if (matched)
+ return;
+
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const PackageDepAtom * const a)
+ {
+ if (matched)
+ return;
+
+ if (match_package(env, a, *dbe))
+ matched = true;
+ }
+
+ void visit(const UseDepAtom * const u)
+ {
+ if (matched)
+ return;
+
+ std::for_each(u->begin(), u->end(), accept_visitor(this));
+ }
+
+ void visit(const AnyDepAtom * const a)
+ {
+ if (matched)
+ return;
+
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const BlockDepAtom * const)
+ {
+ }
+
+ void visit(const PlainTextDepAtom * const) PALUDIS_ATTRIBUTE((noreturn))
+ {
+ throw InternalError(PALUDIS_HERE, "Got PlainTextDepAtom?");
+ }
+ };
}
UninstallList::UninstallList(const Environment * const env, const UninstallListOptions & o) :
@@ -316,15 +383,9 @@ UninstallList::add_unused_dependencies()
i_end(_imp->uninstall_list.end()) ; i != i_end ; ++i)
uninstall_list_targets->insert(i->package);
- Log::get_instance()->message(ll_debug, lc_context, "uninstall_list_targets is '"
- + join(uninstall_list_targets->begin(), uninstall_list_targets->end(), " ") + "'");
-
PackageDatabaseEntryCollection::ConstPointer depped_upon_list(
collect_depped_upon(uninstall_list_targets));
- Log::get_instance()->message(ll_debug, lc_context, "depped_upon_list is '"
- + join(depped_upon_list->begin(), depped_upon_list->end(), " ") + "'");
-
/* find packages that're depped upon by anything not in our uninstall list */
PackageDatabaseEntryCollection::Pointer everything_except_uninstall_list_targets(
new PackageDatabaseEntryCollection::Concrete);
@@ -345,13 +406,14 @@ UninstallList::add_unused_dependencies()
std::set_difference(depped_upon_list->begin(), depped_upon_list->end(),
depped_upon_not_list->begin(), depped_upon_not_list->end(), unused_dependencies->inserter());
- Log::get_instance()->message(ll_debug, lc_context, "unused_dependencies is '"
- + join(unused_dependencies->begin(), unused_dependencies->end(), " ") + "'");
-
- /* if any of them aren't already on the list, add them and recurse */
+ /* if any of them aren't already on the list, and aren't in world, add them and recurse */
+ IsWorld w(_imp->env);
for (PackageDatabaseEntryCollection::Iterator i(unused_dependencies->begin()),
i_end(unused_dependencies->end()) ; i != i_end ; ++i)
{
+ if (w(*i))
+ continue;
+
if (_imp->uninstall_list.end() != std::find_if(_imp->uninstall_list.begin(),
_imp->uninstall_list.end(), MatchUninstallListEntry(*i)))
continue;
@@ -397,87 +459,6 @@ UninstallList::add_dependencies(const PackageDatabaseEntry & e)
}
}
-namespace
-{
- struct IsWorldMatcher :
- DepAtomVisitorTypes::ConstVisitor
- {
- bool matched;
-
- IsWorldMatcher() :
- matched(false)
- {
- }
- };
-
- struct IsWorld :
- DepAtomVisitorTypes::ConstVisitor,
- std::unary_function<PackageDatabaseEntry, bool>
- {
- const Environment * const env;
- DepAtom::ConstPointer world;
- const PackageDatabaseEntry * dbe;
- bool matched;
-
- IsWorld(const Environment * const e) :
- env(e),
- world(e->package_set(SetName("world"))),
- matched(false)
- {
- }
-
- bool operator() (const PackageDatabaseEntry & e)
- {
- dbe = &e;
- matched = false;
- world->accept(this);
- return matched;
- }
-
- void visit(const AllDepAtom * const a)
- {
- if (matched)
- return;
-
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const PackageDepAtom * const a)
- {
- if (matched)
- return;
-
- if (match_package(env, a, *dbe))
- matched = true;
- }
-
- void visit(const UseDepAtom * const u)
- {
- if (matched)
- return;
-
- std::for_each(u->begin(), u->end(), accept_visitor(this));
- }
-
- void visit(const AnyDepAtom * const a)
- {
- if (matched)
- return;
-
- std::for_each(a->begin(), a->end(), accept_visitor(this));
- }
-
- void visit(const BlockDepAtom * const)
- {
- }
-
- void visit(const PlainTextDepAtom * const) PALUDIS_ATTRIBUTE((noreturn))
- {
- throw InternalError(PALUDIS_HERE, "Got PlainTextDepAtom?");
- }
- };
-}
-
PackageDatabaseEntryCollection::ConstPointer
UninstallList::collect_world() const
{
diff --git a/paludis/uninstall_list_TEST.cc b/paludis/uninstall_list_TEST.cc
index 0fc8bc9..8a56c56 100644
--- a/paludis/uninstall_list_TEST.cc
+++ b/paludis/uninstall_list_TEST.cc
@@ -22,6 +22,7 @@
#include <paludis/repositories/fake/fake_installed_repository.hh>
#include <paludis/repositories/virtuals/virtuals_repository.hh>
#include <paludis/environment/test/test_environment.hh>
+#include <paludis/portage_dep_parser.hh>
#include <paludis/util/collection_concrete.hh>
#include <test/test_framework.hh>
#include <test/test_runner.hh>
@@ -316,6 +317,78 @@ namespace test_cases
.with_dependencies(false);
}
} uninstall_list_with_unused_deps_with_cross_used_test;
+
+ struct UninstallListWithUnusedDepsWorldTest :
+ public UninstallListTestCaseBase
+ {
+ UninstallListWithUnusedDepsWorldTest() :
+ UninstallListTestCaseBase("with unused deps world")
+ {
+ installed_repo->add_package_set(SetName("world"), PortageDepParser::parse(
+ "foo/moo"));
+ }
+
+ void populate_targets()
+ {
+ add_target("foo/bar", "1");
+ }
+
+ void populate_repo()
+ {
+ installed_repo->add_version("foo", "bar", "1")->deps.build_depend_string = "foo/baz foo/moo";
+ installed_repo->add_version("foo", "baz", "2");
+ installed_repo->add_version("foo", "moo", "2");
+ }
+
+ void populate_expected()
+ {
+ expected.push_back("foo/bar-1::installed");
+ expected.push_back("foo/baz-2::installed");
+ }
+
+ UninstallListOptions options()
+ {
+ return UninstallListOptions::create()
+ .with_unused_dependencies(true)
+ .with_dependencies(false);
+ }
+ } uninstall_list_with_unused_deps_world_test;
+
+ struct UninstallListWithUnusedDepsWorldTargetTest :
+ public UninstallListTestCaseBase
+ {
+ UninstallListWithUnusedDepsWorldTargetTest() :
+ UninstallListTestCaseBase("with unused deps world target")
+ {
+ installed_repo->add_package_set(SetName("world"), PortageDepParser::parse(
+ "foo/bar foo/moo"));
+ }
+
+ void populate_targets()
+ {
+ add_target("foo/bar", "1");
+ }
+
+ void populate_repo()
+ {
+ installed_repo->add_version("foo", "bar", "1")->deps.build_depend_string = "foo/baz foo/moo";
+ installed_repo->add_version("foo", "baz", "2");
+ installed_repo->add_version("foo", "moo", "2");
+ }
+
+ void populate_expected()
+ {
+ expected.push_back("foo/bar-1::installed");
+ expected.push_back("foo/baz-2::installed");
+ }
+
+ UninstallListOptions options()
+ {
+ return UninstallListOptions::create()
+ .with_unused_dependencies(true)
+ .with_dependencies(false);
+ }
+ } uninstall_list_with_unused_deps_world_target_test;
}