aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-05-23 22:46:22 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-05-23 22:46:22 +0000
commit848d36a59b230b040a25991ee0e560dc3518427f (patch)
tree8d63e6876993fb8c03236dc50cb1dce36f9d96a2
parent213188b0b062b770a36a12c3b84b5fd9735b5669 (diff)
downloadpaludis-848d36a59b230b040a25991ee0e560dc3518427f.tar.gz
paludis-848d36a59b230b040a25991ee0e560dc3518427f.tar.xz
(ruby) EAPI classes.
-rw-r--r--ruby/Makefile.am7
-rw-r--r--ruby/eapi.cc200
-rw-r--r--ruby/eapi_TEST.rb114
-rw-r--r--ruby/name.cc46
-rw-r--r--ruby/paludis_ruby.hh2
-rw-r--r--ruby/version_metadata.cc30
-rw-r--r--ruby/version_metadata_TEST.rb2
7 files changed, 385 insertions, 16 deletions
diff --git a/ruby/Makefile.am b/ruby/Makefile.am
index 4bb2bfc..f25f4cc 100644
--- a/ruby/Makefile.am
+++ b/ruby/Makefile.am
@@ -33,7 +33,8 @@ IF_RUBY_TESTS = \
dep_tag_TEST.rb \
query_TEST.rb \
package_database_TEST.rb \
- find_unused_packages_task_TEST.rb
+ find_unused_packages_task_TEST.rb \
+ eapi_TEST.rb
IF_RUBY_QA_TESTS = \
message_TEST.rb \
@@ -59,7 +60,9 @@ IF_RUBY_SOURCES = \
dep_list.cc \
dep_tag.cc \
query.cc \
- find_unused_packages_task.cc
+ find_unused_packages_task.cc \
+ eapi.cc \
+ name.cc
IF_RUBY_QA_SOURCES = \
message.cc \
diff --git a/ruby/eapi.cc b/ruby/eapi.cc
new file mode 100644
index 0000000..bcccc55
--- /dev/null
+++ b/ruby/eapi.cc
@@ -0,0 +1,200 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Richard Brown <rbrown@gentoo.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/eapi.hh>
+#include <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_eapi;
+ static VALUE c_supported_eapi;
+ static VALUE c_eapi_data;
+
+ VALUE
+ supported_eapi_to_value(tr1::shared_ptr<const SupportedEAPI> m)
+ {
+ tr1::shared_ptr<const SupportedEAPI> * m_ptr = new tr1::shared_ptr<const SupportedEAPI>(m);
+ return Data_Wrap_Struct(c_supported_eapi, 0, &Common<tr1::shared_ptr<const SupportedEAPI> >::free, m_ptr);
+ }
+
+ VALUE
+ eapi_name(VALUE self)
+ {
+ EAPI * p;
+ Data_Get_Struct(self, EAPI, p);
+ return rb_str_new2((p->name).c_str());
+ }
+
+ VALUE
+ eapi_supported(VALUE self)
+ {
+ EAPI * p;
+ Data_Get_Struct(self, EAPI, p);
+ if (p->supported)
+ return supported_eapi_to_value((p->supported));
+ return Qnil;
+ }
+ /*
+ * Document-method: package_dep_spec_parse_mode
+ *
+ * call-seq:
+ * package_dep_spec_parse_mode -> PackageDepSpecParseMode
+ *
+ * Our PackageDepSpecParseMode.
+ */
+ /*
+ * Document-method: strict_package_dep_spec_parse_mode
+ *
+ * call-seq:
+ * strict_package_dep_spec_parse_mode -> PackageDepSpecParseMode
+ *
+ * Our strict PackageDepSpecParseMode.
+ */
+ /*
+ * Document-method: iuse_flag_parse_mode
+ *
+ * call-seq:
+ * iuse_flag_parse_mode -> IUseFlagParseMode
+ *
+ * Our IUseFlagParseMode.
+ */
+ /*
+ * Document-method: strict_iuse_flag_parse_mode
+ *
+ * call-seq:
+ * strict_iuse_flag_parse_mode -> IUseFlagParseMode
+ *
+ * Our strict IUseFlagParseMode.
+ */
+ template <typename T_, T_ SupportedEAPI::* m_>
+ struct ParseModeMember
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ tr1::shared_ptr<SupportedEAPI> * p;
+ Data_Get_Struct(self, tr1::shared_ptr<SupportedEAPI>, p);
+ return INT2FIX((**p).*m_);
+ }
+ };
+
+ /*
+ * Document-method: breaks_portage?
+ *
+ * call_seq:
+ * breaks_portage? -> true or false
+ *
+ * Does this EAPI break portage?
+ */
+ /*
+ * Document-method: has_pretend_phase?
+ *
+ * call_seq:
+ * has_pretend_phase? -> true or false
+ *
+ * Does this EAPI have a pretend phase?
+ */
+ template <bool SupportedEAPI::* m_>
+ struct BoolMember
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ tr1::shared_ptr<SupportedEAPI> * p;
+ Data_Get_Struct(self, tr1::shared_ptr<SupportedEAPI>, p);
+ return ((**p).*m_) ? Qtrue : Qfalse;
+ }
+ };
+
+ /*
+ * call-seq:
+ * EAPIData.eapi_from_string(eapi_string) -> EAPI
+ *
+ * Make an EAPI.
+ */
+ VALUE
+ eapi_data_eapi_from_string(VALUE, VALUE eapi)
+ {
+ return eapi_to_value(EAPIData::get_instance()->eapi_from_string(stringify(StringValuePtr(eapi))));
+ }
+
+ /*
+ * call-seq:
+ * EAPIData.unknown_eapi -> EAPI
+ *
+ * Make the unknown EAPI.
+ */
+ VALUE
+ eapi_data_unknown_eapi()
+ {
+ return eapi_to_value(EAPIData::get_instance()->unknown_eapi());
+ }
+
+ void do_register_eapi()
+ {
+ /*
+ * Document-class: Paludis::EAPI
+ *
+ * Information about an EAPI.
+ */
+ c_eapi = rb_define_class_under(paludis_module(), "EAPI", rb_cObject);
+ rb_funcall(c_eapi, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_eapi, "name", RUBY_FUNC_CAST(&eapi_name), 0);
+ rb_define_method(c_eapi, "supported", RUBY_FUNC_CAST(&eapi_supported), 0);
+
+ c_supported_eapi = rb_define_class_under(paludis_module(), "SupportedEAPI", rb_cObject);
+ rb_funcall(c_supported_eapi, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_supported_eapi, "package_dep_spec_parse_mode",
+ RUBY_FUNC_CAST((&ParseModeMember<PackageDepSpecParseMode, &SupportedEAPI::package_dep_spec_parse_mode>::fetch)), 0);
+ rb_define_method(c_supported_eapi, "strict_package_dep_spec_parse_mode",
+ RUBY_FUNC_CAST((&ParseModeMember<PackageDepSpecParseMode, &SupportedEAPI::strict_package_dep_spec_parse_mode>::fetch)), 0);
+ rb_define_method(c_supported_eapi, "iuse_flag_parse_mode",
+ RUBY_FUNC_CAST((&ParseModeMember<IUseFlagParseMode, &SupportedEAPI::iuse_flag_parse_mode>::fetch)), 0);
+ rb_define_method(c_supported_eapi, "strict_iuse_flag_parse_mode",
+ RUBY_FUNC_CAST((&ParseModeMember<IUseFlagParseMode, &SupportedEAPI::strict_iuse_flag_parse_mode>::fetch)), 0);
+ rb_define_method(c_supported_eapi, "breaks_portage?",
+ RUBY_FUNC_CAST((&BoolMember<&SupportedEAPI::breaks_portage>::fetch)), 0);
+ rb_define_method(c_supported_eapi, "has_pretend_phase?",
+ RUBY_FUNC_CAST((&BoolMember<&SupportedEAPI::has_pretend_phase>::fetch)), 0);
+
+ rb_require("singleton");
+
+ c_eapi_data = rb_define_class_under(paludis_module(), "EAPIData", rb_cObject);
+ rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")), rb_intern("included"), 1, c_eapi_data);
+ rb_define_method(c_eapi_data, "eapi_from_string", RUBY_FUNC_CAST(&eapi_data_eapi_from_string), 1);
+ rb_define_method(c_eapi_data, "unknown_eapi", RUBY_FUNC_CAST(&eapi_data_unknown_eapi), 0);
+ }
+}
+
+VALUE
+paludis::ruby::eapi_to_value(const EAPI & v)
+{
+ EAPI * m_ptr = new EAPI(v);
+ return Data_Wrap_Struct(c_eapi, 0, &Common<EAPI>::free, m_ptr);
+}
+
+RegisterRubyClass::Register paludis_ruby_register_eapi PALUDIS_ATTRIBUTE((used))
+ (&do_register_eapi);
+
diff --git a/ruby/eapi_TEST.rb b/ruby/eapi_TEST.rb
new file mode 100644
index 0000000..0c24c34
--- /dev/null
+++ b/ruby/eapi_TEST.rb
@@ -0,0 +1,114 @@
+#!/usr/bin/env ruby
+# vim: set sw=4 sts=4 et tw=80 :
+
+#
+# Copyright (c) 2007 Richard Brown <rbrown@gentoo.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
+#
+
+ENV["PALUDIS_HOME"] = Dir.getwd().to_s + "/default_environment_TEST_dir/home";
+
+require 'test/unit'
+require 'Paludis'
+
+module Paludis
+ class TestCase_EAPIData < Test::Unit::TestCase
+ def test_instance
+ assert_equal Log.instance.__id__, Log.instance.__id__
+ end
+
+ def test_no_create
+ assert_raise NoMethodError do
+ x = EAPIData.new()
+ end
+ end
+
+ def test_unknown_eapi
+ assert_respond_to EAPIData.instance, :unknown_eapi
+ assert_kind_of EAPI, EAPIData.instance.unknown_eapi
+ end
+
+ def test_eapi_from_string
+ assert_respond_to EAPIData.instance, :eapi_from_string
+ assert_kind_of EAPI, EAPIData.instance.eapi_from_string('0')
+ end
+ end
+
+ class TestCase_EAPI < Test::Unit::TestCase
+ def eapi0
+ @eapi0 ||= EAPIData.instance.eapi_from_string('0')
+ end
+
+ def eapi_zarniwoop
+ @eapi_zarniwoop ||= EAPIData.instance.eapi_from_string('zarniwoop')
+ end
+
+ def test_no_create
+ assert_raise NoMethodError do
+ x = EAPI.new()
+ end
+ end
+
+ def test_name
+ assert_equal '0', eapi0.name
+ assert_equal 'zarniwoop', eapi_zarniwoop.name
+ end
+
+ def test_supported
+ assert_kind_of SupportedEAPI, eapi0.supported
+ assert_kind_of NilClass, eapi_zarniwoop.supported
+ end
+ end
+
+ class TestCase_SupportedEAPI < Test::Unit::TestCase
+ include PackageDepSpecParseMode
+ include IUseFlagParseMode
+
+ def supported
+ @supported ||= EAPIData.instance.eapi_from_string('0').supported
+ end
+
+ def test_no_create
+ assert_raise NoMethodError do
+ x = SupportedEAPI.new()
+ end
+ end
+
+ def test_package_dep_spec_parse_mode
+ assert_equal Eapi0, supported.package_dep_spec_parse_mode
+ end
+
+ def test_strict_package_dep_spec_parse_mode
+ assert_equal Eapi0Strict, supported.strict_package_dep_spec_parse_mode
+ end
+
+ def test_iuse_flag_parse_mode
+ assert_equal Eapi0, supported.iuse_flag_parse_mode
+ end
+
+ def test_strict_iuse_flag_parse_mode
+ assert_equal Eapi0Strict, supported.strict_iuse_flag_parse_mode
+ end
+
+ def test_breaks_portage?
+ assert !supported.breaks_portage?
+ end
+
+ def test_has_pretend_phase?
+ assert !supported.has_pretend_phase?
+ end
+ end
+end
+
diff --git a/ruby/name.cc b/ruby/name.cc
new file mode 100644
index 0000000..a8c836d
--- /dev/null
+++ b/ruby/name.cc
@@ -0,0 +1,46 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Richard Brown <rbrown@gentoo.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 <ruby.h>
+
+using namespace paludis;
+using namespace paludis::ruby;
+
+#define RUBY_FUNC_CAST(x) reinterpret_cast<VALUE (*)(...)>(x)
+
+namespace
+{
+ static VALUE c_iuse_flag_parse_mode;
+
+ void do_register_names()
+ {
+ c_iuse_flag_parse_mode = rb_define_module_under(paludis_module(), "IUseFlagParseMode");
+ for (IUseFlagParseMode l(static_cast<IUseFlagParseMode>(0)), l_end(last_iuse_pm) ; l != l_end ;
+ l = static_cast<IUseFlagParseMode>(static_cast<int>(l) + 1))
+ rb_define_const(c_iuse_flag_parse_mode, value_case_to_RubyCase(stringify(l)).c_str(), INT2FIX(l));
+
+ // cc_enum_special<paludis/name.hh, , c_log_level>
+ }
+}
+
+RegisterRubyClass::Register paludis_ruby_register_names PALUDIS_ATTRIBUTE((used)) (&do_register_names);
+
+
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index fbb35cf..38bf403 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -35,6 +35,7 @@
#include <paludis/repository.hh>
#include <paludis/contents.hh>
#include <paludis/dep_tag.hh>
+#include <paludis/eapi.hh>
#ifdef ENABLE_RUBY_QA
#include <paludis/qa/qa.hh>
@@ -73,6 +74,7 @@ namespace paludis
VALUE contents_to_value(tr1::shared_ptr<const Contents>);
VALUE contents_entry_to_value(tr1::shared_ptr<const ContentsEntry>);
VALUE dep_tag_to_value(tr1::shared_ptr<const DepTag>);
+ VALUE eapi_to_value(const EAPI &);
VersionSpec value_to_version_spec(VALUE v);
tr1::shared_ptr<const VersionMetadata> value_to_version_metadata(VALUE);
diff --git a/ruby/version_metadata.cc b/ruby/version_metadata.cc
index 2120cc3..a03bdb8 100644
--- a/ruby/version_metadata.cc
+++ b/ruby/version_metadata.cc
@@ -133,16 +133,6 @@ namespace
*
* Our slot
*/
-#ifdef CIARANM_REMOVED_THIS
- /*
- * Document-method: eapi
- *
- * call-seq:
- * eapi -> String
- *
- * Our eapi
- */
-#endif
/*
* Document-method: description
*
@@ -164,6 +154,22 @@ namespace
};
/*
+ * Document-method: eapi
+ *
+ * call-seq:
+ * eapi -> EAPI
+ *
+ * Our EAPI.
+ */
+
+ VALUE
+ version_metadata_eapi(VALUE self)
+ {
+ tr1::shared_ptr<const VersionMetadata> * self_ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<const VersionMetadata>, self_ptr);
+ return eapi_to_value((*self_ptr)->eapi);
+ }
+ /*
* Document-method: homepage
*
* call-seq:
@@ -459,9 +465,7 @@ namespace
rb_define_method(c_version_metadata, "license", RUBY_FUNC_CAST(&version_metadata_license), 0);
rb_define_method(c_version_metadata, "slot", RUBY_FUNC_CAST((&BaseValue<SlotName, &VersionMetadataBase::slot>::fetch)), 0);
-#ifdef CIARANM_REMOVED_THIS
- rb_define_method(c_version_metadata, "eapi", RUBY_FUNC_CAST((&BaseValue<std::string, &VersionMetadataBase::eapi>::fetch)), 0);
-#endif
+ rb_define_method(c_version_metadata, "eapi", RUBY_FUNC_CAST(&version_metadata_eapi), 0);
rb_define_method(c_version_metadata, "homepage", RUBY_FUNC_CAST(&version_metadata_homepage), 0);
rb_define_method(c_version_metadata, "description", RUBY_FUNC_CAST((&BaseValue<std::string,
&VersionMetadataBase::description>::fetch)), 0);
diff --git a/ruby/version_metadata_TEST.rb b/ruby/version_metadata_TEST.rb
index 844c62c..220c14f 100644
--- a/ruby/version_metadata_TEST.rb
+++ b/ruby/version_metadata_TEST.rb
@@ -68,7 +68,7 @@ module Paludis
# assert_equal "http://paludis.pioto.org/", vmd("1.0").homepage
assert_kind_of DepSpec, vmd('1.0').homepage
assert_equal "0", vmd("1.0").slot
-# assert_equal "0", vmd("1.0").eapi
+ assert_equal "0", vmd("1.0").eapi.name
# assert_equal "GPL-2", vmd("1.0").license_string
assert_kind_of DepSpec, vmd('1.0').license
assert !vmd('1.0').interactive?