Author: kkaempf Date: Thu Dec 20 23:19:47 2007 New Revision: 8131 URL: http://svn.opensuse.org/viewcvs/zypp?rev=8131&view=rev Log: put some love into the bindings - dont generate everything from .h file, but selectively whats actually needed - add test cases for Ruby bindings Added: trunk/sat-solver/bindings/ruby/tests/ trunk/sat-solver/bindings/ruby/tests/loading.rb trunk/sat-solver/bindings/ruby/tests/pool.rb trunk/sat-solver/bindings/ruby/tests/repo.rb Removed: trunk/sat-solver/bindings/ruby/ruby.i trunk/sat-solver/bindings/ruby/satsolver.rb Modified: trunk/sat-solver/bindings/ruby/CMakeLists.txt trunk/sat-solver/bindings/satsolver.i Modified: trunk/sat-solver/bindings/ruby/CMakeLists.txt URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/CMakeLists.txt?rev=8131&r1=8130&r2=8131&view=diff ============================================================================== --- trunk/sat-solver/bindings/ruby/CMakeLists.txt (original) +++ trunk/sat-solver/bindings/ruby/CMakeLists.txt Thu Dec 20 23:19:47 2007 @@ -1,3 +1,5 @@ +ADD_SUBDIRECTORY(tests) + #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") @@ -7,30 +9,29 @@ MESSAGE(STATUS "Ruby vendor arch dir: ${RUBY_VENDOR_ARCH_DIR}") MESSAGE(STATUS "Ruby include path: ${RUBY_INCLUDE_PATH}") -SET( SWIG_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.cxx" ) +SET( SWIG_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.c" ) SET( SWIG_INPUT "${CMAKE_CURRENT_SOURCE_DIR}/satsolver.i" ) ADD_CUSTOM_COMMAND ( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.cxx + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.c COMMAND ${CMAKE_COMMAND} -E echo_append "Creating wrapper code for ruby..." - COMMAND ${SWIG_EXECUTABLE} -c++ -ruby -autorename -xmlout ${CMAKE_CURRENT_BINARY_DIR}/parse.xml -o ${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.cxx -I${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/../satsolver.i + COMMAND ${SWIG_EXECUTABLE} -ruby -autorename -o ${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.c -I${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/../satsolver.i COMMAND ${CMAKE_COMMAND} -E echo "Done." WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../*.i ${CMAKE_CURRENT_SOURCE_DIR}/*.i + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../*.i ) ADD_CUSTOM_TARGET( glue DEPENDS ${SWIG_OUTPUT} ) -ADD_LIBRARY( satsolverx SHARED "${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.cxx" ) -SET_TARGET_PROPERTIES( satsolverx PROPERTIES PREFIX "" ) -ADD_DEPENDENCIES( satsolverx glue ) +ADD_LIBRARY( SatSolver SHARED "${CMAKE_CURRENT_BINARY_DIR}/libsatsolver_wrap.c" ) +SET_TARGET_PROPERTIES( SatSolver PROPERTIES PREFIX "" ) +ADD_DEPENDENCIES( SatSolver glue ) INCLUDE_DIRECTORIES( ${RUBY_INCLUDE_PATH} ) -TARGET_LINK_LIBRARIES( satsolverx satsolver ) -TARGET_LINK_LIBRARIES( satsolverx ${RUBY_LIBRARY} ) - -INSTALL(TARGETS satsolverx LIBRARY DESTINATION ${RUBY_VENDOR_ARCH_DIR}) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/satsolver.rb DESTINATION ${RUBY_VENDORLIB_DIR} ) +TARGET_LINK_LIBRARIES( SatSolver satsolver ) +TARGET_LINK_LIBRARIES( SatSolver ${RUBY_LIBRARY} ) +INSTALL(TARGETS SatSolver LIBRARY DESTINATION ${RUBY_VENDOR_ARCH_DIR}) +#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/satsolver.rb DESTINATION ${RUBY_VENDORLIB_DIR} ) \ No newline at end of file Added: trunk/sat-solver/bindings/ruby/tests/loading.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/loading.rb?rev=8131&view=auto ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/loading.rb (added) +++ trunk/sat-solver/bindings/ruby/tests/loading.rb Thu Dec 20 23:19:47 2007 @@ -0,0 +1,10 @@ +$: << "../../../build/bindings/ruby" +# test loading of extension +require 'test/unit' + +class LoadTest < Test::Unit::TestCase + def test_loading + require 'SatSolver' + assert true + end +end Added: trunk/sat-solver/bindings/ruby/tests/pool.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/pool.rb?rev=8131&view=auto ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/pool.rb (added) +++ trunk/sat-solver/bindings/ruby/tests/pool.rb Thu Dec 20 23:19:47 2007 @@ -0,0 +1,12 @@ +$: << "../../../build/bindings/ruby" +# test Pool +require 'test/unit' +require 'SatSolver' + +class PoolTest < Test::Unit::TestCase + def test_pool + pool = SatSolver::Pool.new + assert pool + assert pool.repo_count == 0 + end +end Added: trunk/sat-solver/bindings/ruby/tests/repo.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/repo.rb?rev=8131&view=auto ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/repo.rb (added) +++ trunk/sat-solver/bindings/ruby/tests/repo.rb Thu Dec 20 23:19:47 2007 @@ -0,0 +1,25 @@ +$: << "../../../build/bindings/ruby" +# test Repo +require 'test/unit' +require 'SatSolver' + +class RepoTest < Test::Unit::TestCase + def test_repo_create + pool = SatSolver::Pool.new + assert pool + repo = SatSolver::Repo.new( pool, "test" ) + assert repo + assert repo.size == 0 + assert repo.name == "test" + end + def test_repo_add + pool = SatSolver::Pool.new + assert pool + repo = SatSolver::Repo.new( pool, "test" ) + assert repo + pool.arch = "i686" + puts repo.add_solv( "../../../testsuite/data.libzypp/basic-exercises/exercise-1-packages.solv" ) + puts repo.name + puts repo.size + end +end Modified: trunk/sat-solver/bindings/satsolver.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/satsolver.i?rev=8131&r1=8130&r2=8131&view=diff ============================================================================== --- trunk/sat-solver/bindings/satsolver.i (original) +++ trunk/sat-solver/bindings/satsolver.i Thu Dec 20 23:19:47 2007 @@ -1,9 +1,7 @@ -%module satsolverx +%module SatSolver %{ -extern "C" -{ #include "ruby.h" #include "rubyio.h" #include "policy.h" @@ -20,11 +18,14 @@ #include "solver.h" #include "repo.h" #include "repo_solv.h" -} -#include <sstream> + +/*#include <sstream> */ %} +/*-------------------------------------------------------------*/ +/* types and typemaps */ + #if defined(SWIGRUBY) %typemap(in) FILE* { OpenFile *fptr; @@ -34,39 +35,84 @@ /*rb_io_check_writable(fptr);*/ $1 = GetReadFile(fptr); } + +%typemap(in) Id { + $1 = (int) NUM2INT($input); +} + +%typemap(in) Offset { + $1 = (unsigned int) NUM2INT($input); +} #endif -%include "bitmap.h" -%include "evr.h" -%include "hash.h" -%include "poolarch.h" +%nodefault _Repo; +%rename(Repo) _Repo; +typedef struct _Repo {} Repo; + +%nodefault _Solvable; +%rename(Solvable) _Solvable; +struct _Solvable {}; + +/*-------------------------------------------------------------*/ +/* Pool */ + +%newobject pool_create; +%delobject pool_free; +typedef struct _Pool {} Pool; +%rename(Pool) _Pool; -%alias Pool::nsolvables "size" -%include "pool.h" -%extend _Pool { +%extend Pool { - _Pool() + /* + * Pool management + */ + + Pool() { return pool_create(); } - ~_Pool() + ~Pool() { pool_free($self); } - void set_arch(const char *arch) - { pool_setarch($self, arch); } +#if defined(SWIGRUBY) + %rename( "arch=" ) set_arch( const char *arch ); +#endif + void set_arch( const char *arch ) + { pool_setarch( $self, arch ); } - int installable(Solvable *s) - { return pool_installable($self,s); } +#if defined(SWIGRUBY) + %rename( "debug=" ) set_debug( int level ); +#endif + void set_debug( int level ) + { pool_setdebuglevel( $self, level ); } void prepare() - { pool_createwhatprovides($self); } + { pool_createwhatprovides( $self ); } + + /* + * Repo management + */ + + int repo_count() + { return $self->nrepos; } void each_repo() { - for (int i = 0; i < $self->nrepos; ++i ) + int i; + for (i = 0; i < $self->nrepos; ++i ) rb_yield(SWIG_NewPointerObj((void*) $self->repos[i], SWIGTYPE_p__Repo, 0)); } + /* + * Solvable management + */ + + int size() + { return $self->nsolvables; } + + int installable( Solvable *s ) + { return pool_installable( $self,s ); } + Solvable *id2solvable(Id p) { return pool_id2solvable($self, p); @@ -121,15 +167,85 @@ return pool->solvables + id; } +} + +/*-------------------------------------------------------------*/ +/* Repo */ + +%extend Repo { + Repo( Pool *pool, const char *reponame ) + { return repo_create( pool, reponame ); } + int add_solv( FILE *fp ) + { return repo_add_solv( $self, fp ); } + int add_solv( const char *fname ) + { + int result = -1; + FILE *fp = fopen( fname, "r"); + if (fp) { + result = repo_add_solv( $self, fp ); + fclose( fp ); + } + return result; + } + int size() + { return $self->nsolvables; } + const char *name() + { return $self->name; } + int priority() + { return $self->priority; } + Pool *pool() + { return $self->pool; } +} + +#if 0 + + +/*-------------------------------------------------------------*/ +/* Solvable */ + +%include "solvable.h" + +%extend Solvable { + + Id id() { + if (!$self->repo) + return 0; + return $self - $self->repo->pool->solvables; + } + + //%typemap(ruby,in) Id { + // $1 = id2str($self->pool, $input); + //} + + //%typemap(ruby,out) Id { + // $result = rb_str_new2(str2id($self->pool,$1)); + //} - Repo* create_repo(const char *reponame) + //%rename(name_id) name(); + %ignore name; + const char * name() + { return id2str($self->repo->pool, $self->name);} + %ignore arch; + const char * arch() + { return id2str($self->repo->pool, $self->arch);} + %ignore evr; + const char * evr() + { return id2str($self->repo->pool, $self->evr);} + %ignore vendor; + const char * vendor() + { return id2str($self->repo->pool, $self->vendor);} + + %rename("to_s") asString(); + const char * asString() { - return repo_create($self, reponame); + if ( !$self->repo ) + return "<UNKNOWN>"; + return solvable2str($self->repo->pool, $self); } -}; -%newobject pool_create; -%delobject pool_free; +} + +/*-------------------------------------------------------------*/ %include "poolid.h" %include "pooltypes.h" @@ -170,39 +286,6 @@ %delobject queue_free; -%include "solvable.h" - -%extend Solvable { - - Id id() { - if (!$self->repo) - return 0; - return $self - $self->repo->pool->solvables; - } - - //%typemap(ruby,in) Id { - // $1 = id2str($self->pool, $input); - //} - - //%typemap(ruby,out) Id { - // $result = rb_str_new2(str2id($self->pool,$1)); - //} - - //%rename(name_id) name(); - %ignore name; - const char * name() - { return id2str($self->repo->pool, $self->name);} - - %rename("to_s") asString(); - const char * asString() - { - if ( $self->repo == NULL ) - return "<UNKNOWN>"; - return solvable2str($self->repo->pool, $self); - } - -} - %include "solver.h" @@ -289,7 +372,4 @@ %include "repo_solv.h" -%typemap(in) Id { - $1 = (int) NUM2INT($input); - printf("Received an integer : %d\n",$1); -} +#endif \ No newline at end of file -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org