aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-23 11:50:45 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-23 11:50:45 +0000
commitbe73d69521951b5efe2852d1313d05f3054facab (patch)
treedada81f9a1ae5bac575cc3d5b4a0cdd343579b49
parent71eb5a51c9ab9d8b38eb2f6a1518719e831c798a (diff)
downloadpaludis-be73d69521951b5efe2852d1313d05f3054facab.tar.gz
paludis-be73d69521951b5efe2852d1313d05f3054facab.tar.xz
More Ruby interface
-rw-r--r--ruby/Makefile.am67
-rw-r--r--ruby/default_environment.cc65
-rwxr-xr-xruby/default_environment_TEST_cleanup.sh12
-rwxr-xr-xruby/default_environment_TEST_setup.sh26
-rw-r--r--ruby/name.cc139
-rw-r--r--ruby/name_TEST.rb78
-rw-r--r--ruby/package_database_entry.cc80
-rw-r--r--ruby/package_database_entry_TEST.rb39
-rw-r--r--ruby/paludis_ruby.cc17
-rw-r--r--ruby/paludis_ruby.hh44
-rw-r--r--ruby/paludis_ruby_TEST.rb17
-rw-r--r--ruby/version_spec.cc72
-rwxr-xr-xtest/run_test.sh31
13 files changed, 620 insertions, 67 deletions
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 28b2082..a30b044 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -11,12 +11,25 @@ DEFS= \
-DLIBEXECDIR=\"$(libexecdir)\" \
-DLIBDIR=\"$(libdir)\"
-CLEANFILES = *~ gmon.out *.gcov *.gcno *.gcda *.o *.so
+CLEANFILES = *~ gmon.out *.gcov *.gcno *.gcda *.o *.so .libs/*.so
MAINTAINERCLEANFILES = Makefile.in
-IF_RUBY_TESTS = paludis_ruby_TEST.rb name_TEST.rb
-IF_RUBY_SOURCES = paludis_ruby.cc paludis_ruby.hh name.cc
-EXTRA_DIST = $(IF_RUBY_TESTS) $(IF_RUBY_SOURCES)
+IF_RUBY_TESTS = \
+ paludis_ruby_TEST.rb \
+ name_TEST.rb \
+ default_environment_TEST.rb \
+ package_database_entry_TEST.rb \
+ version_spec_TEST.rb
+
+IF_RUBY_SOURCES = \
+ paludis_ruby.cc paludis_ruby.hh \
+ name.cc \
+ default_environment.cc \
+ package_database_entry.cc \
+ version_spec.cc
+
+EXTRA_DIST = $(IF_RUBY_TESTS) $(IF_RUBY_SOURCES) \
+ default_environment_TEST_setup.sh default_environment_TEST_cleanup.sh
TESTS_ENVIRONMENT = env \
PALUDIS_NO_GLOBAL_HOOKS="yes" \
@@ -24,14 +37,22 @@ TESTS_ENVIRONMENT = env \
PALUDIS_EBUILD_DIR="`$(top_srcdir)/ebuild/utils/canonicalise $(top_srcdir)/ebuild/`" \
PALUDIS_EBUILD_DIR_FALLBACK="`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/ebuild/`" \
PALUDIS_REPOSITORY_SO_DIR="`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/repositories`" \
- LD_LIBRARY_PATH="`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/.libs`" \
- ruby -I ./
+ SYSCONFDIR="$(sysconfdir)" \
+ LD_LIBRARY_PATH="`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/.libs`:`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/repositories/nothing/.libs`:`$(top_srcdir)/ebuild/utils/canonicalise $(top_builddir)/paludis/repositories/virtuals/.libs`" \
+ bash $(top_srcdir)/test/run_test.sh "ruby -I ./.libs/"
if ENABLE_RUBY
+OUR_OBJECTS = \
+ name.o \
+ default_environment.o \
+ paludis_ruby.o \
+ package_database_entry.o \
+ version_spec.o
+
TESTS = $(IF_RUBY_TESTS)
-OUR_OBJECTS = name.o paludis_ruby.o
noinst_DATA = $(OUR_OBJECTS)
+check_DATA = .libs/Paludis.so
rubylibdir = $(DESTDIR)/@RUBY_SITEARCHDIR@
rubylib_DATA = Paludis.so
@@ -45,14 +66,38 @@ paludis_ruby.o : paludis_ruby.cc paludis_ruby.hh
name.o : name.cc paludis_ruby.hh
$(OUR_CXXCOMPILE) -o $@ $(srcdir)/name.cc
+default_environment.o : default_environment.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/default_environment.cc
+
+package_database_entry.o : package_database_entry.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/package_database_entry.cc
+
+version_spec.o : version_spec.cc paludis_ruby.hh
+ $(OUR_CXXCOMPILE) -o $@ $(srcdir)/version_spec.cc
+
+.libs/Paludis.so : $(OUR_OBJECTS)
+ mkdir -p .libs
+ $(CXX) -fPIC -shared $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) \
+ -I@RUBY_SITEARCHDIR@ -l@RUBY_SONAME@ \
+ -o $@ \
+ $(top_builddir)/paludis/.libs/libpaludis.so \
+ $(top_builddir)/paludis/repositories/nothing/.libs/libpaludisnothingrepository.so \
+ $(top_builddir)/paludis/repositories/virtuals/.libs/libpaludisvirtualsrepository.so \
+ $^
+
Paludis.so : $(OUR_OBJECTS)
+ mkdir -p .libs
$(CXX) -fPIC -shared $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) \
- $(AM_LDFLAGS) $(LDFLAGS) -I@RUBY_SITEARCHDIR@ -l@RUBY_SONAME@ \
- -L$(top_builddir)/paludis/.libs -lpaludis -o $@ $^
+ $(AM_LDFLAGS) $(LDFLAGS) \
+ -I@RUBY_SITEARCHDIR@ -l@RUBY_SONAME@ \
+ -L$(top_builddir)/paludis/util/.libs/ -lpaludisutil \
+ -L$(top_builddir)/paludis/.libs/ -lpaludis \
+ -o $@ \
+ $^
-clean-local :
- rm -fr Paludis.so .checkimage || true
endif
diff --git a/ruby/default_environment.cc b/ruby/default_environment.cc
new file mode 100644
index 0000000..463c39c
--- /dev/null
+++ b/ruby/default_environment.cc
@@ -0,0 +1,65 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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
+ */
+
+#include <paludis_ruby.hh>
+#include <paludis/default_environment.hh>
+#include <paludis/util/compare.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_default_environment;
+
+ VALUE
+ default_environment_query_use(int argc, VALUE * argv, VALUE)
+ {
+ try
+ {
+ if (1 == argc)
+ {
+ UseFlagName * use_flag_ptr;
+ Data_Get_Struct(argv[0], UseFlagName, use_flag_ptr);
+ return DefaultEnvironment::get_instance()->query_use(*use_flag_ptr, 0) ? Qtrue : Qfalse;
+ }
+ else
+ rb_raise(rb_eArgError, "DefaultEnvironment.query_use expects one or two arguments, but got %d", argc);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ void do_register_default_environment()
+ {
+ rb_require("singleton");
+
+ c_default_environment = rb_define_class("DefaultEnvironment", rb_cObject);
+ rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")), rb_intern("included"), 1, c_default_environment);
+ rb_define_method(c_default_environment, "query_use", RUBY_FUNC_CAST(&default_environment_query_use), -1);
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_default_environment PALUDIS_ATTRIBUTE((used)) (&do_register_default_environment);
+
diff --git a/ruby/default_environment_TEST_cleanup.sh b/ruby/default_environment_TEST_cleanup.sh
new file mode 100755
index 0000000..eab3f2d
--- /dev/null
+++ b/ruby/default_environment_TEST_cleanup.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d default_environment_TEST_dir ] ; then
+ rm -fr default_environment_TEST_dir
+else
+ true
+fi
+
+
+
+
diff --git a/ruby/default_environment_TEST_setup.sh b/ruby/default_environment_TEST_setup.sh
new file mode 100755
index 0000000..40201bf
--- /dev/null
+++ b/ruby/default_environment_TEST_setup.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir default_environment_TEST_dir || exit 1
+cd default_environment_TEST_dir || exit 1
+
+mkdir -p home/.paludis/repositories
+
+cat <<END > home/.paludis/repositories/nothing.conf
+format = nothing
+location = /var/empty
+name = nothing
+END
+
+cat <<END > home/.paludis/keywords.conf
+* test
+END
+
+cat <<END > home/.paludis/use.conf
+* enabled
+END
+
+cat <<END > home/.paludis/licenses.conf
+* *
+END
+
diff --git a/ruby/name.cc b/ruby/name.cc
index 928d5b1..1c39470 100644
--- a/ruby/name.cc
+++ b/ruby/name.cc
@@ -1,8 +1,24 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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
+ */
+
#include <paludis_ruby.hh>
#include <paludis/name.hh>
-#include <paludis/util/compare.hh>
#include <ruby.h>
using namespace paludis;
@@ -18,18 +34,12 @@ namespace
static VALUE c_class;
static VALUE c_class_except;
- static void
- name_part_error_free(void * ptr)
- {
- delete static_cast<std::string *>(ptr);
- }
-
static VALUE
name_part_error_new(VALUE the_class, VALUE value)
{
VALUE argv[1];
std::string * ptr(new std::string(STR2CSTR(value)));
- VALUE tdata(Data_Wrap_Struct(the_class, 0, &name_part_error_free, ptr));
+ VALUE tdata(Data_Wrap_Struct(the_class, 0, &Common<std::string>::free, ptr));
argv[0] = value;
rb_obj_call_init(tdata, 1, argv);
rb_call_super(1, &value);
@@ -42,12 +52,6 @@ namespace
return self;
}
- static void
- name_part_free(void * ptr)
- {
- delete static_cast<T_ *>(ptr);
- }
-
static VALUE
name_part_new(VALUE the_class, VALUE value)
{
@@ -56,7 +60,7 @@ namespace
try
{
ptr = new T_(std::string(STR2CSTR(value)));
- VALUE tdata(Data_Wrap_Struct(the_class, 0, &name_part_free, ptr));
+ VALUE tdata(Data_Wrap_Struct(the_class, 0, &Common<T_>::free, ptr));
argv[0] = value;
rb_obj_call_init(tdata, 1, argv);
return tdata;
@@ -74,25 +78,6 @@ namespace
}
static VALUE
- name_part_compare(VALUE left, VALUE right)
- {
- T_ * left_ptr, * right_ptr;
- Data_Get_Struct(left, T_, left_ptr);
- Data_Get_Struct(right, T_, right_ptr);
-
- return INT2FIX(compare(*left_ptr, *right_ptr));
- }
-
- static VALUE
- name_part_to_s(VALUE left)
- {
- T_ * left_ptr;
- Data_Get_Struct(left, T_, left_ptr);
-
- return rb_str_new2(left_ptr->data().c_str());
- }
-
- static VALUE
name_part_init(VALUE self, VALUE)
{
return self;
@@ -103,9 +88,9 @@ namespace
c_class = rb_define_class(name.c_str(), rb_cObject);
rb_define_singleton_method(c_class, "new", RUBY_FUNC_CAST(&name_part_new), 1);
rb_define_method(c_class, "initialize", RUBY_FUNC_CAST(&name_part_init), 1);
- rb_define_method(c_class, "<=>", RUBY_FUNC_CAST(&name_part_compare), 1);
+ rb_define_method(c_class, "<=>", RUBY_FUNC_CAST(&Common<T_>::compare), 1);
rb_include_module(c_class, rb_mComparable);
- rb_define_method(c_class, "to_s", RUBY_FUNC_CAST(&name_part_to_s), 0);
+ rb_define_method(c_class, "to_s", RUBY_FUNC_CAST(&Common<T_>::to_s), 0);
c_class_except = rb_define_class((name + "Error").c_str(), rb_eRuntimeError);
rb_define_singleton_method(c_class_except, "new", RUBY_FUNC_CAST(&name_part_error_new), 1);
@@ -116,6 +101,74 @@ namespace
template <typename T_, typename E_> VALUE NameWrapper<T_, E_>::c_class;
template <typename T_, typename E_> VALUE NameWrapper<T_, E_>::c_class_except;
+ static VALUE c_qualified_package_name;
+ static VALUE c_qualified_package_name_error;
+
+ VALUE
+ category_name_part_plus(VALUE left, VALUE right)
+ {
+ return rb_funcall(c_qualified_package_name, rb_intern("new"), 2, left, right);
+ }
+
+ VALUE
+ qualified_package_name_init(int, VALUE *, VALUE self)
+ {
+ return self;
+ }
+
+ VALUE
+ qualified_package_name_new(int argc, VALUE * argv, VALUE self)
+ {
+ QualifiedPackageName * ptr(0);
+ try
+ {
+ if (1 == argc)
+ ptr = new QualifiedPackageName(std::string(STR2CSTR(argv[0])));
+ else if (2 == argc)
+ {
+ CategoryNamePart * cat_ptr;
+ Data_Get_Struct(argv[0], CategoryNamePart, cat_ptr);
+ PackageNamePart * pkg_ptr;
+ Data_Get_Struct(argv[1], PackageNamePart, pkg_ptr);
+ ptr = new QualifiedPackageName(*cat_ptr, *pkg_ptr);
+ }
+ else
+ rb_raise(rb_eArgError, "QualifiedPackageName.new expects one or two arguments, but got %d", argc);
+
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<QualifiedPackageName>::free, ptr));
+ rb_obj_call_init(tdata, argc, argv);
+ return tdata;
+ }
+ catch (const NameError & e)
+ {
+ delete ptr;
+ rb_raise(c_qualified_package_name_error, e.message().c_str());
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ VALUE
+ qualified_package_name_error_new(VALUE the_class, VALUE value)
+ {
+ VALUE argv[1];
+ std::string * ptr(new std::string(STR2CSTR(value)));
+ VALUE tdata(Data_Wrap_Struct(the_class, 0, &Common<std::string>::free, ptr));
+ argv[0] = value;
+ rb_obj_call_init(tdata, 1, argv);
+ rb_call_super(1, &value);
+ return tdata;
+ }
+
+ VALUE
+ qualified_package_name_error_init(VALUE self, VALUE)
+ {
+ return self;
+ }
+
void do_register_names()
{
NameWrapper<PackageNamePart, PackageNamePartError>::do_register("PackageNamePart");
@@ -124,6 +177,20 @@ namespace
NameWrapper<SlotName, SlotNameError>::do_register("SlotName");
NameWrapper<RepositoryName, RepositoryNameError>::do_register("RepositoryName");
NameWrapper<KeywordName, KeywordNameError>::do_register("KeywordName");
+
+ rb_define_method(NameWrapper<CategoryNamePart, CategoryNamePartError>::c_class,
+ "+", RUBY_FUNC_CAST(&category_name_part_plus), 1);
+
+ c_qualified_package_name = rb_define_class("QualifiedPackageName", rb_cObject);
+ rb_define_singleton_method(c_qualified_package_name, "new", RUBY_FUNC_CAST(&qualified_package_name_new), -1);
+ rb_define_method(c_qualified_package_name, "initialize", RUBY_FUNC_CAST(&qualified_package_name_init), -1);
+ rb_define_method(c_qualified_package_name, "<=>", RUBY_FUNC_CAST(&Common<QualifiedPackageName>::compare), 1);
+ rb_include_module(c_qualified_package_name, rb_mComparable);
+ rb_define_method(c_qualified_package_name, "to_s", RUBY_FUNC_CAST(&Common<QualifiedPackageName>::to_s), 0);
+
+ c_qualified_package_name_error = rb_define_class("QualifiedPackageNameError", rb_eRuntimeError);
+ rb_define_singleton_method(c_qualified_package_name_error, "new", RUBY_FUNC_CAST(&qualified_package_name_error_new), 1);
+ rb_define_method(c_qualified_package_name_error, "initialize", RUBY_FUNC_CAST(&qualified_package_name_error_init), 1);
}
}
diff --git a/ruby/name_TEST.rb b/ruby/name_TEST.rb
index 6e35cc3..69e48a1 100644
--- a/ruby/name_TEST.rb
+++ b/ruby/name_TEST.rb
@@ -1,6 +1,23 @@
#!/usr/bin/ruby
# vim: set sw=4 sts=4 et tw=80 :
+#
+# Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+#
+# 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'
@@ -30,10 +47,10 @@ module NameTestCaseBase
x = name_type().new(valid_name_foo())
y = name_type().new(valid_name_foo())
z = name_type().new(valid_name_bar())
- assert x == y
- assert y != z
- assert z < x
- assert x > z
+ assert_equal x, y
+ assert_not_equal y, z
+ assert_operator z, :<, x
+ assert_operator x, :>, z
assert_raise TypeError do
x < valid_name_foo()
end
@@ -51,8 +68,8 @@ module NameTestCaseBase
def test_to_s
x = name_type().new(valid_name_foo())
y = name_type().new(valid_name_bar())
- assert x.to_s == valid_name_foo()
- assert y.to_s == valid_name_bar()
+ assert_equal valid_name_foo(), x.to_s
+ assert_equal valid_name_bar(), y.to_s
end
end
@@ -78,6 +95,17 @@ class TestCase_CategoryNamePart < Test::Unit::TestCase
def name_type
return CategoryNamePart
end
+
+ def test_plus
+ q = CategoryNamePart.new("foo") + PackageNamePart.new("bar")
+ assert_equal "foo/bar", q.to_s
+ end
+
+ def test_plus_bad
+ assert_raise TypeError do
+ q = CategoryNamePart.new("foo") + "bar"
+ end
+ end
end
class TestCase_UseFlagName < Test::Unit::TestCase
@@ -128,3 +156,41 @@ class TestCase_KeywordName < Test::Unit::TestCase
end
end
+class TestCase_QualifiedPackageName < Test::Unit::TestCase
+ include NameTestCaseBase
+
+ def error_type
+ return QualifiedPackageNameError
+ end
+
+ def name_type
+ return QualifiedPackageName
+ end
+
+ def valid_name_foo
+ return "foo/foo"
+ end
+
+ def valid_name_bar
+ return "bar/bar"
+ end
+
+ def test_two_arg_create
+ x = QualifiedPackageName.new(CategoryNamePart.new("foo"), PackageNamePart.new("bar"))
+ assert_equal "foo/bar", x.to_s
+ end
+
+ def test_bad_arg_count_create
+ assert_raise ArgumentError do
+ x = QualifiedPackageName.new("foo", "bar", "baz")
+ end
+ end
+
+ def test_bad_type_create
+ assert_raise TypeError do
+ x = QualifiedPackageName.new("foo", "bar")
+ end
+ end
+end
+
+
diff --git a/ruby/package_database_entry.cc b/ruby/package_database_entry.cc
new file mode 100644
index 0000000..8854fbe
--- /dev/null
+++ b/ruby/package_database_entry.cc
@@ -0,0 +1,80 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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
+ */
+
+#include <paludis_ruby.hh>
+#include <paludis/package_database_entry.hh>
+#include <paludis/util/compare.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_package_database_entry;
+
+ VALUE
+ package_database_entry_init(VALUE self, VALUE, VALUE, VALUE)
+ {
+ return self;
+ }
+
+ VALUE
+ package_database_entry_new(VALUE self, VALUE q, VALUE v, VALUE n)
+ {
+ VALUE argv[3] = { q, v, n };
+ PackageDatabaseEntry * ptr(0);
+ try
+ {
+ QualifiedPackageName * q_ptr;
+ Data_Get_Struct(q, QualifiedPackageName, q_ptr);
+ VersionSpec * v_ptr;
+ Data_Get_Struct(v, VersionSpec, v_ptr);
+ RepositoryName * n_ptr;
+ Data_Get_Struct(n, RepositoryName, n_ptr);
+
+ ptr = new PackageDatabaseEntry(*q_ptr, *v_ptr, *n_ptr);
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<PackageDatabaseEntry>::free, ptr));
+ rb_obj_call_init(tdata, 3, argv);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ void do_register_package_database_entry()
+ {
+ c_package_database_entry = rb_define_class("PackageDatabaseEntry", rb_cObject);
+ rb_define_singleton_method(c_package_database_entry, "new", RUBY_FUNC_CAST(&package_database_entry_new), 3);
+ rb_define_method(c_package_database_entry, "initialize", RUBY_FUNC_CAST(&package_database_entry_init), 3);
+ rb_define_method(c_package_database_entry, "<=>", RUBY_FUNC_CAST(&Common<PackageDatabaseEntry>::compare), 1);
+ rb_include_module(c_package_database_entry, rb_mComparable);
+ rb_define_method(c_package_database_entry, "to_s", RUBY_FUNC_CAST(&Common<PackageDatabaseEntry>::to_s), 0);
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_package_database_entry PALUDIS_ATTRIBUTE((used))
+ (&do_register_package_database_entry);
+
+
diff --git a/ruby/package_database_entry_TEST.rb b/ruby/package_database_entry_TEST.rb
new file mode 100644
index 0000000..e77767f
--- /dev/null
+++ b/ruby/package_database_entry_TEST.rb
@@ -0,0 +1,39 @@
+#!/usr/bin/ruby
+# vim: set sw=4 sts=4 et tw=80 :
+#
+# Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+#
+# 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'
+
+class TestCase_PackageDatabaseEntry < Test::Unit::TestCase
+ def test_create
+ v = PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
+ VersionSpec.new("0"), RepositoryName.new("moo"))
+ end
+
+ def test_create_error
+ assert_raise TypeError do
+ v = PackageDatabaseEntry.new("foo/bar", "0", "moo")
+ end
+ end
+ def test_to_s
+ assert_equal "foo/bar-10::moo", PackageDatabaseEntry.new(QualifiedPackageName.new("foo/bar"),
+ VersionSpec.new("10"), RepositoryName.new("moo")).to_s
+ end
+end
+
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index d70e480..7aa92c7 100644
--- a/ruby/paludis_ruby.cc
+++ b/ruby/paludis_ruby.cc
@@ -1,5 +1,22 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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
+ */
+
#include <paludis/paludis.hh>
#include <paludis_ruby.hh>
#include <ruby.h>
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index 74e9296..4650edc 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -1,5 +1,22 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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_RUBY_RUBY_PALUDIS_RUBY_HH
#define PALUDIS_GUARD_RUBY_RUBY_PALUDIS_RUBY_HH 1
@@ -7,6 +24,8 @@
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/util/attributes.hh>
#include <paludis/util/exception.hh>
+#include <paludis/util/compare.hh>
+#include <ruby.h>
namespace paludis
{
@@ -37,6 +56,31 @@ namespace paludis
public:
Register(void (* func)());
};
+
+ template <typename T_>
+ struct Common
+ {
+ static void free(void * p)
+ {
+ delete static_cast<T_ *>(p);
+ }
+
+ static VALUE compare(VALUE left, VALUE right)
+ {
+ T_ * left_ptr, * right_ptr;
+ Data_Get_Struct(left, T_, left_ptr);
+ Data_Get_Struct(right, T_, right_ptr);
+ return INT2FIX(paludis::compare(*left_ptr, *right_ptr));
+ }
+
+ static VALUE to_s(VALUE self)
+ {
+ T_ * self_ptr;
+ Data_Get_Struct(self, T_, self_ptr);
+
+ return rb_str_new2(stringify(*self_ptr).c_str());
+ }
+ };
}
}
diff --git a/ruby/paludis_ruby_TEST.rb b/ruby/paludis_ruby_TEST.rb
index 77cdfc2..83c62d7 100644
--- a/ruby/paludis_ruby_TEST.rb
+++ b/ruby/paludis_ruby_TEST.rb
@@ -1,6 +1,23 @@
#!/usr/bin/env ruby
# vim: set sw=4 sts=4 et tw=80 :
+#
+# Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+#
+# 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'
class TC_Basic < Test::Unit::TestCase
diff --git a/ruby/version_spec.cc b/ruby/version_spec.cc
new file mode 100644
index 0000000..2b3e273
--- /dev/null
+++ b/ruby/version_spec.cc
@@ -0,0 +1,72 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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
+ */
+
+#include <paludis_ruby.hh>
+#include <paludis/version_spec.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_version_spec;
+
+ VALUE
+ version_spec_init(VALUE self, VALUE)
+ {
+ return self;
+ }
+
+ VALUE
+ version_spec_new(VALUE self, VALUE s)
+ {
+ VersionSpec * ptr(0);
+ try
+ {
+ ptr = new VersionSpec(std::string(STR2CSTR(s)));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<VersionSpec>::free, ptr));
+ rb_obj_call_init(tdata, 1, &s);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ void do_register_version_spec()
+ {
+ c_version_spec = rb_define_class("VersionSpec", rb_cObject);
+ rb_define_singleton_method(c_version_spec, "new", RUBY_FUNC_CAST(&version_spec_new), 1);
+ rb_define_method(c_version_spec, "initialize", RUBY_FUNC_CAST(&version_spec_init), 1);
+ rb_define_method(c_version_spec, "<=>", RUBY_FUNC_CAST(&Common<VersionSpec>::compare), 1);
+ rb_include_module(c_version_spec, rb_mComparable);
+ rb_define_method(c_version_spec, "to_s", RUBY_FUNC_CAST(&Common<VersionSpec>::to_s), 0);
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_version_spec PALUDIS_ATTRIBUTE((used))
+ (&do_register_version_spec);
+
+
+
diff --git a/test/run_test.sh b/test/run_test.sh
index 3dc57a7..bee8b37 100755
--- a/test/run_test.sh
+++ b/test/run_test.sh
@@ -1,33 +1,36 @@
#!/bin/bash
# vim: set ft=sh sw=4 sts=4 et :
-if test -f "$TEST_SCRIPT_DIR""${2:-${1}}"_"setup.sh" ; then
- echo ">>> setup for test ${2:-${1}}"
- if ! "$TEST_SCRIPT_DIR""${2:-${1}}"_"setup.sh" ; then
- echo ">>> exiting with error for test ${2:-${1}}"
+testname=${2:-${1}}
+testname=${testname%.rb}
+
+if test -f "$TEST_SCRIPT_DIR""${testname}"_"setup.sh" ; then
+ echo ">>> setup for test ${testname}"
+ if ! "$TEST_SCRIPT_DIR""${testname}"_"setup.sh" ; then
+ echo ">>> exiting with error for test ${testname}"
exit 255
fi
fi
-echo ">>> test ${2:-${1}}"
+echo ">>> test ${testname}"
if ! ${@} ; then
- if test -f "$TEST_SCRIPT_DIR""${2:-${1}}"_"cleanup.sh" ; then
- echo ">>> cleanup for test ${2:-${1}}"
- "$TEST_SCRIPT_DIR""${2:-${1}}"_"cleanup.sh"
+ if test -f "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
+ echo ">>> cleanup for test ${testname}"
+ "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh"
fi
- echo ">>> exiting with error for test ${2:-${1}}"
+ echo ">>> exiting with error for test ${testname}"
exit 255
fi
-if test -f "$TEST_SCRIPT_DIR""${2:-${1}}"_"cleanup.sh" ; then
- echo ">>> cleanup for test ${2:-${1}}"
- if ! "$TEST_SCRIPT_DIR""${2:-${1}}"_"cleanup.sh" ; then
- echo ">>> exiting with error for test ${2:-${1}}"
+if test -f "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
+ echo ">>> cleanup for test ${testname}"
+ if ! "$TEST_SCRIPT_DIR""${testname}"_"cleanup.sh" ; then
+ echo ">>> exiting with error for test ${testname}"
exit 255
fi
fi
-echo ">>> exiting with success for test ${2:-${1}}"
+echo ">>> exiting with success for test ${testname}"
exit 0