Add Zypp::VERSION to dynamically adapt to API changes
authorKlaus Kämpf <kkaempf@suse.de>
Sat, 13 Nov 2010 17:15:55 +0000 (18:15 +0100)
committerKlaus Kämpf <kkaempf@suse.de>
Sat, 13 Nov 2010 17:15:55 +0000 (18:15 +0100)
Use this in Arch to flag if Arch::baseArch is available

swig/Arch.i
swig/ruby/tests/arch.rb
swig/zypp.i

index 1f33234..f0746e9 100644 (file)
@@ -85,7 +85,7 @@ class Arch {
    */
   static Arch s390x() { return zypp::Arch_s390x; }
 
-#if defined(SWIGRUBY)
+#if 0 /* defined(SWIGRUBY) */
 %typemap(out) int is_builtin
    "$result = $1 ? Qtrue : Qfalse;";
 %rename("builtin?") builtin;
@@ -94,7 +94,7 @@ class Arch {
    * Whether this is a builtin (or known) architecture.
    *
    */
-  int is_builtin() {
+  bool is_builtin() {
     return ($self->isBuiltIn() ? 1 : 0);
   }
 #if defined(SWIGRUBY)
@@ -112,6 +112,7 @@ class Arch {
     return ($self->compatibleWith(arch) ? 1 : 0);
   }
 
+#if ZYPP_VERSION > 800
   /*
    * return the arch before noarch if it's not a multilib arch
    * (e.g. x86_64,sparc64v,sparc64,ppc64,s390x).
@@ -121,6 +122,7 @@ class Arch {
   {
     return $self->baseArch();
   }
+#endif
 
 #if defined(SWIGRUBY)
 %alias compare "<=>";
index e9a8155..3e2f508 100644 (file)
@@ -2,7 +2,7 @@
 # Arch
 #
 
-$:.unshift "../../../build/swig/ruby"
+$:.unshift File.expand_path(File.join(File.dirname(__FILE__),"..","..","..","build","swig","ruby"))
 
 require 'test/unit'
 require 'zypp'
@@ -19,7 +19,7 @@ class ArchTest < Test::Unit::TestCase
     a = Arch.new("i386")
     assert a
     assert_equal "i386", a.to_s
-    assert a.is_builtin
+    assert_equal true, a.is_builtin
     
     # i486 is 'bigger' than i386
     
@@ -27,7 +27,9 @@ class ArchTest < Test::Unit::TestCase
     assert b
     assert_equal "i486", b.to_s
     assert b.is_builtin
-    assert_equal a, b.base_arch
+    if VERSION > 800
+      assert_equal a, b.base_arch
+    end
     assert a < b
     assert a.compatible_with?(b)
 
@@ -35,7 +37,7 @@ class ArchTest < Test::Unit::TestCase
     z = Arch.new("xyzzy")
     assert z
     assert_equal "xyzzy", z.to_s
-    assert !z.is_builtin
+    assert_equal false, z.is_builtin
     
     # predefined archs
     assert_equal Arch.new("noarch"), Arch.noarch 
index b09dfd9..856156a 100644 (file)
@@ -1,5 +1,8 @@
 %module zypp
 
+/* set this to 0 (zero) to only create a subset of the bindings
+ * for testing
+ */
 #define PRODUCTION 1
 
 #ifdef SWIGPERL5
@@ -140,8 +143,7 @@ typedef std::list<std::string> StringList;
 
 %}
 
-%nodefault ByKind;
-
+/* prevent swig from creating a type called 'Target_Type' */
 #if defined(SWIGRUBY)
 #define Target_Type VALUE
 #endif
@@ -152,22 +154,6 @@ typedef std::list<std::string> StringList;
 #define Target_Type SV *
 #endif
 
-%rename("+") "operator+";
-%rename("<<") "operator<<";
-%rename("!=") "operator!=";
-%rename("!") "operator!";
-%rename("==") "operator==";
-
-namespace zypp {
-  namespace base {
-    // silence 'Nothing known about class..' warning
-    class  ReferenceCounted {};
-  }
-}
-
-%include "std_string.i"
-%include "stl.i"
-
 #ifdef SWIGRUBY
 %include "ruby/std_list.i"
 %include "ruby/std_set.i"
@@ -185,10 +171,33 @@ namespace zypp {
 %include "perl5/perl.i"
 #endif
 
+#define VERSION ZYPP_VERSION
+
 /* These include files are already cleaned up from C++ cruft */
 %include "Arch.i"
+%include "Resolvable.i"
+%include "Callbacks.i"
 
 /* These include files are pending to be cleaned up from C++ cruft */
+#if PRODUCTION /* set 0 for testing, these files still carry the full C++ cruft */
+
+%nodefault ByKind;
+
+%rename("+") "operator+";
+%rename("<<") "operator<<";
+%rename("!=") "operator!=";
+%rename("!") "operator!";
+%rename("==") "operator==";
+
+namespace zypp {
+  namespace base {
+    // silence 'Nothing known about class..' warning
+    class  ReferenceCounted {};
+  }
+}
+
+%include "std_string.i"
+%include "stl.i"
 
 #ifdef BOOST_SMARTPTR_INCLUDE_DIR
 %import <boost/smart_ptr/scoped_ptr.hpp>
@@ -204,7 +213,6 @@ namespace zypp {
 %import <zypp/base/PtrTypes.h>
 %import <zypp/base/Flags.h>
 
-#if PRODUCTION /* set 0 for testing, these files still carry the full C++ cruft */
 %include "IdStringType.i"
 %include "Pathname.i"
 %include "ByteCount.i"
@@ -223,7 +231,6 @@ namespace zypp {
 %include "ServiceInfo.i"
 %include "ResTraits.i"
 %include "ResStatus.i"
-%include "Resolvable.i"
 %include "ResObject.i"
 %include "Package.i"
 %include "Patch.i"
@@ -238,16 +245,12 @@ namespace zypp {
 %include "Target.i"
 %include "MediaSetAccess.i"
 %include "PoolItem.i"
-#endif
 %include "ResPool.i"
-#if PRODUCTION
 %include "ZYppCommitPolicy.i"
 %include "ZYppCommitResult.i"
 %include "TmpPath.i"
 %include "Resolver.i"
 %include "ZConfig.i"
-%include "Callbacks.i"
-#endif
 
 %ignore zypp::ZYpp::setTextLocale;
 %ignore zypp::ZYpp::getTextLocale;
@@ -261,6 +264,7 @@ namespace zypp {
 %include <zypp/ZYpp.h>
 
 %include "ZYppFactory.i"
+#endif
 
 //
 // helper