aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-11 18:50:22 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-11 18:50:22 +0000
commit85b69107d6c3c2c6090333bd0a9548fac0c791a3 (patch)
tree90639f43845d0b2538c8f07eb7440159c1b8427a
parent6eae5cfdf9fae7fdfafb0ecf48335ba48dd28466 (diff)
downloadpaludis-85b69107d6c3c2c6090333bd0a9548fac0c791a3.tar.gz
paludis-85b69107d6c3c2c6090333bd0a9548fac0c791a3.tar.xz
More yaml support
-rw-r--r--paludis/repositories/gems/cache.cc118
-rw-r--r--paludis/repositories/gems/cache.hh1
-rw-r--r--paludis/repositories/gems/cache.sr2
-rw-r--r--paludis/repositories/gems/cache_TEST.cc12
-rwxr-xr-xpaludis/repositories/gems/cache_TEST_setup.sh7
5 files changed, 137 insertions, 3 deletions
diff --git a/paludis/repositories/gems/cache.cc b/paludis/repositories/gems/cache.cc
index bd0d2b2..800f106 100644
--- a/paludis/repositories/gems/cache.cc
+++ b/paludis/repositories/gems/cache.cc
@@ -22,6 +22,7 @@
#include <paludis/repositories/gems/yaml.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/save.hh>
+#include <paludis/util/collection_concrete.hh>
#include <list>
#include <yaml.h>
@@ -71,6 +72,99 @@ namespace
return v.str;
}
+ struct VersionVisitor :
+ YamlNodeVisitorTypes::ConstVisitor
+ {
+ std::string str;
+
+ void visit(const YamlScalarNode * n) PALUDIS_ATTRIBUTE((noreturn))
+ {
+ throw GemsCacheError("Expected a mapping node, not scalar '" + n->value() + "'");
+ }
+
+ void visit(const YamlSequenceNode *) PALUDIS_ATTRIBUTE((noreturn))
+ {
+ throw GemsCacheError("Expected a mapping node, not a sequence");
+ }
+
+ void visit(const YamlMappingNode * n)
+ {
+ for (YamlMappingNode::Iterator i(n->begin()), i_end(n->end()) ; i != i_end ; ++i)
+ if (i->first->value() == "version")
+ str = as_string(i->second);
+ }
+ };
+
+ struct RequirementsVisitor :
+ YamlNodeVisitorTypes::ConstVisitor
+ {
+ VersionRequirements::Pointer r;
+ bool top_level;
+
+ std::string op;
+ std::string v;
+
+ RequirementsVisitor(VersionRequirements::Pointer rr) :
+ r(rr),
+ top_level(true)
+ {
+ }
+
+ void visit(const YamlMappingNode * n)
+ {
+ Context context("When handling mapping node:");
+
+ if (top_level)
+ {
+ for (YamlMappingNode::Iterator i(n->begin()), i_end(n->end()) ; i != i_end ; ++i)
+ if (i->first->value() == "requirements")
+ {
+ Context context2("When handling mapping node requirements key:");
+ i->second->accept(this);
+ }
+ }
+ else
+ for (YamlMappingNode::Iterator i(n->begin()), i_end(n->end()) ; i != i_end ; ++i)
+ if (i->first->value() == "version")
+ v = as_string(i->second);
+ }
+
+ void visit(const YamlSequenceNode * n)
+ {
+ Context context("When handling sequence node:");
+
+ if (top_level)
+ {
+ Save<bool> save_top_level(&top_level, false);
+ std::for_each(n->begin(), n->end(), accept_visitor(this));
+ }
+ else
+ {
+ op = "";
+ v = "";
+
+ YamlSequenceNode::Iterator i(n->begin()), i_end(n->end());
+ if (i == i_end)
+ throw YamlError("Expected a sequence with two entries, not zero");
+ op = as_string(*i++);
+ if (i == i_end)
+ throw YamlError("Expected a sequence with two entries, not one");
+ VersionVisitor vv;
+ (*i++)->accept(&vv);
+ v = vv.str;
+ if (i != i_end)
+ throw YamlError("Expected a sequence with two entries, not more than two");
+
+ r->push_back(VersionRequirement(VersionOperator(op), VersionSpec(v)));
+ }
+ }
+
+ void visit(const YamlScalarNode *) PALUDIS_ATTRIBUTE((noreturn))
+ {
+ throw YamlError("Didn't expect a scalar");
+ }
+ };
+
struct EntryVisitor :
YamlNodeVisitorTypes::ConstVisitor
{
@@ -81,9 +175,11 @@ namespace
std::string summary;
std::string description;
std::string homepage;
+ VersionRequirements::Pointer required_ruby_version;
EntryVisitor(const std::string & _id) :
- id(_id)
+ id(_id),
+ required_ruby_version(new VersionRequirements::Concrete)
{
}
@@ -98,7 +194,7 @@ namespace
.summary(summary)
.description(description)
.homepage(homepage)
- .required_ruby_version(SequentialCollection<std::string>::Pointer(0))
+ .required_ruby_version(required_ruby_version)
.authors(SequentialCollection<std::string>::Pointer(0))
.dependencies(SequentialCollection<std::string>::Pointer(0))
.requirements(SequentialCollection<std::string>::Pointer(0));
@@ -120,6 +216,24 @@ namespace
{
if (i->first->value() == "name")
name = as_string(i->second);
+ else if (i->first->value() == "summary")
+ summary = as_string(i->second);
+ else if (i->first->value() == "description")
+ description = as_string(i->second);
+ else if (i->first->value() == "homepage")
+ homepage = as_string(i->second);
+ else if (i->first->value() == "version")
+ {
+ VersionVisitor v;
+ i->second->accept(&v);
+ version = v.str;
+ }
+ else if (i->first->value() == "required_ruby_version")
+ {
+ Context context("When handling required_ruby_version children:");
+ RequirementsVisitor v(required_ruby_version);
+ i->second->accept(&v);
+ }
}
}
};
diff --git a/paludis/repositories/gems/cache.hh b/paludis/repositories/gems/cache.hh
index e3b6ebb..abb49c5 100644
--- a/paludis/repositories/gems/cache.hh
+++ b/paludis/repositories/gems/cache.hh
@@ -25,6 +25,7 @@
#include <paludis/util/collection.hh>
#include <paludis/name.hh>
#include <paludis/version_spec.hh>
+#include <paludis/version_requirements.hh>
#include <libwrapiter/libwrapiter.hh>
diff --git a/paludis/repositories/gems/cache.sr b/paludis/repositories/gems/cache.sr
index 7d2816c..52b2d29 100644
--- a/paludis/repositories/gems/cache.sr
+++ b/paludis/repositories/gems/cache.sr
@@ -8,7 +8,7 @@ make_class_GemsCacheEntry()
key summary std::string
key description std::string
key homepage std::string
- key required_ruby_version "SequentialCollection<std::string>::Pointer"
+ key required_ruby_version "VersionRequirements::Pointer"
key authors "SequentialCollection<std::string>::Pointer"
key dependencies "SequentialCollection<std::string>::Pointer"
key requirements "SequentialCollection<std::string>::Pointer"
diff --git a/paludis/repositories/gems/cache_TEST.cc b/paludis/repositories/gems/cache_TEST.cc
index fe6288e..c842d94 100644
--- a/paludis/repositories/gems/cache_TEST.cc
+++ b/paludis/repositories/gems/cache_TEST.cc
@@ -45,11 +45,23 @@ namespace test_cases
TEST_CHECK(c != cache.end());
TEST_CHECK_EQUAL(c->name, PackageNamePart("foo"));
+ TEST_CHECK_EQUAL(c->homepage, "http://foo.com/");
+ TEST_CHECK_EQUAL(c->version, VersionSpec("1.2.3"));
+
+ TEST_CHECK(c->required_ruby_version);
+ TEST_CHECK_EQUAL(std::distance(c->required_ruby_version->begin(),
+ c->required_ruby_version->end()), 1);
+ TEST_CHECK_EQUAL(c->required_ruby_version->begin()->version_operator, VersionOperator(">"));
+ TEST_CHECK_EQUAL(c->required_ruby_version->begin()->version_spec, VersionSpec("1.8.0"));
++c;
TEST_CHECK(c != cache.end());
TEST_CHECK_EQUAL(c->name, PackageNamePart("bar"));
+ TEST_CHECK_EQUAL(c->homepage, "");
+ TEST_CHECK_EQUAL(c->version, VersionSpec("2.3.4"));
+ TEST_CHECK(c->required_ruby_version);
+ TEST_CHECK(c->required_ruby_version->empty());
++c;
TEST_CHECK(c == cache.end());
diff --git a/paludis/repositories/gems/cache_TEST_setup.sh b/paludis/repositories/gems/cache_TEST_setup.sh
index 7fb6cc6..826220c 100755
--- a/paludis/repositories/gems/cache_TEST_setup.sh
+++ b/paludis/repositories/gems/cache_TEST_setup.sh
@@ -9,8 +9,15 @@ cat <<END > entries
gems:
foo-1.2.3: !ruby/object:Gem::Specification
name: foo
+ homepage: http://foo.com/
version: !ruby/object:Gem::Version
version: 1.2.3
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
+ requirements:
+ - - ">"
+ - !ruby/object:Gem::Version
+ version: 1.8.0
+ version:
bar-2.3.4: !ruby/object:Gem::Specification
name: bar