aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-12 20:32:22 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-12 20:32:22 +0000
commita8f8cd81142237b89e9943876547c489a7c8fcc4 (patch)
treea48802e05c34698777b2c5f50feeee6b55cb03f5
parent6ec00aa68582fdf4232ed539b547b0f8546b08af (diff)
downloadpaludis-a8f8cd81142237b89e9943876547c489a7c8fcc4.tar.gz
paludis-a8f8cd81142237b89e9943876547c489a7c8fcc4.tar.xz
PROVIDE scanning. Sadly this is stupidly slow, and will remain so until we switch VDB formats
-rw-r--r--paludis/environment.cc32
-rw-r--r--paludis/environment.hh10
-rw-r--r--paludis/fake_repository.cc15
-rw-r--r--paludis/fake_repository.hh4
-rw-r--r--paludis/portage_repository.cc66
-rw-r--r--paludis/portage_repository.hh4
-rw-r--r--paludis/repository.hh6
-rw-r--r--paludis/vdb_repository.cc62
-rw-r--r--paludis/vdb_repository.hh4
9 files changed, 187 insertions, 16 deletions
diff --git a/paludis/environment.cc b/paludis/environment.cc
index 96bfbf2..8783c84 100644
--- a/paludis/environment.cc
+++ b/paludis/environment.cc
@@ -25,7 +25,8 @@
using namespace paludis;
Environment::Environment(PackageDatabase::Pointer d) :
- _package_database(d)
+ _package_database(d),
+ _has_provide_map(false)
{
}
@@ -159,3 +160,32 @@ Environment::mask_reasons(const PackageDatabaseEntry & e) const
return result;
}
+Environment::ProvideMapIterator
+Environment::begin_provide_map() const
+{
+ if (! _has_provide_map)
+ {
+ Context context("When scanning for PROVIDEs:");
+
+ for (PackageDatabase::RepositoryIterator r(package_database()->begin_repositories()),
+ r_end(package_database()->end_repositories()) ; r != r_end ; ++r)
+ {
+ if (! (*r)->installed())
+ continue;
+
+ std::copy((*r)->begin_provide_map(), (*r)->end_provide_map(),
+ std::inserter(_provide_map, _provide_map.begin()));
+ }
+
+ _has_provide_map = true;
+ }
+
+ return _provide_map.begin();
+}
+
+Environment::ProvideMapIterator
+Environment::end_provide_map() const
+{
+ return _provide_map.end();
+}
+
diff --git a/paludis/environment.hh b/paludis/environment.hh
index 4644711..ca39137 100644
--- a/paludis/environment.hh
+++ b/paludis/environment.hh
@@ -47,6 +47,10 @@ namespace paludis
private:
PackageDatabase::Pointer _package_database;
+ mutable bool _has_provide_map;
+
+ mutable std::map<QualifiedPackageName, QualifiedPackageName> _provide_map;
+
protected:
/**
* Constructor.
@@ -107,6 +111,12 @@ namespace paludis
* Destructor.
*/
virtual ~Environment();
+
+ typedef std::map<QualifiedPackageName, QualifiedPackageName>::const_iterator ProvideMapIterator;
+
+ ProvideMapIterator begin_provide_map() const;
+
+ ProvideMapIterator end_provide_map() const;
};
}
diff --git a/paludis/fake_repository.cc b/paludis/fake_repository.cc
index cf3ebec..3f6cc7a 100644
--- a/paludis/fake_repository.cc
+++ b/paludis/fake_repository.cc
@@ -46,6 +46,9 @@ namespace paludis
/// Our metadata.
std::map<std::string, VersionMetadata::Pointer > metadata;
+ /// (Empty) provides map.
+ const std::map<QualifiedPackageName, QualifiedPackageName> provide_map;
+
/// Constructor.
Implementation() :
category_names(new CategoryNamePartCollection)
@@ -240,3 +243,15 @@ FakeRepository::invalidate() const
{
}
+Repository::ProvideMapIterator
+FakeRepository::begin_provide_map() const
+{
+ return _imp->provide_map.begin();
+}
+
+Repository::ProvideMapIterator
+FakeRepository::end_provide_map() const
+{
+ return _imp->provide_map.end();
+}
+
diff --git a/paludis/fake_repository.hh b/paludis/fake_repository.hh
index 4d57bd7..c640d21 100644
--- a/paludis/fake_repository.hh
+++ b/paludis/fake_repository.hh
@@ -136,6 +136,10 @@ namespace paludis
}
virtual void invalidate() const;
+
+ virtual ProvideMapIterator begin_provide_map() const;
+
+ virtual ProvideMapIterator end_provide_map() const;
};
}
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index f6f0a72..59ef4af 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -186,6 +186,9 @@ namespace paludis
/// Invalidate our cache.
void invalidate() const;
+ /// (Empty) provides map.
+ const std::map<QualifiedPackageName, QualifiedPackageName> provide_map;
+
private:
void add_profile_r(const FSEntry & f) const;
};
@@ -418,7 +421,9 @@ PortageRepository::do_has_package_named(const CategoryNamePart & c,
+ stringify(p) + "' in " + stringify(name()) + ":");
need_category_names();
- need_virtual_names();
+
+ if (c == CategoryNamePart("virtual"))
+ need_virtual_names();
CategoryMap::iterator cat_iter(
_imp->category_names.find(c));
@@ -491,7 +496,8 @@ PortageRepository::do_package_names(const CategoryNamePart & c) const
+ "' in " + stringify(name()) + ":");
need_category_names();
- need_virtual_names();
+ if (c == CategoryNamePart("virtual"))
+ need_virtual_names();
if (_imp->category_names.end() == _imp->category_names.find(c))
return QualifiedPackageNameCollection::Pointer(new QualifiedPackageNameCollection);
@@ -582,7 +588,8 @@ PortageRepository::need_category_names() const
void
PortageRepository::need_version_names(const QualifiedPackageName & n) const
{
- need_virtual_names();
+ if (n.get<qpn_category>() == CategoryNamePart("virtual"))
+ need_virtual_names();
if (_imp->package_names[n])
return;
@@ -907,21 +914,40 @@ PortageRepository::need_virtual_names() const
if (_imp->has_virtuals)
return;
- if (! _imp->has_profile)
+ _imp->has_virtuals = true;
+
+ try
{
- Context context("When loading virtual names:");
- _imp->add_profile(_imp->profile.realpath());
- _imp->has_profile = true;
- }
+ if (! _imp->has_profile)
+ {
+ Context context("When loading virtual names:");
+ _imp->add_profile(_imp->profile.realpath());
+ _imp->has_profile = true;
+ }
- need_category_names();
+ need_category_names();
- for (VirtualsMap::const_iterator
- v(_imp->virtuals_map.begin()), v_end(_imp->virtuals_map.end()) ;
- v != v_end ; ++v)
- _imp->package_names.insert(std::make_pair(v->first, false));
+ for (Environment::ProvideMapIterator p(_imp->env->begin_provide_map()),
+ p_end(_imp->env->end_provide_map()) ; p != p_end ; ++p)
+ {
+ if (! has_package_named(p->second))
+ continue;
- _imp->has_virtuals = true;
+ _imp->virtuals_map.erase(p->first);
+ _imp->virtuals_map.insert(std::make_pair(p->first, PackageDepAtom::Pointer(
+ new PackageDepAtom(p->second))));
+ }
+
+ for (VirtualsMap::const_iterator
+ v(_imp->virtuals_map.begin()), v_end(_imp->virtuals_map.end()) ;
+ v != v_end ; ++v)
+ _imp->package_names.insert(std::make_pair(v->first, false));
+ }
+ catch (...)
+ {
+ _imp->has_virtuals = false;
+ throw;
+ }
}
CountedPtr<Repository>
@@ -1275,3 +1301,15 @@ PortageRepository::invalidate() const
_imp->invalidate();
}
+Repository::ProvideMapIterator
+PortageRepository::begin_provide_map() const
+{
+ return _imp->provide_map.begin();
+}
+
+Repository::ProvideMapIterator
+PortageRepository::end_provide_map() const
+{
+ return _imp->provide_map.end();
+}
+
diff --git a/paludis/portage_repository.hh b/paludis/portage_repository.hh
index bd2d1fd..085d8f5 100644
--- a/paludis/portage_repository.hh
+++ b/paludis/portage_repository.hh
@@ -129,6 +129,10 @@ namespace paludis
}
virtual void invalidate() const;
+
+ virtual ProvideMapIterator begin_provide_map() const;
+
+ virtual ProvideMapIterator end_provide_map() const;
};
/**
diff --git a/paludis/repository.hh b/paludis/repository.hh
index 4ef444d..d57b49b 100644
--- a/paludis/repository.hh
+++ b/paludis/repository.hh
@@ -428,6 +428,12 @@ namespace paludis
* Invalidate any cache.
*/
virtual void invalidate() const = 0;
+
+ typedef std::map<QualifiedPackageName, QualifiedPackageName>::const_iterator ProvideMapIterator;
+
+ virtual ProvideMapIterator begin_provide_map() const = 0;
+
+ virtual ProvideMapIterator end_provide_map() const = 0;
};
/**
diff --git a/paludis/vdb_repository.cc b/paludis/vdb_repository.cc
index b6fdb8a..47ad3ed 100644
--- a/paludis/vdb_repository.cc
+++ b/paludis/vdb_repository.cc
@@ -156,6 +156,12 @@ namespace paludis
/// Load metadata for one entry.
void load_entry(std::vector<VDBEntry>::iterator) const;
+ /// Do we have provide map loaded?
+ mutable bool has_provide_map;
+
+ /// Provide map.
+ mutable std::map<QualifiedPackageName, QualifiedPackageName> provide_map;
+
/// Constructor.
Implementation(const Environment * const,
const PackageDatabase * const d, const FSEntry & l,
@@ -176,7 +182,8 @@ Implementation<VDBRepository>::Implementation(const Environment * const env,
env(env),
location(l),
root(r),
- entries_valid(false)
+ entries_valid(false),
+ has_provide_map(false)
{
}
@@ -217,6 +224,9 @@ Implementation<VDBRepository>::invalidate() const
{
entries_valid = false;
entries.clear();
+
+ has_provide_map = false;
+ provide_map.clear();
}
namespace
@@ -586,3 +596,53 @@ VDBRepository::invalidate() const
_imp->invalidate();
}
+Repository::ProvideMapIterator
+VDBRepository::begin_provide_map() const
+{
+ if (! _imp->has_provide_map)
+ {
+ Context context("When loading VDB PROVIDEs map:");
+
+ if (! _imp->entries_valid)
+ _imp->load_entries();
+
+ for (std::vector<VDBEntry>::iterator e(_imp->entries.begin()),
+ e_end(_imp->entries.end()) ; e != e_end ; ++e)
+ {
+ if (! e->metadata)
+ _imp->load_entry(e);
+ const std::string provide_str(e->metadata->get(vmk_provide));
+ if (provide_str.empty())
+ continue;
+
+ DepAtom::ConstPointer provide(DepParser::parse(provide_str,
+ DepParserPolicy<PackageDepAtom, false>::get_instance()));
+ PackageDatabaseEntry dbe(e->name, e->version, name());
+ DepAtomFlattener f(_imp->env, &dbe, provide);
+
+ for (DepAtomFlattener::Iterator p(f.begin()), p_end(f.end()) ; p != p_end ; ++p)
+ {
+ QualifiedPackageName pp((*p)->text());
+
+ if (pp.get<qpn_category>() != CategoryNamePart("virtual"))
+ Log::get_instance()->message(ll_warning, "PROVIDE of non-virtual '"
+ + stringify(pp) + "' from '" + stringify(e->name) + "-"
+ + stringify(e->version) + "' in '" + stringify(name())
+ + "' will not work as expected");
+
+ _imp->provide_map.insert(std::make_pair(pp, e->name));
+ }
+ }
+
+ _imp->has_provide_map = true;
+ }
+
+ return _imp->provide_map.begin();
+}
+
+Repository::ProvideMapIterator
+VDBRepository::end_provide_map() const
+{
+ return _imp->provide_map.end();
+}
+
diff --git a/paludis/vdb_repository.hh b/paludis/vdb_repository.hh
index 99ec992..c923740 100644
--- a/paludis/vdb_repository.hh
+++ b/paludis/vdb_repository.hh
@@ -106,6 +106,10 @@ namespace paludis
}
virtual void invalidate() const;
+
+ virtual ProvideMapIterator begin_provide_map() const;
+
+ virtual ProvideMapIterator end_provide_map() const;
};
/**