aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-05-16 22:59:03 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-05-16 22:59:13 +0100
commit20b5964db49950e5651354e88e4f651c2a30cf09 (patch)
tree1c024d17445051291bd19ed8aa156ca62f4a0286
parent8f32a82ae30934f8077b646726e18807a52f8b49 (diff)
downloadpaludis-20b5964db49950e5651354e88e4f651c2a30cf09.tar.gz
paludis-20b5964db49950e5651354e88e4f651c2a30cf09.tar.xz
labels bindings for ruby
-rw-r--r--ruby/Makefile.am1
-rw-r--r--ruby/dep_label.cc374
-rw-r--r--ruby/dep_label_TEST.rb34
-rw-r--r--ruby/dep_spec.cc53
-rw-r--r--ruby/dep_spec_TEST.rb20
-rwxr-xr-xruby/dep_spec_TEST_setup.sh2
-rw-r--r--ruby/metadata_key.cc34
-rw-r--r--ruby/paludis_ruby.hh6
8 files changed, 520 insertions, 4 deletions
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 039a73a..48d7872 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -21,6 +21,7 @@ IF_RUBY_TESTS = \
action_TEST.rb \
choice_TEST.rb \
contents_TEST.rb \
+ dep_label_TEST.rb \
dep_list_TEST.rb \
dep_spec_TEST.rb \
dep_tag_TEST.rb \
diff --git a/ruby/dep_label.cc b/ruby/dep_label.cc
index f4dad0e..f98db88 100644
--- a/ruby/dep_label.cc
+++ b/ruby/dep_label.cc
@@ -44,6 +44,28 @@ namespace
static VALUE c_uri_local_mirrors_only_label;
static VALUE c_uri_manual_only_label;
+ static VALUE c_dependency_label;
+ static VALUE c_dependency_system_label;
+ static VALUE c_dependency_type_label;
+ static VALUE c_dependency_suggest_label;
+ static VALUE c_dependency_abis_label;
+ static VALUE c_dependency_host_label;
+ static VALUE c_dependency_target_label;
+ static VALUE c_dependency_build_label;
+ static VALUE c_dependency_run_label;
+ static VALUE c_dependency_post_label;
+ static VALUE c_dependency_compile_label;
+ static VALUE c_dependency_install_label;
+ static VALUE c_dependency_suggested_label;
+ static VALUE c_dependency_recommended_label;
+ static VALUE c_dependency_required_label;
+ static VALUE c_dependency_any_label;
+ static VALUE c_dependency_mine_label;
+ static VALUE c_dependency_primary_label;
+ static VALUE c_dependency_abi_label;
+
+ static VALUE c_active_dependency_labels;
+
struct URILabelToValue
{
VALUE value;
@@ -91,6 +113,155 @@ namespace
}
};
+ struct RealDependencyLabelToValue
+ {
+ VALUE value;
+ std::tr1::shared_ptr<const DependencyLabel> mm;
+
+ RealDependencyLabelToValue(const std::tr1::shared_ptr<const DependencyLabel> & _m) :
+ mm(_m)
+ {
+ value = Qnil;
+ }
+
+ void visit(const DependencyHostLabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_host_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+
+ void visit(const DependencyTargetLabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_target_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+
+ void visit(const DependencyBuildLabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_build_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+
+ void visit(const DependencyRunLabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_run_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+
+ void visit(const DependencyPostLabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_post_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+
+ void visit(const DependencyCompileLabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_compile_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+
+ void visit(const DependencyInstallLabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_install_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+
+ void visit(const DependencySuggestedLabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_suggested_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+
+ void visit(const DependencyRecommendedLabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_recommended_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+
+ void visit(const DependencyRequiredLabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_required_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+
+ void visit(const DependencyAnyLabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_any_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+
+ void visit(const DependencyMineLabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_mine_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+
+ void visit(const DependencyPrimaryLabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_primary_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+
+ void visit(const DependencyABILabel &)
+ {
+ value = Data_Wrap_Struct(c_dependency_abi_label, 0,
+ &Common<std::tr1::shared_ptr<const DependencyLabel> >::free,
+ new std::tr1::shared_ptr<const DependencyLabel>(mm));
+ }
+ };
+
+ struct DependencyLabelToValue
+ {
+ VALUE value;
+ std::tr1::shared_ptr<const DependencyLabel> mm;
+
+ DependencyLabelToValue(const std::tr1::shared_ptr<const DependencyLabel> & _m) :
+ mm(_m)
+ {
+ }
+
+ void visit(const DependencySystemLabel & label)
+ {
+ RealDependencyLabelToValue v(mm);
+ label.accept(v);
+ value = v.value;
+ }
+
+ void visit(const DependencyTypeLabel & label)
+ {
+ RealDependencyLabelToValue v(mm);
+ label.accept(v);
+ value = v.value;
+ }
+
+ void visit(const DependencySuggestLabel & label)
+ {
+ RealDependencyLabelToValue v(mm);
+ label.accept(v);
+ value = v.value;
+ }
+
+ void visit(const DependencyABIsLabel & label)
+ {
+ RealDependencyLabelToValue v(mm);
+ label.accept(v);
+ value = v.value;
+ }
+ };
+
/*
* Document-method: text
*
@@ -115,6 +286,87 @@ namespace
return rb_str_new2((*ptr)->text().c_str());
}
+ /*
+ * Document-method: text
+ *
+ * call-seq:
+ * text -> String
+ *
+ * Our text.
+ */
+ /*
+ * Document-method: to_s
+ *
+ * call-seq:
+ * to_s -> String
+ *
+ * Fetch a string representation of ourself.
+ */
+ VALUE
+ dependency_label_text(VALUE self)
+ {
+ std::tr1::shared_ptr<const DependencyLabel> * ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<const DependencyLabel>, ptr);
+ return rb_str_new2((*ptr)->text().c_str());
+ }
+
+ VALUE
+ empty_init(int, VALUE *, VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ active_dependency_labels_new(int argc, VALUE *argv, VALUE self)
+ {
+ std::tr1::shared_ptr<ActiveDependencyLabels> * ptr(0);
+ try
+ {
+ if (1 == argc && rb_obj_is_kind_of(argv[0], c_active_dependency_labels))
+ {
+ ptr = new std::tr1::shared_ptr<ActiveDependencyLabels>(
+ new ActiveDependencyLabels(*value_to_active_dependency_labels(argv[0])));
+ }
+ else if (1 == argc && rb_obj_is_kind_of(argv[0], *dependency_labels_dep_spec_value_ptr()))
+ {
+ ptr = new std::tr1::shared_ptr<ActiveDependencyLabels>(
+ new ActiveDependencyLabels(*value_to_dependency_labels_dep_spec(argv[0])));
+ }
+ else if (1 == argc && rb_obj_is_kind_of(argv[0], rb_cArray))
+ {
+ std::tr1::shared_ptr<DependencyLabelSequence> seq(new DependencyLabelSequence);
+
+ for (int i(0) ; i < RARRAY_LEN(argv[0]) ; ++i)
+ {
+ VALUE entry(rb_ary_entry(argv[0], i));
+ seq->push_back(value_to_dependency_label(entry));
+ }
+
+ ptr = new std::tr1::shared_ptr<ActiveDependencyLabels>(new ActiveDependencyLabels(*seq));
+ }
+ else if (2 == argc && rb_obj_is_kind_of(argv[0], c_active_dependency_labels) &&
+ rb_obj_is_kind_of(argv[1], *dependency_labels_dep_spec_value_ptr()))
+ {
+ ptr = new std::tr1::shared_ptr<ActiveDependencyLabels>(
+ new ActiveDependencyLabels(*value_to_active_dependency_labels(argv[0]),
+ *value_to_dependency_labels_dep_spec(argv[1])));
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "ActiveDependencyLabels expects one or two arguments, but got %d",argc);
+ }
+
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<std::tr1::shared_ptr<ActiveDependencyLabels> >::free, ptr));
+ rb_obj_call_init(tdata, argc, argv);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
void do_register_dep_label()
{
/*
@@ -133,6 +385,69 @@ namespace
c_uri_listed_then_mirrors_label = rb_define_class_under(paludis_module(), "URIListedThenMirrorsLabel", c_uri_label);
c_uri_local_mirrors_only_label = rb_define_class_under(paludis_module(), "URILocalMirrorsOnlyLabel", c_uri_label);
c_uri_manual_only_label = rb_define_class_under(paludis_module(), "URIManualOnlyLabel", c_uri_label);
+
+ c_dependency_label = rb_define_class_under(paludis_module(), "DependencyLabel", rb_cObject);
+ rb_funcall(c_dependency_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_dependency_label, "text", RUBY_FUNC_CAST(&dependency_label_text), 0);
+ rb_define_method(c_dependency_label, "to_s", RUBY_FUNC_CAST(&dependency_label_text), 0);
+
+ c_dependency_system_label = rb_define_class_under(paludis_module(), "DependencySystemLabel", c_dependency_label);
+ rb_funcall(c_dependency_system_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_type_label = rb_define_class_under(paludis_module(), "DependencyTypeLabel", c_dependency_label);
+ rb_funcall(c_dependency_type_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_suggest_label = rb_define_class_under(paludis_module(), "DependencySuggestLabel", c_dependency_label);
+ rb_funcall(c_dependency_suggest_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_abis_label = rb_define_class_under(paludis_module(), "DependencyABIsLabel", c_dependency_label);
+ rb_funcall(c_dependency_abis_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_host_label = rb_define_class_under(paludis_module(), "DependencyHostLabel", c_dependency_system_label);
+ rb_funcall(c_dependency_host_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_target_label = rb_define_class_under(paludis_module(), "DependencyTargetLabel", c_dependency_system_label);
+ rb_funcall(c_dependency_target_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_build_label = rb_define_class_under(paludis_module(), "DependencyBuildLabel", c_dependency_type_label);
+ rb_funcall(c_dependency_build_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_run_label = rb_define_class_under(paludis_module(), "DependencyRunLabel", c_dependency_type_label);
+ rb_funcall(c_dependency_run_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_post_label = rb_define_class_under(paludis_module(), "DependencyPostLabel", c_dependency_type_label);
+ rb_funcall(c_dependency_post_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_compile_label = rb_define_class_under(paludis_module(), "DependencyCompileLabel", c_dependency_type_label);
+ rb_funcall(c_dependency_compile_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_install_label = rb_define_class_under(paludis_module(), "DependencyInstallLabel", c_dependency_type_label);
+ rb_funcall(c_dependency_install_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_suggested_label = rb_define_class_under(paludis_module(), "DependencySuggestedLabel", c_dependency_suggest_label);
+ rb_funcall(c_dependency_suggested_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_recommended_label = rb_define_class_under(paludis_module(), "DependencyRecommendedLabel", c_dependency_suggest_label);
+ rb_funcall(c_dependency_recommended_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_required_label = rb_define_class_under(paludis_module(), "DependencyRequiredLabel", c_dependency_suggest_label);
+ rb_funcall(c_dependency_required_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_any_label = rb_define_class_under(paludis_module(), "DependencyAnyLabel", c_dependency_abis_label);
+ rb_funcall(c_dependency_any_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_mine_label = rb_define_class_under(paludis_module(), "DependencyMineLabel", c_dependency_abis_label);
+ rb_funcall(c_dependency_mine_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_primary_label = rb_define_class_under(paludis_module(), "DependencyPrimaryLabel", c_dependency_abis_label);
+ rb_funcall(c_dependency_primary_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_dependency_abi_label = rb_define_class_under(paludis_module(), "DependencyAbiLabel", c_dependency_abis_label);
+ rb_funcall(c_dependency_abi_label, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+
+ c_active_dependency_labels = rb_define_class_under(paludis_module(), "ActiveDependencyLabels", rb_cObject);
+ rb_define_singleton_method(c_active_dependency_labels, "new", RUBY_FUNC_CAST(&active_dependency_labels_new), -1);
+ rb_define_method(c_active_dependency_labels, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
}
}
@@ -151,6 +466,65 @@ paludis::ruby::uri_label_to_value(const std::tr1::shared_ptr<const URILabel> & m
}
}
+VALUE
+paludis::ruby::dependency_label_to_value(const std::tr1::shared_ptr<const DependencyLabel> & m)
+{
+ try
+ {
+ DependencyLabelToValue v(m);
+ m->accept(v);
+ return v.value;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+}
+
+std::tr1::shared_ptr<ActiveDependencyLabels>
+paludis::ruby::value_to_active_dependency_labels(VALUE v)
+{
+ try
+ {
+ if (rb_obj_is_kind_of(v, c_active_dependency_labels))
+ {
+ std::tr1::shared_ptr<ActiveDependencyLabels> * ptr;
+ Data_Get_Struct(v, std::tr1::shared_ptr<ActiveDependencyLabels>, ptr);
+ return *ptr;
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into ActiveDependencyLabels", rb_obj_classname(v));
+ }
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+}
+
+std::tr1::shared_ptr<const DependencyLabel>
+paludis::ruby::value_to_dependency_label(VALUE v)
+{
+ try
+ {
+ if (rb_obj_is_kind_of(v, c_dependency_label))
+ {
+ std::tr1::shared_ptr<const DependencyLabel> * ptr;
+ Data_Get_Struct(v, std::tr1::shared_ptr<const DependencyLabel>, ptr);
+ return *ptr;
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into DependencyLabel", rb_obj_classname(v));
+ }
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+}
+
RegisterRubyClass::Register paludis_ruby_register_dep_label PALUDIS_ATTRIBUTE((used))
(&do_register_dep_label);
diff --git a/ruby/dep_label_TEST.rb b/ruby/dep_label_TEST.rb
new file mode 100644
index 0000000..f2a4c9f
--- /dev/null
+++ b/ruby/dep_label_TEST.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=80 :
+#
+# Copyright (c) 2006, 2007, 2008, 2009 Ciaran McCreesh
+# Copyright (c) 2007 Richard Brown
+#
+# 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
+#
+
+require 'test/unit'
+require 'Paludis'
+
+module Paludis
+ class TestCase_ActiveDependencyLabels < Test::Unit::TestCase
+ def test_create
+ a = ActiveDependencyLabels.new(DependencyLabelsDepSpec.new)
+ a = ActiveDependencyLabels.new(a)
+ a = ActiveDependencyLabels.new(a, DependencyLabelsDepSpec.new)
+ a = ActiveDependencyLabels.new([])
+ end
+ end
+end
+
diff --git a/ruby/dep_spec.cc b/ruby/dep_spec.cc
index fa2f868..382bf18 100644
--- a/ruby/dep_spec.cc
+++ b/ruby/dep_spec.cc
@@ -435,6 +435,33 @@ namespace
}
VALUE
+ dependency_labels_dep_spec_labels(VALUE self)
+ {
+ std::tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<WrappedSpecBase>, ptr);
+ std::tr1::shared_ptr<const DependencyLabelsDepSpec> real_ptr(std::tr1::static_pointer_cast<const WrappedSpec<DependencyLabelsDepSpec> >(*ptr)->spec());
+
+ if (rb_block_given_p())
+ {
+ for (DependencyLabelsDepSpec::ConstIterator it(real_ptr->begin()),
+ it_end(real_ptr->end()); it_end != it; ++it)
+ rb_yield(dependency_label_to_value(*it));
+
+ return Qnil;
+ }
+ else
+ {
+ VALUE result(rb_ary_new());
+
+ for (DependencyLabelsDepSpec::ConstIterator it(real_ptr->begin()),
+ it_end(real_ptr->end()); it_end != it; ++it)
+ rb_ary_push(result, dependency_label_to_value(*it));
+
+ return result;
+ }
+ }
+
+ VALUE
block_dep_spec_new(VALUE self, VALUE spec)
{
std::tr1::shared_ptr<const WrappedSpecBase> * ptr(0);
@@ -471,14 +498,14 @@ namespace
struct DepSpecThings
{
static VALUE
- dep_spec_new_0(VALUE self, VALUE s)
+ dep_spec_new_0(VALUE self)
{
std::tr1::shared_ptr<const WrappedSpecBase> * ptr(0);
try
{
ptr = new std::tr1::shared_ptr<const WrappedSpecBase>(new WrappedSpec<A_>(make_shared_ptr(new A_)));
VALUE tdata(Data_Wrap_Struct(self, 0, &Common<std::tr1::shared_ptr<const WrappedSpecBase> >::free, ptr));
- rb_obj_call_init(tdata, 1, &s);
+ rb_obj_call_init(tdata, 0, &self);
return tdata;
}
catch (const std::exception & e)
@@ -1141,6 +1168,7 @@ namespace
rb_define_method(c_dependency_labels_dep_spec, "initialize", RUBY_FUNC_CAST(&dep_spec_init_0), 0);
VALUE (* dependency_labels_dep_spec_to_s) (VALUE) = &dep_spec_to_s<DependencyLabelsDepSpec>;
rb_define_method(c_dependency_labels_dep_spec, "to_s", RUBY_FUNC_CAST(dependency_labels_dep_spec_to_s), 0);
+ rb_define_method(c_dependency_labels_dep_spec, "labels", RUBY_FUNC_CAST(&dependency_labels_dep_spec_labels), 0);
/*
* Document-class: Paludis::URILabelsDepSpec
@@ -1242,6 +1270,21 @@ paludis::ruby::value_to_package_dep_spec(VALUE v)
}
}
+std::tr1::shared_ptr<const DependencyLabelsDepSpec>
+paludis::ruby::value_to_dependency_labels_dep_spec(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_dependency_labels_dep_spec))
+ {
+ std::tr1::shared_ptr<WrappedSpecBase> * v_ptr;
+ Data_Get_Struct(v, std::tr1::shared_ptr<WrappedSpecBase>, v_ptr);
+ return std::tr1::static_pointer_cast<const WrappedSpec<DependencyLabelsDepSpec> >(*v_ptr)->spec();
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into DependencyLabelsDepSpec", rb_obj_classname(v));
+ }
+}
+
std::tr1::shared_ptr<const DepSpec>
paludis::ruby::value_to_dep_spec(VALUE v)
{
@@ -1302,6 +1345,12 @@ paludis::ruby::dep_tree_to_value(const std::tr1::shared_ptr<const T_> & m)
}
}
+VALUE *
+paludis::ruby::dependency_labels_dep_spec_value_ptr()
+{
+ return &c_dependency_labels_dep_spec;
+}
+
template VALUE paludis::ruby::dep_tree_to_value<SetSpecTree> (const std::tr1::shared_ptr<const SetSpecTree> &);
template VALUE paludis::ruby::dep_tree_to_value<DependencySpecTree> (const std::tr1::shared_ptr<const DependencySpecTree> &);
template VALUE paludis::ruby::dep_tree_to_value<FetchableURISpecTree> (const std::tr1::shared_ptr<const FetchableURISpecTree> &);
diff --git a/ruby/dep_spec_TEST.rb b/ruby/dep_spec_TEST.rb
index 18ee9a8..314f2a1 100644
--- a/ruby/dep_spec_TEST.rb
+++ b/ruby/dep_spec_TEST.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# vim: set sw=4 sts=4 et tw=80 :
#
-# Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
+# Copyright (c) 2006, 2007, 2008, 2009 Ciaran McCreesh
# Copyright (c) 2007 Richard Brown
#
# This file is part of the Paludis package manager. Paludis is free software;
@@ -402,5 +402,23 @@ module Paludis
assert_equal "manual", specs.to_a[5].labels[0].text
end
end
+
+ class TestCase_DependencyLabels < Test::Unit::TestCase
+ def env
+ @env or @env = EnvironmentFactory.instance.create("")
+ end
+
+ def spec_key
+ env[Selection::RequireExactlyOne.new(Generator::Package.new("bar/foo"))].last.build_dependencies_key
+ end
+
+ def test_initial_labels
+ assert_kind_of Array, spec_key.initial_labels
+ assert_kind_of DependencyBuildLabel, spec_key.initial_labels[0]
+ assert_equal "DEPEND", spec_key.initial_labels[0].text
+ assert_equal "DEPEND", spec_key.initial_labels[0].to_s
+ ActiveDependencyLabels.new spec_key.initial_labels
+ end
+ end
end
diff --git a/ruby/dep_spec_TEST_setup.sh b/ruby/dep_spec_TEST_setup.sh
index 61c9d56..a05ab5f 100755
--- a/ruby/dep_spec_TEST_setup.sh
+++ b/ruby/dep_spec_TEST_setup.sh
@@ -55,7 +55,7 @@ SLOT="0"
MYOPTIONS=""
LICENCES="GPL-2"
PLATFORMS="test"
-DEPENDENCIES=""
+DEPENDENCIES="build: one/two"
END
cat <<"END" > bar/bar/bar-1.0.ebuild || exit 1
diff --git a/ruby/metadata_key.cc b/ruby/metadata_key.cc
index fe5d1c3..700e479 100644
--- a/ruby/metadata_key.cc
+++ b/ruby/metadata_key.cc
@@ -24,6 +24,8 @@
#include <paludis/metadata_key.hh>
#include <paludis/mask.hh>
#include <paludis/util/set.hh>
+#include <paludis/util/sequence.hh>
+#include <paludis/util/simple_visitor_cast.hh>
#include <ruby.h>
using namespace paludis;
@@ -550,6 +552,37 @@ namespace
/*
* call-seq:
+ * initial_labels -> Array of DependencyLabel
+ *
+ * Return the initial labels to use when deciding the behaviour of
+ * individual items in the heirarchy.
+ */
+ VALUE
+ metadata_dependency_spec_tree_key_initial_labels(VALUE self)
+ {
+ try
+ {
+ std::tr1::shared_ptr<const MetadataKey> * self_ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<const MetadataKey>, self_ptr);
+ const MetadataSpecTreeKey<DependencySpecTree> * real_self(simple_visitor_cast<
+ const MetadataSpecTreeKey<DependencySpecTree> >(**self_ptr));
+
+ VALUE result(rb_ary_new());
+
+ for (DependencyLabelSequence::ConstIterator it(real_self->initial_labels()->begin()),
+ it_end(real_self->initial_labels()->end()); it_end != it; ++it)
+ rb_ary_push(result, dependency_label_to_value(*it));
+
+ return result;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
* mask_file -> String
*
* Filename where the key was defined.
@@ -776,6 +809,7 @@ namespace
*/
c_metadata_dependency_spec_tree_key = rb_define_class_under(paludis_module(), "MetadataDependencySpecTreeKey", c_metadata_key);
rb_define_method(c_metadata_dependency_spec_tree_key, "value", RUBY_FUNC_CAST((&SpecTreeValue<DependencySpecTree>::fetch)), 0);
+ rb_define_method(c_metadata_dependency_spec_tree_key, "initial_labels", RUBY_FUNC_CAST(&metadata_dependency_spec_tree_key_initial_labels), 0);
/*
* Document-class: Paludis::MetadataFetchableURISpecTreeKey
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index bed6533..58b04f5 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -40,6 +40,7 @@
#include <paludis/generator.hh>
#include <paludis/filtered_generator.hh>
#include <paludis/choice-fwd.hh>
+#include <paludis/dep_label-fwd.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/hashes.hh>
@@ -101,6 +102,7 @@ namespace paludis
template <typename T_> std::tr1::shared_ptr<const T_> value_to_dep_tree(VALUE);
VALUE package_dep_spec_to_value(const std::tr1::shared_ptr<const PackageDepSpec> &);
VALUE uri_label_to_value(const std::tr1::shared_ptr<const URILabel> &);
+ VALUE dependency_label_to_value(const std::tr1::shared_ptr<const DependencyLabel> &);
VALUE mask_to_value(std::tr1::shared_ptr<const Mask>);
VALUE choices_to_value(const std::tr1::shared_ptr<const Choices> & c);
VALUE choice_to_value(const std::tr1::shared_ptr<const Choice> & c);
@@ -111,6 +113,7 @@ namespace paludis
VersionSpec value_to_version_spec(VALUE v);
std::tr1::shared_ptr<const PackageID> value_to_package_id(VALUE);
std::tr1::shared_ptr<const PackageDepSpec> value_to_package_dep_spec(VALUE v);
+ std::tr1::shared_ptr<const DependencyLabelsDepSpec> value_to_dependency_labels_dep_spec(VALUE v);
std::tr1::shared_ptr<const DepSpec> value_to_dep_spec(VALUE v);
std::tr1::shared_ptr<const DepTag> value_to_dep_tag(VALUE v);
QualifiedPackageName value_to_qualified_package_name(VALUE v);
@@ -123,8 +126,10 @@ namespace paludis
std::tr1::shared_ptr<const Choices> value_to_choices(VALUE v);
std::tr1::shared_ptr<const Choice> value_to_choice(VALUE v);
std::tr1::shared_ptr<const ChoiceValue> value_to_choice_value(VALUE v);
+ std::tr1::shared_ptr<const DependencyLabel> value_to_dependency_label(VALUE v);
MatchPackageOptions value_to_match_package_options(VALUE v);
bool value_to_bool(VALUE v);
+ std::tr1::shared_ptr<ActiveDependencyLabels> value_to_active_dependency_labels(VALUE v);
Filter value_to_filter(VALUE v);
Selection value_to_selection(VALUE v);
@@ -139,6 +144,7 @@ namespace paludis
VALUE * pretend_action_value_ptr();
VALUE * installed_action_value_ptr();
VALUE * pretend_fetch_action_value_ptr();
+ VALUE * dependency_labels_dep_spec_value_ptr();
#ifdef ENABLE_RUBY_QA
QACheckProperties value_to_qa_check_properties(VALUE);