aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-11-21 05:24:39 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-11-21 05:24:39 +0000
commit270a702f018c5616d7a69072b3c32bef19b1cb36 (patch)
tree81bd86755266833b5954f4bf02f0de486364a1ab
parentddf65604053759e2988195f8cb650cca7d596a79 (diff)
downloadpaludis-270a702f018c5616d7a69072b3c32bef19b1cb36.tar.gz
paludis-270a702f018c5616d7a69072b3c32bef19b1cb36.tar.xz
Implement paludis --uninstall --with-unused-dependencies
-rw-r--r--paludis/dep_list_TEST.cc3
-rw-r--r--paludis/files.m41
-rw-r--r--paludis/tasks/uninstall_task.cc42
-rw-r--r--paludis/tasks/uninstall_task.hh8
-rw-r--r--paludis/uninstall_list.cc289
-rw-r--r--paludis/uninstall_list.sr41
-rw-r--r--paludis/uninstall_list_TEST.cc321
-rw-r--r--src/paludis/command_line.cc2
-rw-r--r--src/paludis/command_line.hh3
-rw-r--r--src/paludis/install.cc2
-rw-r--r--src/paludis/uninstall.cc18
11 files changed, 703 insertions, 27 deletions
diff --git a/paludis/dep_list_TEST.cc b/paludis/dep_list_TEST.cc
index e743c36..b5a1057 100644
--- a/paludis/dep_list_TEST.cc
+++ b/paludis/dep_list_TEST.cc
@@ -17,7 +17,8 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <paludis/paludis.hh>
+#include <paludis/dep_list.hh>
+#include <paludis/portage_dep_parser.hh>
#include <paludis/repositories/fake/fake_repository.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
#include <paludis/repositories/virtuals/virtuals_repository.hh>
diff --git a/paludis/files.m4 b/paludis/files.m4
index 8aaccc7..91adfbe 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -33,6 +33,7 @@ add(`repository', `hh', `cc', `sr')
add(`repository_config_entry', `sr')
add(`repository_so_loader', `cc')
add(`syncer', `hh', `cc', `sr')
+add(`uninstall_list', `hh', `cc', `sr', `test')
add(`use_config_entry', `sr')
add(`version_metadata', `hh', `cc', `sr')
add(`version_operator', `hh', `cc', `test')
diff --git a/paludis/tasks/uninstall_task.cc b/paludis/tasks/uninstall_task.cc
index 6770c75..4b52cb8 100644
--- a/paludis/tasks/uninstall_task.cc
+++ b/paludis/tasks/uninstall_task.cc
@@ -19,6 +19,7 @@
#include "uninstall_task.hh"
#include <paludis/environment.hh>
+#include <paludis/uninstall_list.hh>
#include <paludis/util/collection_concrete.hh>
#include <list>
@@ -38,12 +39,14 @@ namespace paludis
bool pretend;
bool preserve_world;
+ bool with_unused_dependencies;
Implementation<UninstallTask>(Environment * const e) :
env(e),
install_options(false, false),
pretend(false),
- preserve_world(false)
+ preserve_world(false),
+ with_unused_dependencies(false)
{
}
};
@@ -115,14 +118,19 @@ namespace
void
UninstallTask::execute()
{
- Context context("When executing install task:");
+ Context context("When executing uninstall task:");
on_build_unmergelist_pre();
- PackageDatabaseEntryCollection::Pointer unmerge(new PackageDatabaseEntryCollection::Concrete);
+ UninstallList list(_imp->env, UninstallListOptions::create()
+ .with_dependencies(false)
+ .with_unused_dependencies(_imp->with_unused_dependencies));
+
for (std::list<PackageDepAtom::Pointer>::const_iterator t(_imp->targets.begin()),
t_end(_imp->targets.end()) ; t != t_end ; ++t)
{
+ Context local_context("When looking for target '" + stringify(**t) + "':");
+
PackageDatabaseEntryCollection::ConstPointer r(_imp->env->package_database()->query(
*t, is_installed_only));
if (r->empty())
@@ -130,15 +138,14 @@ UninstallTask::execute()
else if (r->size() > 1)
throw AmbiguousUnmergeTargetError(stringify(**t), r);
else
- unmerge->insert(*r->begin());
+ list.add(*r->begin());
}
on_build_unmergelist_post();
on_display_unmerge_list_pre();
- for (PackageDatabaseEntryCollection::Iterator i(unmerge->begin()),
- i_end(unmerge->end()) ; i != i_end ; ++i)
+ for (UninstallList::Iterator i(list.begin()), i_end(list.end()) ; i != i_end ; ++i)
on_display_unmerge_list_entry(*i);
on_display_unmerge_list_post();
@@ -163,28 +170,26 @@ UninstallTask::execute()
on_update_world_post();
}
- _imp->env->perform_hook(Hook("uninstall_all_pre")("TARGETS", join(unmerge->begin(), unmerge->end(), " ")));
+ _imp->env->perform_hook(Hook("uninstall_all_pre")("TARGETS", join(_imp->raw_targets.begin(),
+ _imp->raw_targets.end(), " ")));
on_uninstall_all_pre();
- for (PackageDatabaseEntryCollection::Iterator i(unmerge->begin()),
- i_end(unmerge->end()) ; i != i_end ; ++i)
+ for (UninstallList::Iterator i(list.begin()), i_end(list.end()) ; i != i_end ; ++i)
{
- std::string cpvr(stringify(i->name) + "-" +
- stringify(i->version) + "::" +
- stringify(i->repository));
+ std::string cpvr(stringify(i->package));
_imp->env->perform_hook(Hook("uninstall_pre")("TARGET", cpvr));
on_uninstall_pre(*i);
const RepositoryUninstallableInterface * const uninstall_interface(
- _imp->env->package_database()->fetch_repository(i->repository)->
+ _imp->env->package_database()->fetch_repository(i->package.repository)->
uninstallable_interface);
if (! uninstall_interface)
throw InternalError(PALUDIS_HERE, "Trying to uninstall from a non-uninstallable repo");
try
{
- uninstall_interface->uninstall(i->name, i->version, _imp->install_options);
+ uninstall_interface->uninstall(i->package.name, i->package.version, _imp->install_options);
}
catch (const PackageUninstallActionError & e)
{
@@ -197,10 +202,17 @@ UninstallTask::execute()
}
on_uninstall_all_post();
- _imp->env->perform_hook(Hook("uninstall_all_post")("TARGETS", join(unmerge->begin(), unmerge->end(), " ")));
+ _imp->env->perform_hook(Hook("uninstall_all_post")("TARGETS", join(_imp->raw_targets.begin(),
+ _imp->raw_targets.end(), " ")));
}
AmbiguousUnmergeTargetError::~AmbiguousUnmergeTargetError() throw ()
{
}
+void
+UninstallTask::set_with_unused_dependencies(const bool value)
+{
+ _imp->with_unused_dependencies = value;
+}
+
diff --git a/paludis/tasks/uninstall_task.hh b/paludis/tasks/uninstall_task.hh
index 9f7e846..d028b11 100644
--- a/paludis/tasks/uninstall_task.hh
+++ b/paludis/tasks/uninstall_task.hh
@@ -28,6 +28,7 @@
namespace paludis
{
class Environment;
+ class UninstallListEntry;
/**
* Thrown if an ambiguous unmerge target is supplied.
@@ -102,6 +103,7 @@ namespace paludis
void set_no_config_protect(const bool value);
void set_pretend(const bool value);
void set_preserve_world(const bool value);
+ void set_with_unused_dependencies(const bool value);
///\}
@@ -120,11 +122,11 @@ namespace paludis
virtual void on_display_unmerge_list_pre() = 0;
virtual void on_display_unmerge_list_post() = 0;
- virtual void on_display_unmerge_list_entry(const PackageDatabaseEntry &) = 0;
+ virtual void on_display_unmerge_list_entry(const UninstallListEntry &) = 0;
virtual void on_uninstall_all_pre() = 0;
- virtual void on_uninstall_pre(const PackageDatabaseEntry &) = 0;
- virtual void on_uninstall_post(const PackageDatabaseEntry &) = 0;
+ virtual void on_uninstall_pre(const UninstallListEntry &) = 0;
+ virtual void on_uninstall_post(const UninstallListEntry &) = 0;
virtual void on_uninstall_all_post() = 0;
virtual void on_update_world_pre() = 0;
diff --git a/paludis/uninstall_list.cc b/paludis/uninstall_list.cc
new file mode 100644
index 0000000..537567f
--- /dev/null
+++ b/paludis/uninstall_list.cc
@@ -0,0 +1,289 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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 "uninstall_list.hh"
+
+using namespace paludis;
+
+#include <paludis/uninstall_list-sr.cc>
+#include <paludis/environment.hh>
+#include <paludis/util/collection_concrete.hh>
+#include <paludis/util/join.hh>
+#include <paludis/util/log.hh>
+#include <list>
+#include <algorithm>
+
+namespace paludis
+{
+ template<>
+ struct Implementation<UninstallList> :
+ InternalCounted<Implementation<UninstallList> >
+ {
+ const Environment * const env;
+ UninstallListOptions options;
+ std::list<UninstallListEntry> uninstall_list;
+
+ Implementation(const Environment * const e, const UninstallListOptions & o) :
+ env(e),
+ options(o)
+ {
+ }
+ };
+}
+
+namespace
+{
+ struct MatchUninstallListEntry
+ {
+ PackageDatabaseEntry e;
+
+ MatchUninstallListEntry(const PackageDatabaseEntry & ee) :
+ e(ee)
+ {
+ }
+
+ bool operator() (const UninstallListEntry & f)
+ {
+ return f.package == e;
+ }
+ };
+}
+
+UninstallList::UninstallList(const Environment * const env, const UninstallListOptions & o) :
+ PrivateImplementationPattern<UninstallList>(new Implementation<UninstallList>(env, o)),
+ options(_imp->options)
+{
+}
+
+UninstallList::~UninstallList()
+{
+}
+
+void
+UninstallList::add(const PackageDatabaseEntry & e)
+{
+ if (_imp->uninstall_list.end() != std::find_if(_imp->uninstall_list.begin(),
+ _imp->uninstall_list.end(), MatchUninstallListEntry(e)))
+ return;
+
+ Context context("When adding '" + stringify(e) + "' to the uninstall list:");
+
+ add_package(e);
+ if (_imp->options.with_unused_dependencies)
+ add_unused_dependencies();
+}
+
+UninstallList::Iterator
+UninstallList::begin() const
+{
+ return Iterator(_imp->uninstall_list.begin());
+}
+
+UninstallList::Iterator
+UninstallList::end() const
+{
+ return Iterator(_imp->uninstall_list.end());
+}
+
+UninstallListOptions::UninstallListOptions() :
+ with_unused_dependencies(false),
+ with_dependencies(false)
+{
+}
+
+void
+UninstallList::add_package(const PackageDatabaseEntry & e)
+{
+ Context context("When adding package '" + stringify(e) + "' to the uninstall list:");
+
+ if (! _imp->env->package_database()->fetch_repository(e.repository)->has_version(e.name, e.version))
+ throw InternalError(PALUDIS_HERE, "Trying to add '" + stringify(e) +
+ "' to UninstallList but has_version failed");
+
+ _imp->uninstall_list.push_back(e);
+}
+
+PackageDatabaseEntryCollection::ConstPointer
+UninstallList::collect_all_installed() const
+{
+ Context context("When collecting all installed packages:");
+
+ PackageDatabaseEntryCollection::Pointer result(new PackageDatabaseEntryCollection::Concrete);
+ for (PackageDatabase::RepositoryIterator i(_imp->env->package_database()->begin_repositories()),
+ i_end(_imp->env->package_database()->end_repositories()) ; i != i_end ; ++i)
+ {
+ if (! (*i)->installed_interface)
+ continue;
+
+ CategoryNamePartCollection::ConstPointer cats((*i)->category_names());
+ for (CategoryNamePartCollection::Iterator c(cats->begin()), c_end(cats->end()) ;
+ c != c_end ; ++c)
+ {
+ QualifiedPackageNameCollection::ConstPointer pkgs((*i)->package_names(*c));
+ for (QualifiedPackageNameCollection::Iterator p(pkgs->begin()), p_end(pkgs->end()) ;
+ p != p_end ; ++p)
+ {
+ VersionSpecCollection::ConstPointer vers((*i)->version_specs(*p));
+ for (VersionSpecCollection::Iterator v(vers->begin()), v_end(vers->end()) ;
+ v != v_end ; ++v)
+ result->insert(PackageDatabaseEntry(*p, *v, (*i)->name()));
+ }
+ }
+ }
+
+ return result;
+}
+
+namespace
+{
+ struct DepCollector :
+ DepAtomVisitorTypes::ConstVisitor
+ {
+ const Environment * const env;
+ const PackageDatabaseEntry pkg;
+ PackageDatabaseEntryCollection::Pointer matches;
+
+ DepCollector(const Environment * const ee, const PackageDatabaseEntry & e) :
+ env(ee),
+ pkg(e),
+ matches(new PackageDatabaseEntryCollection::Concrete)
+ {
+ }
+
+ void visit(const AllDepAtom * const a)
+ {
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const PackageDepAtom * const a)
+ {
+ PackageDatabaseEntryCollection::ConstPointer m(env->package_database()->query(
+ *a, is_installed_only));
+ matches->insert(m->begin(), m->end());
+ }
+
+ void visit(const UseDepAtom * const u)
+ {
+ if (env->query_use(UseFlagName(u->flag()), &pkg) ^ u->inverse())
+ std::for_each(u->begin(), u->end(), accept_visitor(this));
+ }
+
+ void visit(const AnyDepAtom * const a)
+ {
+ 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_depped_upon(PackageDatabaseEntryCollection::ConstPointer targets) const
+{
+ Context context("When collecting depended upon packages:");
+
+ PackageDatabaseEntryCollection::Pointer result(new PackageDatabaseEntryCollection::Concrete);
+
+ for (PackageDatabaseEntryCollection::Iterator i(targets->begin()), i_end(targets->end()) ;
+ i != i_end ; ++i)
+ {
+ Context local_context("When collecting depended upon packages for '" + stringify(*i) + "':");
+ DepCollector c(_imp->env, *i);
+ VersionMetadata::ConstPointer metadata(_imp->env->package_database()->fetch_repository(
+ i->repository)->version_metadata(i->name, i->version));
+ metadata->deps.build_depend()->accept(&c);
+ metadata->deps.run_depend()->accept(&c);
+ metadata->deps.post_depend()->accept(&c);
+ result->insert(c.matches->begin(), c.matches->end());
+ }
+
+ return result;
+}
+
+void
+UninstallList::add_unused_dependencies()
+{
+ Context context("When adding unused dependencies:");
+
+ bool added(true);
+ PackageDatabaseEntryCollection::ConstPointer everything(collect_all_installed());
+ while (added)
+ {
+ added = false;
+
+ /* find packages that're depped upon by anything in our uninstall list */
+ PackageDatabaseEntryCollection::Pointer uninstall_list_targets(
+ new PackageDatabaseEntryCollection::Concrete);
+ for (std::list<UninstallListEntry>::const_iterator i(_imp->uninstall_list.begin()),
+ 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);
+ std::set_difference(everything->begin(), everything->end(),
+ uninstall_list_targets->begin(), uninstall_list_targets->end(),
+ everything_except_uninstall_list_targets->inserter());
+
+ Log::get_instance()->message(ll_debug, lc_context, "everything_except_uninstall_list_targets is '"
+ + join(everything_except_uninstall_list_targets->begin(),
+ everything_except_uninstall_list_targets->end(), " ") + "'");
+
+ PackageDatabaseEntryCollection::ConstPointer depped_upon_not_list(
+ collect_depped_upon(everything_except_uninstall_list_targets));
+
+ /* find unused dependencies */
+ PackageDatabaseEntryCollection::Pointer unused_dependencies(
+ new PackageDatabaseEntryCollection::Concrete);
+ 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 */
+ for (PackageDatabaseEntryCollection::Iterator i(unused_dependencies->begin()),
+ i_end(unused_dependencies->end()) ; i != i_end ; ++i)
+ {
+ if (_imp->uninstall_list.end() != std::find_if(_imp->uninstall_list.begin(),
+ _imp->uninstall_list.end(), MatchUninstallListEntry(*i)))
+ continue;
+
+ add_package(*i);
+ added = true;
+ }
+ }
+}
+
diff --git a/paludis/uninstall_list.sr b/paludis/uninstall_list.sr
new file mode 100644
index 0000000..ff83372
--- /dev/null
+++ b/paludis/uninstall_list.sr
@@ -0,0 +1,41 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+make_class_UninstallListOptions()
+{
+ key with_unused_dependencies bool;
+ key with_dependencies bool;
+ extra_constructors <<END
+ UninstallListOptions();
+END
+
+ allow_named_args
+
+ doxygen_comment << "END"
+ /**
+ * Parameters for an UninstallList.
+ *
+ * \see UninstallList
+ * \ingroup grpuninstalllist
+ * \nosubgrouping
+ */
+END
+}
+
+make_class_UninstallListEntry()
+{
+ key package PackageDatabaseEntry
+
+ allow_named_args
+
+ doxygen_comment << "END"
+ /**
+ * An entry in an UninstallList.
+ *
+ * \see UninstallList
+ * \ingroup grpdepresolver
+ * \nosubgrouping
+ */
+END
+}
+
diff --git a/paludis/uninstall_list_TEST.cc b/paludis/uninstall_list_TEST.cc
new file mode 100644
index 0000000..0fc8bc9
--- /dev/null
+++ b/paludis/uninstall_list_TEST.cc
@@ -0,0 +1,321 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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/uninstall_list.hh>
+#include <paludis/repositories/fake/fake_repository.hh>
+#include <paludis/repositories/fake/fake_installed_repository.hh>
+#include <paludis/repositories/virtuals/virtuals_repository.hh>
+#include <paludis/environment/test/test_environment.hh>
+#include <paludis/util/collection_concrete.hh>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+#include <string>
+#include <list>
+#include <ostream>
+
+using namespace paludis;
+using namespace test;
+
+namespace paludis
+{
+ std::ostream &
+ operator<< (std::ostream & s, const UninstallListEntry & e)
+ {
+ s << e.package;
+ return s;
+ }
+}
+
+namespace test_cases
+{
+ /**
+ * Convenience base class used by many of the UninstallList tests.
+ *
+ */
+ class UninstallListTestCaseBase :
+ public TestCase
+ {
+ protected:
+ TestEnvironment env;
+ FakeInstalledRepository::Pointer installed_repo;
+ VirtualsRepository::Pointer virtuals_repo;
+ PackageDatabaseEntryCollection::Pointer targets;
+ std::list<std::string> expected;
+ bool done_populate;
+
+ /**
+ * Constructor.
+ */
+ UninstallListTestCaseBase(const std::string & s) :
+ TestCase("uninstall list " + s),
+ env(),
+ installed_repo(new FakeInstalledRepository(RepositoryName("installed"))),
+ virtuals_repo(new VirtualsRepository(&env)),
+ targets(new PackageDatabaseEntryCollection::Concrete),
+ done_populate(false)
+ {
+ env.package_database()->add_repository(installed_repo);
+ env.package_database()->add_repository(virtuals_repo);
+ }
+
+ /**
+ * Populate our repo member.
+ */
+ virtual void populate_repo() = 0;
+
+ /**
+ * Populate our targets.
+ */
+ virtual void populate_targets() = 0;
+
+ void add_target(const std::string & p, const std::string & v)
+ {
+ targets->insert(PackageDatabaseEntry(
+ QualifiedPackageName(p),
+ VersionSpec(v),
+ RepositoryName("installed")));
+ }
+
+ /**
+ * Populate our expected member.
+ */
+ virtual void populate_expected() = 0;
+
+ /**
+ * Check expected is what we got.
+ */
+ virtual void check_lists()
+ {
+ TEST_CHECK(true);
+ UninstallList d(&env, options());
+ for (PackageDatabaseEntryCollection::Iterator i(targets->begin()),
+ i_end(targets->end()) ; i != i_end ; ++i)
+ d.add(*i);
+ TEST_CHECK(true);
+
+ unsigned n(0);
+ std::list<std::string>::const_iterator exp(expected.begin());
+ UninstallList::Iterator got(d.begin());
+ while (true)
+ {
+ TestMessageSuffix s(stringify(n++), true);
+
+ TEST_CHECK((exp == expected.end()) == (got == d.end()));
+ if (got == d.end())
+ break;
+ TEST_CHECK_STRINGIFY_EQUAL(*got, *exp);
+ ++exp;
+ ++got;
+ }
+ }
+
+ virtual UninstallListOptions options()
+ {
+ return UninstallListOptions();
+ }
+
+ public:
+ void run()
+ {
+ if (! done_populate)
+ {
+ populate_repo();
+ populate_targets();
+ populate_expected();
+ done_populate = true;
+ }
+ check_lists();
+ }
+ };
+
+ struct UninstallListSimpleTest :
+ public UninstallListTestCaseBase
+ {
+ UninstallListSimpleTest() : UninstallListTestCaseBase("simple") { }
+
+ void populate_targets()
+ {
+ add_target("foo/bar", "1");
+ }
+
+ void populate_repo()
+ {
+ installed_repo->add_version("foo", "bar", "1");
+ }
+
+ void populate_expected()
+ {
+ expected.push_back("foo/bar-1::installed");
+ }
+ } uninstall_list_simple_test;
+
+ struct UninstallListRepeatTest :
+ public UninstallListTestCaseBase
+ {
+ UninstallListRepeatTest() : UninstallListTestCaseBase("repeat") { }
+
+ void populate_targets()
+ {
+ add_target("foo/bar", "1");
+ add_target("foo/bar", "1");
+ }
+
+ void populate_repo()
+ {
+ installed_repo->add_version("foo", "bar", "1");
+ }
+
+ void populate_expected()
+ {
+ expected.push_back("foo/bar-1::installed");
+ }
+ } uninstall_list_repeat_test;
+
+ struct UninstallListWithUnusedDepsTest :
+ public UninstallListTestCaseBase
+ {
+ UninstallListWithUnusedDepsTest() : UninstallListTestCaseBase("with unused deps") { }
+
+ void populate_targets()
+ {
+ add_target("foo/bar", "1");
+ }
+
+ void populate_repo()
+ {
+ installed_repo->add_version("foo", "bar", "1")->deps.build_depend_string = "foo/baz";
+ installed_repo->add_version("foo", "baz", "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_test;
+
+ struct UninstallListWithUnusedDepsRecursiveTest :
+ public UninstallListTestCaseBase
+ {
+ UninstallListWithUnusedDepsRecursiveTest() : UninstallListTestCaseBase("with unused deps recursive") { }
+
+ void populate_targets()
+ {
+ add_target("foo/bar", "1");
+ }
+
+ void populate_repo()
+ {
+ installed_repo->add_version("foo", "bar", "1")->deps.build_depend_string = "foo/baz";
+ installed_repo->add_version("foo", "baz", "2")->deps.build_depend_string = "foo/moo";
+ installed_repo->add_version("foo", "moo", "3");
+ }
+
+ void populate_expected()
+ {
+ expected.push_back("foo/bar-1::installed");
+ expected.push_back("foo/baz-2::installed");
+ expected.push_back("foo/moo-3::installed");
+ }
+
+ UninstallListOptions options()
+ {
+ return UninstallListOptions::create()
+ .with_unused_dependencies(true)
+ .with_dependencies(false);
+ }
+ } uninstall_list_with_unused_deps_recursive_test;
+
+ struct UninstallListWithUnusedDepsWithUsedTest :
+ public UninstallListTestCaseBase
+ {
+ UninstallListWithUnusedDepsWithUsedTest() : UninstallListTestCaseBase("with unused deps with used") { }
+
+ 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/oink";
+ installed_repo->add_version("foo", "baz", "2");
+ installed_repo->add_version("foo", "moo", "3")->deps.build_depend_string = "foo/oink";
+ installed_repo->add_version("foo", "oink", "1");
+ }
+
+ 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_with_used_test;
+
+ struct UninstallListWithUnusedDepsWithCrossUsedTest :
+ public UninstallListTestCaseBase
+ {
+ UninstallListWithUnusedDepsWithCrossUsedTest() :
+ UninstallListTestCaseBase("with unused deps with cross used") { }
+
+ void populate_targets()
+ {
+ add_target("foo/moo", "3");
+ add_target("foo/bar", "1");
+ }
+
+ void populate_repo()
+ {
+ installed_repo->add_version("foo", "bar", "1")->deps.build_depend_string = "foo/baz foo/oink";
+ installed_repo->add_version("foo", "baz", "2");
+ installed_repo->add_version("foo", "moo", "3")->deps.build_depend_string = "foo/oink";
+ installed_repo->add_version("foo", "oink", "1");
+ }
+
+ void populate_expected()
+ {
+ expected.push_back("foo/bar-1::installed");
+ expected.push_back("foo/baz-2::installed");
+ expected.push_back("foo/moo-3::installed");
+ expected.push_back("foo/oink-1::installed");
+ }
+
+ UninstallListOptions options()
+ {
+ return UninstallListOptions::create()
+ .with_unused_dependencies(true)
+ .with_dependencies(false);
+ }
+ } uninstall_list_with_unused_deps_with_cross_used_test;
+}
+
+
diff --git a/src/paludis/command_line.cc b/src/paludis/command_line.cc
index f0d3853..25e96c5 100644
--- a/src/paludis/command_line.cc
+++ b/src/paludis/command_line.cc
@@ -82,6 +82,8 @@ CommandLine::CommandLine() :
("summary", "Show a summary")
("full", "Show full output (can be very verbose)"),
"none"),
+ a_with_unused_dependencies(&install_args, "with-unused-dependencies", '\0',
+ "Also uninstall any dependencies that are no longer used"),
dl_args(this, "DepList behaviour",
"Modify dependency list generation behaviour. Use with caution."),
diff --git a/src/paludis/command_line.hh b/src/paludis/command_line.hh
index 3aab733..39c8335 100644
--- a/src/paludis/command_line.hh
+++ b/src/paludis/command_line.hh
@@ -182,6 +182,9 @@ class CommandLine :
/// --show-install-reasons
paludis::args::EnumArg a_show_install_reasons;
+ /// --with-unused-dependencies
+ paludis::args::SwitchArg a_with_unused_dependencies;
+
/// }
/// \name DepList behaviour arguments
diff --git a/src/paludis/install.cc b/src/paludis/install.cc
index 7d9af88..af567a7 100644
--- a/src/paludis/install.cc
+++ b/src/paludis/install.cc
@@ -749,9 +749,11 @@ do_install()
try
{
+ cout << "Building target list... " << std::flush;
for (CommandLine::ParametersIterator q(CommandLine::get_instance()->begin_parameters()),
q_end(CommandLine::get_instance()->end_parameters()) ; q != q_end ; ++q)
task.add_target(*q);
+ cout << endl;
task.execute();
diff --git a/src/paludis/uninstall.cc b/src/paludis/uninstall.cc
index b34268a..970071d 100644
--- a/src/paludis/uninstall.cc
+++ b/src/paludis/uninstall.cc
@@ -22,6 +22,7 @@
#include <paludis/environment/default/default_environment.hh>
#include <paludis/tasks/uninstall_task.hh>
+#include <paludis/uninstall_list.hh>
#include <iostream>
@@ -73,9 +74,9 @@ namespace
"Total: " << _count << (_count == 1 ? " package" : " packages") << endl;
}
- virtual void on_display_unmerge_list_entry(const PackageDatabaseEntry & d)
+ virtual void on_display_unmerge_list_entry(const UninstallListEntry & d)
{
- cout << "* " << colour(cl_package_name, stringify(d)) << endl;
+ cout << "* " << colour(cl_package_name, stringify(d.package)) << endl;
++_count;
}
@@ -83,19 +84,19 @@ namespace
{
}
- virtual void on_uninstall_pre(const PackageDatabaseEntry & d)
+ virtual void on_uninstall_pre(const UninstallListEntry & d)
{
cout << endl << colour(cl_heading, "Uninstalling " +
- stringify(d.name) + "-" + stringify(d.version) +
- "::" + stringify(d.repository)) << endl << endl;
+ stringify(d.package.name) + "-" + stringify(d.package.version) +
+ "::" + stringify(d.package.repository)) << endl << endl;
cerr << xterm_title("(" + stringify(++_current_count) + " of " +
stringify(_count) + ") Uninstalling " +
- stringify(d.name) + "-" + stringify(d.version) +
- "::" + stringify(d.repository));
+ stringify(d.package.name) + "-" + stringify(d.package.version) +
+ "::" + stringify(d.package.repository));
}
- virtual void on_uninstall_post(const PackageDatabaseEntry &)
+ virtual void on_uninstall_post(const UninstallListEntry &)
{
}
@@ -139,6 +140,7 @@ do_uninstall()
task.set_pretend(CommandLine::get_instance()->a_pretend.specified());
task.set_no_config_protect(CommandLine::get_instance()->a_no_config_protection.specified());
task.set_preserve_world(CommandLine::get_instance()->a_preserve_world.specified());
+ task.set_with_unused_dependencies(CommandLine::get_instance()->a_with_unused_dependencies.specified());
try
{