aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Stephen P. Bennett <spb@exherbo.org> 2006-04-18 16:06:38 +0000
committerAvatar Stephen P. Bennett <spb@exherbo.org> 2006-04-18 16:06:38 +0000
commitbbb5f0f0c1d60746844758f28ed52e98ebb6136f (patch)
tree51e5ed4c4776185a6f19a9fad2e7681c34fab36d
parentdd0820356f45523b8fed9f3d415a6c0b0075fcb7 (diff)
downloadpaludis-bbb5f0f0c1d60746844758f28ed52e98ebb6136f.tar.gz
paludis-bbb5f0f0c1d60746844758f28ed52e98ebb6136f.tar.xz
Support querying of USE from VDBRepository.
-rw-r--r--paludis/default_environment.cc4
-rw-r--r--paludis/fake_repository.cc2
-rw-r--r--paludis/fake_repository.hh2
-rw-r--r--paludis/package_database.hh40
-rw-r--r--paludis/package_database_entry.hh69
-rw-r--r--paludis/portage_repository.cc2
-rw-r--r--paludis/portage_repository.hh2
-rw-r--r--paludis/repository.hh7
-rw-r--r--paludis/vdb_repository.cc32
-rw-r--r--paludis/vdb_repository.hh2
-rw-r--r--paludis/vdb_repository_TEST.cc25
-rwxr-xr-xpaludis/vdb_repository_TEST_setup.sh12
12 files changed, 147 insertions, 52 deletions
diff --git a/paludis/default_environment.cc b/paludis/default_environment.cc
index 02dc885..9364153 100644
--- a/paludis/default_environment.cc
+++ b/paludis/default_environment.cc
@@ -123,8 +123,8 @@ DefaultEnvironment::query_use(const UseFlagName & f, const PackageDatabaseEntry
throw InternalError(PALUDIS_HERE, "bad state " + stringify(state));
} while (false);
- switch (e ? package_database()->fetch_repository(e->get<pde_repository>())->query_use(f) :
- package_database()->fetch_repository(package_database()->favourite_repository())->query_use(f))
+ switch (e ? package_database()->fetch_repository(e->get<pde_repository>())->query_use(f, e) :
+ package_database()->fetch_repository(package_database()->favourite_repository())->query_use(f, e))
{
case use_disabled:
case use_unspecified:
diff --git a/paludis/fake_repository.cc b/paludis/fake_repository.cc
index da0798b..d594b7b 100644
--- a/paludis/fake_repository.cc
+++ b/paludis/fake_repository.cc
@@ -179,7 +179,7 @@ FakeRepository::do_query_profile_masks(const CategoryNamePart &,
}
UseFlagState
-FakeRepository::do_query_use(const UseFlagName &) const
+FakeRepository::do_query_use(const UseFlagName &, const PackageDatabaseEntry *) const
{
return use_unspecified;
}
diff --git a/paludis/fake_repository.hh b/paludis/fake_repository.hh
index bf653f6..81dc4fd 100644
--- a/paludis/fake_repository.hh
+++ b/paludis/fake_repository.hh
@@ -67,7 +67,7 @@ namespace paludis
virtual bool do_query_profile_masks(const CategoryNamePart &,
const PackageNamePart &, const VersionSpec &) const;
- virtual UseFlagState do_query_use(const UseFlagName &) const;
+ virtual UseFlagState do_query_use(const UseFlagName &, const PackageDatabaseEntry *) const;
virtual bool do_query_use_mask(const UseFlagName &) const;
diff --git a/paludis/package_database.hh b/paludis/package_database.hh
index fbbe7d5..9d310db 100644
--- a/paludis/package_database.hh
+++ b/paludis/package_database.hh
@@ -34,6 +34,7 @@
#include <paludis/util/collection.hh>
#include <paludis/version_metadata.hh>
#include <paludis/version_spec.hh>
+#include <paludis/package_database_entry.hh>
#include <ostream>
#include <algorithm>
@@ -45,45 +46,6 @@ namespace paludis
class PackageDepAtom;
/**
- * Keys in a PackageDatabaseEntry.
- */
- enum PackageDatabaseEntryKeys
- {
- pde_name, ///< Our package
- pde_version, ///< Our version
- pde_repository, ///< Our repository
- last_pde ///< Number of items
- };
-
- /**
- * Tag for a PackageDatabaseEntry.
- */
- struct PackageDatabaseEntryTag :
- SmartRecordTag<comparison_mode::FullComparisonTag, comparison_method::SmartRecordCompareByAllTag>,
- SmartRecordKeys<PackageDatabaseEntryKeys, last_pde>,
- SmartRecordKey<pde_name, QualifiedPackageName>,
- SmartRecordKey<pde_version, VersionSpec>,
- SmartRecordKey<pde_repository, RepositoryName>
- {
- };
-
- /**
- * A PackageDatabaseEntry holds a QualifiedPackageName, a VersionSpec and a
- * RepositoryName, and is fully comparable.
- */
- typedef MakeSmartRecord<PackageDatabaseEntryTag>::Type PackageDatabaseEntry;
-
- /**
- * A collection of PackageDatabaseEntry instances.
- */
- typedef SortedCollection<PackageDatabaseEntry> PackageDatabaseEntryCollection;
-
- /**
- * A PackageDatabaseEntry can be written to a stream.
- */
- std::ostream & operator<< (std::ostream &, const PackageDatabaseEntry &);
-
- /**
* A PackageDatabaseError is an error that occurs when performing some
* operation upon a PackageDatabase.
*/
diff --git a/paludis/package_database_entry.hh b/paludis/package_database_entry.hh
new file mode 100644
index 0000000..22ffd5e
--- /dev/null
+++ b/paludis/package_database_entry.hh
@@ -0,0 +1,69 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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_PACKAGE_DATABASE_ENTRY_HH
+#define PALUDIS_GUARD_PALUDIS_PACKAGE_DATABASE_ENTRY_HH 1
+
+#include <paludis/util/smart_record.hh>
+#include <paludis/name.hh>
+#include <paludis/version_spec.hh>
+
+namespace paludis
+{
+ /**
+ * Keys in a PackageDatabaseEntry.
+ */
+ enum PackageDatabaseEntryKeys
+ {
+ pde_name, ///< Our package
+ pde_version, ///< Our version
+ pde_repository, ///< Our repository
+ last_pde ///< Number of items
+ };
+
+ /**
+ * Tag for a PackageDatabaseEntry.
+ */
+ struct PackageDatabaseEntryTag :
+ SmartRecordTag<comparison_mode::FullComparisonTag, comparison_method::SmartRecordCompareByAllTag>,
+ SmartRecordKeys<PackageDatabaseEntryKeys, last_pde>,
+ SmartRecordKey<pde_name, QualifiedPackageName>,
+ SmartRecordKey<pde_version, VersionSpec>,
+ SmartRecordKey<pde_repository, RepositoryName>
+ {
+ };
+
+ /**
+ * A PackageDatabaseEntry holds a QualifiedPackageName, a VersionSpec and a
+ * RepositoryName, and is fully comparable.
+ */
+ typedef MakeSmartRecord<PackageDatabaseEntryTag>::Type PackageDatabaseEntry;
+
+ /**
+ * A collection of PackageDatabaseEntry instances.
+ */
+ typedef SortedCollection<PackageDatabaseEntry> PackageDatabaseEntryCollection;
+
+ /**
+ * A PackageDatabaseEntry can be written to a stream.
+ */
+ std::ostream & operator<< (std::ostream &, const PackageDatabaseEntry &);
+}
+
+#endif
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index f494d27..a1d37a0 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -847,7 +847,7 @@ PortageRepository::do_query_profile_masks(const CategoryNamePart &,
}
UseFlagState
-PortageRepository::do_query_use(const UseFlagName & f) const
+PortageRepository::do_query_use(const UseFlagName & f, const PackageDatabaseEntry *e) const
{
if (! _imp->has_profile)
{
diff --git a/paludis/portage_repository.hh b/paludis/portage_repository.hh
index a6cbae6..d5c9ce7 100644
--- a/paludis/portage_repository.hh
+++ b/paludis/portage_repository.hh
@@ -113,7 +113,7 @@ namespace paludis
virtual bool do_query_profile_masks(const CategoryNamePart &,
const PackageNamePart &, const VersionSpec &) const;
- virtual UseFlagState do_query_use(const UseFlagName &) const;
+ virtual UseFlagState do_query_use(const UseFlagName &, const PackageDatabaseEntry *) const;
virtual bool do_query_use_mask(const UseFlagName &) const;
diff --git a/paludis/repository.hh b/paludis/repository.hh
index e65ae3a..477e741 100644
--- a/paludis/repository.hh
+++ b/paludis/repository.hh
@@ -28,6 +28,7 @@
#include <paludis/util/virtual_constructor.hh>
#include <paludis/version_metadata.hh>
#include <paludis/version_spec.hh>
+#include <paludis/package_database_entry.hh>
#include <map>
#include <string>
@@ -147,7 +148,7 @@ namespace paludis
/**
* Override in descendents: get use.
*/
- virtual UseFlagState do_query_use(const UseFlagName &) const = 0;
+ virtual UseFlagState do_query_use(const UseFlagName &, const PackageDatabaseEntry *) const = 0;
/**
* Override in descendents: get use mask.
@@ -363,12 +364,12 @@ namespace paludis
/**
* Query the state of the specified use flag.
*/
- UseFlagState query_use(const UseFlagName & u) const
+ UseFlagState query_use(const UseFlagName & u, const PackageDatabaseEntry *pde) const
{
if (do_query_use_mask(u))
return use_disabled;
else
- return do_query_use(u);
+ return do_query_use(u, pde);
}
/**
diff --git a/paludis/vdb_repository.cc b/paludis/vdb_repository.cc
index abefaf0..b178b67 100644
--- a/paludis/vdb_repository.cc
+++ b/paludis/vdb_repository.cc
@@ -50,6 +50,7 @@ namespace
QualifiedPackageName name;
VersionSpec version;
VersionMetadata::Pointer metadata;
+ std::set<UseFlagName> use;
VDBEntry(const QualifiedPackageName & n, const VersionSpec & v) :
name(n),
@@ -286,6 +287,11 @@ Implementation<VDBRepository>::load_entry(std::vector<VDBEntry>::iterator p) con
slot = "0";
}
p->metadata->set(vmk_slot, slot);
+
+ std::string raw_use(file_contents(location, p->name, p->version, "USE"));
+ p->use.clear();
+ Tokeniser<delim_kind::AnyOfTag, delim_mode::DelimiterTag> t(" \t\n");
+ t.tokenise(raw_use, create_inserter<UseFlagName>(std::inserter(p->use, p->use.begin())));
}
VDBRepository::VDBRepository(const VDBRepositoryParams & p) :
@@ -442,9 +448,31 @@ VDBRepository::do_query_profile_masks(const CategoryNamePart &,
}
UseFlagState
-VDBRepository::do_query_use(const UseFlagName &) const
+VDBRepository::do_query_use(const UseFlagName & f, const PackageDatabaseEntry * const e) const
{
- return use_unspecified;
+ if (! _imp->entries_valid)
+ _imp->load_entries();
+
+ if (e->get<pde_repository>() == name())
+ {
+
+ std::pair<std::vector<VDBEntry>::iterator, std::vector<VDBEntry>::iterator>
+ r(std::equal_range(_imp->entries.begin(), _imp->entries.end(), std::make_pair(
+ e->get<pde_name>(), e->get<pde_version>()), VDBEntry::CompareVersion()));
+
+ if (r.first == r.second)
+ return use_unspecified;
+
+ if (!r.first->metadata)
+ _imp->load_entry(r.first);
+
+ if (r.first->use.end() != r.first->use.find(f))
+ return use_enabled;
+ else
+ return use_disabled;
+ }
+ else
+ return use_unspecified;
}
bool
diff --git a/paludis/vdb_repository.hh b/paludis/vdb_repository.hh
index 0db0f29..5b6a9c2 100644
--- a/paludis/vdb_repository.hh
+++ b/paludis/vdb_repository.hh
@@ -82,7 +82,7 @@ namespace paludis
virtual bool do_query_profile_masks(const CategoryNamePart &,
const PackageNamePart &, const VersionSpec &) const;
- virtual UseFlagState do_query_use(const UseFlagName &) const;
+ virtual UseFlagState do_query_use(const UseFlagName &, const PackageDatabaseEntry *) const;
virtual bool do_query_use_mask(const UseFlagName &) const;
diff --git a/paludis/vdb_repository_TEST.cc b/paludis/vdb_repository_TEST.cc
index f0a5ff8..d25e01e 100644
--- a/paludis/vdb_repository_TEST.cc
+++ b/paludis/vdb_repository_TEST.cc
@@ -68,5 +68,30 @@ namespace test_cases
}
} test_vdb_repository_has_category_named;
+ struct VDBRepositoryQueryUseTest : TestCase
+ {
+ VDBRepositoryQueryUseTest() : TestCase("query USE") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ std::map<std::string, std::string> keys;
+ keys.insert(std::make_pair("format", "vdb"));
+ keys.insert(std::make_pair("location", "vdb_repository_TEST_dir/repo1"));
+ VDBRepository::Pointer repo(VDBRepository::make_vdb_repository(
+ &env, env.package_database().raw_pointer(), keys));
+
+ PackageDatabaseEntry e1(QualifiedPackageName(CategoryNamePart("cat-one"), PackageNamePart("pkg-one")),
+ VersionSpec("1"), RepositoryName("installed"));
+ PackageDatabaseEntry e2(QualifiedPackageName(CategoryNamePart("cat-one"), PackageNamePart("pkg-neither")),
+ VersionSpec("1"), RepositoryName("installed"));
+
+ TEST_CHECK(repo->query_use(UseFlagName("flag1"), &e1) == use_enabled);
+ TEST_CHECK(repo->query_use(UseFlagName("flag2"), &e1) == use_enabled);
+ TEST_CHECK(repo->query_use(UseFlagName("flag3"), &e1) == use_disabled);
+
+ TEST_CHECK(repo->query_use(UseFlagName("flag4"), &e2) == use_unspecified);
+ }
+ } test_vdb_repository_query_use;
}
diff --git a/paludis/vdb_repository_TEST_setup.sh b/paludis/vdb_repository_TEST_setup.sh
index 8f3caea..e88a3f3 100755
--- a/paludis/vdb_repository_TEST_setup.sh
+++ b/paludis/vdb_repository_TEST_setup.sh
@@ -1,7 +1,17 @@
#!/bin/sh
# vim: set ft=sh sw=4 sts=4 et :
-mkdir vdb_repository_TEST_dir || exit 1
+mkdir -p vdb_repository_TEST_dir || exit 1
cd vdb_repository_TEST_dir || exit 1
mkdir -p repo1/cat-{one/{pkg-one-1,pkg-both-1},two/{pkg-two-2,pkg-both-2}} || exit 1
+
+for i in SLOT EAPI; do
+ echo "0" >repo1/cat-one/pkg-one-1/${i}
+done
+
+for i in DEPEND RDEPEND LICENSE INHERITED IUSE PDEPEND PROVIDE; do
+ touch repo1/cat-one/pkg-one-1/${i}
+done
+
+echo "flag1 flag2" >>repo1/cat-one/pkg-one-1/USE