aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-18 22:43:34 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-18 22:43:34 +0000
commita317c029d9a1aa86c8e69fe7c78f1ce2fcabadbc (patch)
treea07c24833de9e95e68084cc40e277a8268e8d1ee
parent36a80160fffc083d49662b2fed38e59395896396 (diff)
downloadpaludis-a317c029d9a1aa86c8e69fe7c78f1ce2fcabadbc.tar.gz
paludis-a317c029d9a1aa86c8e69fe7c78f1ce2fcabadbc.tar.xz
(ruby) Make DepList::add accept a set spec tree.
-rw-r--r--ruby/Makefile.am12
-rw-r--r--ruby/dep_list.cc8
-rw-r--r--ruby/dep_list_TEST.rb15
-rwxr-xr-xruby/dep_list_TEST_setup.sh3
-rw-r--r--ruby/dep_spec.cc152
-rw-r--r--ruby/nice_names.nn44
-rw-r--r--ruby/paludis_ruby.hh1
7 files changed, 232 insertions, 3 deletions
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 042e65f..3c5f55f 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -3,6 +3,7 @@ SUBDIRS = . demos
AM_CXXFLAGS = -I$(top_srcdir) -I$(srcdir)/ \
-I$(top_builddir)/ \
@PALUDIS_CXXFLAGS_WITHOUT_PEDANTIC@ \
+ @PALUDIS_CXXFLAGS_NO_WMISSING_NORETURN@ \
@PALUDIS_CXXFLAGS_NO_WREDUNDANT_DECLS@ \
@PALUDIS_CXXFLAGS_NO_WOLD_STYLE_CAST@ \
@PALUDIS_CXXFLAGS_VISIBILITY@
@@ -48,6 +49,7 @@ IF_RUBY_SOURCES = \
log.cc \
metadata_key.cc \
name.cc \
+ nice_names-nn.hh nice_names-nn.cc \
package_database.cc \
package_id.cc \
qualified_package_name.cc \
@@ -56,6 +58,9 @@ IF_RUBY_SOURCES = \
version_spec.cc \
mask.cc
+BUILT_SOURCES = \
+ nice_names-nn.hh nice_names-nn.cc
+
IF_RUBY_QA_SOURCES = \
qa.cc
@@ -67,6 +72,7 @@ EXTRA_DIST = $(IF_RUBY_TESTS) $(IF_RUBY_SOURCES) \
dep_list_TEST_setup.sh dep_list_TEST_cleanup.sh \
environment_TEST_setup.sh environment_TEST_cleanup.sh \
find_unused_packages_task_TEST_setup.sh find_unused_packages_task_TEST_cleanup.sh \
+ nice_names.nn \
package_database_TEST_setup.sh package_database_TEST_cleanup.sh \
package_id_TEST_setup.sh package_id_TEST_cleanup.sh \
paludis_ruby_TEST_setup.sh paludis_ruby_TEST_cleanup.sh \
@@ -156,6 +162,12 @@ Paludis.so : libpaludisruby.la paludis_ruby_so.o
endif
+nice_names-nn.hh : nice_names.nn $(top_srcdir)/misc/make_nn.bash
+ if ! $(top_srcdir)/misc/make_nn.bash --header $(srcdir)/nice_names.nn > $@ ; then rm -f $@ ; exit 1 ; fi
+
+nice_names-nn.cc : nice_names.nn $(top_srcdir)/misc/make_nn.bash
+ if ! $(top_srcdir)/misc/make_nn.bash --source $(srcdir)/nice_names.nn > $@ ; then rm -f $@ ; exit 1 ; fi
+
built-sources : $(BUILT_SOURCES)
for s in `echo $(SUBDIRS) | tr -d .` ; do $(MAKE) -C $$s built-sources || exit 1 ; done
diff --git a/ruby/dep_list.cc b/ruby/dep_list.cc
index 47e34da..044624c 100644
--- a/ruby/dep_list.cc
+++ b/ruby/dep_list.cc
@@ -862,8 +862,10 @@ namespace
/*
* call-seq:
* add(dep_spec, destinations)
+ * add(set_spec_tree, destinations)
*
- * Add the packages required to resolve an additional dependency spec.
+ * Add the packages required to resolve an additional dependency
+ * spec or set.
*/
VALUE
dep_list_add(VALUE self, VALUE da, VALUE d)
@@ -879,8 +881,8 @@ namespace
for (long i = 0 ; i < RARRAY(d)->len ; ++i)
destinations->insert(value_to_repository(rb_ary_entry(d, i)));
- const PackageDepSpec pds = *value_to_package_dep_spec(da);
- p->add(pds, destinations);
+ tr1::shared_ptr<const SetSpecTree::ConstItem> sst(value_to_dep_tree<SetSpecTree>(da));
+ p->add(*sst, destinations);
return self;
}
catch (const std::exception & e)
diff --git a/ruby/dep_list_TEST.rb b/ruby/dep_list_TEST.rb
index 363e4c5..3e871f7 100644
--- a/ruby/dep_list_TEST.rb
+++ b/ruby/dep_list_TEST.rb
@@ -194,6 +194,21 @@ module Paludis
end
end
+ def test_add_set
+ assert_nothing_raised do
+ dl.add(env.set("world"), dd)
+ end
+ end
+
+ def test_add_bad_tree
+ assert_raise TypeError do
+ dl.add(env.package_database.
+ query(Query::Matches.new(pda),
+ QueryOrder::BestVersionOnly).
+ last.build_dependencies_key.value, dd)
+ end
+ end
+
def test_clear
assert_nothing_raised do
dl.clear
diff --git a/ruby/dep_list_TEST_setup.sh b/ruby/dep_list_TEST_setup.sh
index d04d8fb..bdd939d 100755
--- a/ruby/dep_list_TEST_setup.sh
+++ b/ruby/dep_list_TEST_setup.sh
@@ -72,11 +72,14 @@ SLOT="0"
IUSE=""
LICENSE="GPL-2"
KEYWORDS="~test"
+DEPEND="disabled? ( bar/foo )"
END
cd ..
mkdir -p installed/cat-one/pkg-one-1 || exit 1
+echo foo/bar >installed/world
+
for i in SLOT EAPI; do
echo "0" >installed/cat-one/pkg-one-1/${i}
done
diff --git a/ruby/dep_spec.cc b/ruby/dep_spec.cc
index 2e2e0a1..ef6c4b4 100644
--- a/ruby/dep_spec.cc
+++ b/ruby/dep_spec.cc
@@ -28,9 +28,13 @@
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/options.hh>
+#include <paludis/util/save.hh>
+#include <paludis/util/member_iterator-impl.hh>
#include <list>
#include <ruby.h>
+#include "nice_names-nn.hh"
+
using namespace paludis;
using namespace paludis::ruby;
@@ -264,6 +268,137 @@ namespace
return this;
}
+ template <typename H_>
+ struct ValueToTree :
+ ConstVisitor<WrappedSpecVisitorTypes>
+ {
+ tr1::shared_ptr<typename H_::ConstItem> result;
+ tr1::function<void (const tr1::shared_ptr<ConstAcceptInterface<H_> > &)> adder;
+
+ ValueToTree(VALUE val) :
+ adder(tr1::bind(&ValueToTree<H_>::set_result, this, tr1::placeholders::_1))
+ {
+ tr1::shared_ptr<WrappedSpecBase> * p;
+ Data_Get_Struct(val, tr1::shared_ptr<WrappedSpecBase>, p);
+ (*p)->accept(*this);
+ }
+
+ void set_result(const tr1::shared_ptr<ConstAcceptInterface<H_> > & res)
+ {
+ result = res;
+ }
+
+ template <typename T_>
+ void do_visit_sequence(const WrappedSpec<T_> & item, tr1::true_type)
+ {
+ using namespace tr1::placeholders;
+
+ tr1::shared_ptr<ConstTreeSequence<H_, T_> > a(
+ new ConstTreeSequence<H_, T_>(
+ tr1::static_pointer_cast<T_>(item.spec()->clone())));
+ adder(a);
+
+ Save<tr1::function<void (const tr1::shared_ptr<ConstAcceptInterface<H_> > &)> > s(
+ &adder, tr1::bind(&ConstTreeSequence<H_, T_>::add, a, _1));
+ std::for_each(indirect_iterator(second_iterator(item.children()->begin())),
+ indirect_iterator(second_iterator(item.children()->end())),
+ accept_visitor(*this));
+ }
+
+ template <typename T_>
+ void do_visit_sequence(const WrappedSpec<T_> &, tr1::false_type)
+ {
+ rb_raise(rb_eTypeError, "Item of type %s is not allowed in hierarchy of type %s", NiceNames<T_>::name, NiceNames<H_>::name);
+ }
+
+ template <typename T_>
+ void do_visit_sequence(const WrappedSpec<T_> & s)
+ {
+ do_visit_sequence(s, tr1::is_convertible<ConstVisitor<H_> *, Visits<const ConstTreeSequence<H_, T_> > *>());
+ }
+
+ virtual void visit(const WrappedSpec<AllDepSpec> & s)
+ {
+ do_visit_sequence(s);
+ }
+
+ virtual void visit(const WrappedSpec<AnyDepSpec> & s)
+ {
+ do_visit_sequence(s);
+ }
+
+ virtual void visit(const WrappedSpec<UseDepSpec> & s)
+ {
+ do_visit_sequence(s);
+ }
+
+ template <typename T_>
+ void do_visit_leaf(const WrappedSpec<T_> & item, tr1::true_type)
+ {
+ tr1::shared_ptr<TreeLeaf<H_, T_> > a(
+ new TreeLeaf<H_, T_>(
+ tr1::static_pointer_cast<T_>(item.spec()->clone())));
+ adder(a);
+ }
+
+ template <typename T_>
+ void do_visit_leaf(const WrappedSpec<T_> &, tr1::false_type)
+ {
+ rb_raise(rb_eTypeError, "Item of type %s is not allowed in hierarchy of type %s", NiceNames<T_>::name, NiceNames<H_>::name);
+ }
+
+ template <typename T_>
+ void do_visit_leaf(const WrappedSpec<T_> & s)
+ {
+ do_visit_leaf(s, tr1::is_convertible<ConstVisitor<H_> *, Visits<const TreeLeaf<H_, T_> > *>());
+ }
+
+ virtual void visit(const WrappedSpec<PlainTextDepSpec> & s)
+ {
+ do_visit_leaf(s);
+ }
+
+ virtual void visit(const WrappedSpec<SimpleURIDepSpec> & s)
+ {
+ do_visit_leaf(s);
+ }
+
+ virtual void visit(const WrappedSpec<FetchableURIDepSpec> & s)
+ {
+ do_visit_leaf(s);
+ }
+
+ virtual void visit(const WrappedSpec<LicenseDepSpec> & s)
+ {
+ do_visit_leaf(s);
+ }
+
+ virtual void visit(const WrappedSpec<PackageDepSpec> & s)
+ {
+ do_visit_leaf(s);
+ }
+
+ virtual void visit(const WrappedSpec<BlockDepSpec> & s)
+ {
+ do_visit_leaf(s);
+ }
+
+ virtual void visit(const WrappedSpec<URILabelsDepSpec> & s)
+ {
+ do_visit_leaf(s);
+ }
+
+ virtual void visit(const WrappedSpec<DependencyLabelsDepSpec> & s)
+ {
+ do_visit_leaf(s);
+ }
+
+ virtual void visit(const WrappedSpec<NamedSetDepSpec> & s)
+ {
+ do_visit_leaf(s);
+ }
+ };
+
VALUE
dep_spec_init_0(VALUE self)
{
@@ -1035,6 +1170,21 @@ paludis::ruby::value_to_dep_spec(VALUE v)
}
}
+template <typename H_>
+tr1::shared_ptr<const typename H_::ConstItem>
+paludis::ruby::value_to_dep_tree(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_dep_spec))
+ {
+ ValueToTree<H_> vtt(v);
+ return vtt.result;
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into DepSpec", rb_obj_classname(v));
+ }
+}
+
VALUE
paludis::ruby::package_dep_spec_to_value(const tr1::shared_ptr<const PackageDepSpec> & p)
{
@@ -1082,6 +1232,8 @@ template VALUE dep_tree_to_value <RestrictSpecTree> (const tr1::shared_ptr<const
template VALUE dep_tree_to_value <ProvideSpecTree> (const tr1::shared_ptr<const ProvideSpecTree::ConstItem> &);
template VALUE dep_tree_to_value <LicenseSpecTree> (const tr1::shared_ptr<const LicenseSpecTree::ConstItem> &);
+template tr1::shared_ptr<const SetSpecTree::ConstItem> value_to_dep_tree <SetSpecTree> (VALUE);
+
RegisterRubyClass::Register paludis_ruby_register_dep_spec PALUDIS_ATTRIBUTE((used))
(&do_register_dep_spec);
diff --git a/ruby/nice_names.nn b/ruby/nice_names.nn
new file mode 100644
index 0000000..4cbd738
--- /dev/null
+++ b/ruby/nice_names.nn
@@ -0,0 +1,44 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et ft=sh :
+
+include_hh << END
+#include <paludis/dep_spec-fwd.hh>
+#include <paludis/dep_tree-fwd.hh>
+END
+
+include_cc << END
+#include "nice_names-nn.hh"
+END
+
+use_namespace "paludis"
+
+make_nn_NiceNames() {
+ namespace "paludis::ruby"
+
+ # paludis/dep_spec-fwd.hh
+ name "DepSpec"
+ name "PackageDepSpec"
+ name "PlainTextDepSpec"
+ name "LicenseDepSpec"
+ name "FetchableURIDepSpec"
+ name "SimpleURIDepSpec"
+ name "AllDepSpec"
+ name "AnyDepSpec"
+ name "UseDepSpec"
+ name "BlockDepSpec"
+ name "StringDepSpec"
+ name "NamedSetDepSpec"
+ name "URILabelsDepSpec"
+ name "DependencyLabelsDepSpec"
+
+ # paludis/dep_tree-fwd.hh
+ name "GenericSpecTree"
+ name "LicenseSpecTree"
+ name "FetchableURISpecTree"
+ name "SimpleURISpecTree"
+ name "FlattenableSpecTree"
+ name "ProvideSpecTree"
+ name "RestrictSpecTree"
+ name "DependencySpecTree"
+ name "SetSpecTree"
+}
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index 572df21..b19edc1 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -88,6 +88,7 @@ namespace paludis
VALUE qa_message_to_value(const QAMessage &);
#endif
template <typename T_> VALUE dep_tree_to_value(const tr1::shared_ptr<const typename T_::ConstItem> &);
+ template <typename T_> tr1::shared_ptr<const typename T_::ConstItem> value_to_dep_tree(VALUE);
VALUE package_dep_spec_to_value(const tr1::shared_ptr<const PackageDepSpec> &);
VALUE uri_label_to_value(const tr1::shared_ptr<const URILabel> &);
VALUE mask_to_value(tr1::shared_ptr<const Mask>);