From 07cacb881b6d03d83a97ecf477418b0cfdbf79e2 Mon Sep 17 00:00:00 2001 From: Stefan Haas Date: Thu, 6 Sep 2007 14:15:14 +0000 Subject: [PATCH] first running version of perl-bindings --- swig/CMakeLists.txt | 2 ++ swig/ItemCapKind.i | 59 +++++++++++++++++++++++++++++++++++++++++++++++ swig/RepoInfo.i | 6 +++-- swig/ResPool.i | 25 ++++++++++++++++++-- swig/ResStatus.i | 36 +++++++++++++++++++---------- swig/Resolver.i | 50 +++++++++++++++++++++++++++++++++++++++ swig/perl5/CMakeLists.txt | 41 ++++++++++++++++++++++++++++++++ swig/perl5/perl.i | 0 swig/zypp.i | 29 ++++++++++++++++++----- 9 files changed, 226 insertions(+), 22 deletions(-) create mode 100644 swig/ItemCapKind.i create mode 100644 swig/Resolver.i create mode 100644 swig/perl5/CMakeLists.txt create mode 100644 swig/perl5/perl.i diff --git a/swig/CMakeLists.txt b/swig/CMakeLists.txt index b3004d4..8cac9d9 100644 --- a/swig/CMakeLists.txt +++ b/swig/CMakeLists.txt @@ -3,3 +3,5 @@ ADD_SUBDIRECTORY(ruby) ADD_SUBDIRECTORY(python) +ADD_SUBDIRECTORY(perl5) + diff --git a/swig/ItemCapKind.i b/swig/ItemCapKind.i new file mode 100644 index 0000000..6493130 --- /dev/null +++ b/swig/ItemCapKind.i @@ -0,0 +1,59 @@ +/*%{ + +struct solver::detail::ItemCapKind +{ + public: + Capability cap; //Capability which has triggerd this selection + Dep capKind; //Kind of that capability + PoolItem_Ref item; //Item which has triggered this selection + bool initialInstallation; //This item has triggered the installation + //Not already fullfilled requierement only. + + ItemCapKind( PoolItem i, Capability c, Dep k, bool initial) + : cap( c ) + , capKind( k ) + , item( i ) + , initialInstallation( initial ) + { } +}; +//typedef std::list solver::detail::ItemCapKindList; +%} +*/ + +namespace zypp +{ + namespace solver + { + namespace detail + { + + struct ItemCapKind + { + public: + Capability cap; + Dep capKind; + PoolItem_Ref item; + bool initialInstallation; + + /*%extend { + ItemCapKind(){}; + }*/ + + //ItemCapKind(); + ItemCapKind( PoolItem i, Capability c, Dep k, bool initial) + : cap( c ) + , capKind( k ) + , item( i ) + , initialInstallation( initial ) + { } + }; + } + } +} +typedef std::list solver::detail::ItemCapKindList; +%template(ItemCapKindList) std::list; + +#ifdef SWIGRUBY + auto_iterator(std::list, solver::detail::ItemCapKind); +#endif + diff --git a/swig/RepoInfo.i b/swig/RepoInfo.i index 0210642..afbd32a 100644 --- a/swig/RepoInfo.i +++ b/swig/RepoInfo.i @@ -1,5 +1,7 @@ - -%template(UrlSet) std::set; +#ifdef SWIGPERL5 +#else + %template(UrlSet) std::set; +#endif class RepoInfo { diff --git a/swig/ResPool.i b/swig/ResPool.i index 998dc75..b288160 100644 --- a/swig/ResPool.i +++ b/swig/ResPool.i @@ -27,10 +27,10 @@ class ResPool /** \name Iterate through all ResObjects (all kinds). */ //@{ - /** + #ifdef SWIGPERL5 const_iterator begin() const; const_iterator end() const; - */ + #endif //@} public: @@ -150,6 +150,27 @@ class ResPool }; +#ifdef SWIGPERL5 + +%extend ResPool { + + pool::PoolTraits::const_iterator iterator_incr(pool::PoolTraits::const_iterator *it ) { + (*it)++; + return *it; + } + pool::PoolTraits::const_iterator iterator_decr(pool::PoolTraits::const_iterator it) { + (it)--; + return it; + } + bool iterator_equal(pool::PoolTraits::const_iterator it1, pool::PoolTraits::const_iterator it2) { + return (it1 == it2); + } + PoolItem_Ref iterator_value(pool::PoolTraits::const_iterator it) { + return (*it); + } +}; + +#endif #ifdef SWIGRUBY diff --git a/swig/ResStatus.i b/swig/ResStatus.i index a26056c..7661354 100644 --- a/swig/ResStatus.i +++ b/swig/ResStatus.i @@ -1,6 +1,16 @@ class ResStatus { + public: + + /** Default ctor. */ + ResStatus(); + + /** Ctor setting the initial . */ + ResStatus( bool isInstalled_r ); + + /** Dtor. */ + ~ResStatus(); public: /** \name BitField range definitions. @@ -78,9 +88,9 @@ class ResStatus }; enum SolverStateValue { - NORMAL = bit::RangeValue::value, // default, notthing special - SEEN = bit::RangeValue::value, // already seen during ResolverUpgrade - IMPOSSIBLE = bit::RangeValue::value // impossible to install + NORMAL = bit::RangeValue::value, // default, notthing special + SEEN = bit::RangeValue::value, // already seen during ResolverUpgrade + IMPOSSIBLE = bit::RangeValue::value // impossible to install }; enum LicenceConfirmedValue @@ -92,15 +102,6 @@ class ResStatus public: - /** Default ctor. */ - ResStatus(); - - /** Ctor setting the initial . */ - ResStatus( bool isInstalled_r ); - - /** Dtor. */ - ~ResStatus(); - /** Debug helper returning the bitfield. * It's save to expose the bitfield, as it can't be used to * recreate a ResStatus. So it is not possible to bypass @@ -369,3 +370,14 @@ class ResStatus private: BitFieldType _bitfield; }; + +#ifdef SWIGPERL5 + + %extend ResStatus { + + bool setToBeInstalledUser() + { + return self->setToBeInstalled(ResStatus::USER); + } + }; +#endif diff --git a/swig/Resolver.i b/swig/Resolver.i new file mode 100644 index 0000000..a83d6bc --- /dev/null +++ b/swig/Resolver.i @@ -0,0 +1,50 @@ +#ifdef SWIGPERL5 + %template(StringList) std::list; +#endif + +class Resolver +{ + public: + Resolver( const ResPool & pool); + virtual ~Resolver(); + bool verifySystem (); + bool verifySystem (bool considerNewHardware); + bool establishPool (void); + bool freshenPool (void); + bool resolvePool (void); + bool resolvePool (bool tryAllPossibilities); + bool resolveDependencies( void ); + void undo( void ); + solver::detail::ResolverContext_Ptr context (void) const; + void doUpgrade( UpgradeStatistics & opt_stats_r ); + std::list problematicUpdateItems( void ) const; + ResolverProblemList problems(); + std::list problemDescription( void ) const; + void applySolutions( const ProblemSolutionList & solutions ); + + Arch architecture() const; + void setArchitecture( const Arch & arch); + void setForceResolve (const bool force); + const bool forceResolve(); + void setPreferHighestVersion (const bool highestVersion); + const bool preferHighestVersion(); + bool transactResObject( ResObject::constPtr robj, bool install = true); + //bool transactResKind( Resolvable::Kind kind ); + void transactReset( ResStatus::TransactByValue causer ); + void addRequire (const Capability & capability); + void addConflict (const Capability & capability); + void setTimeout( int seconds ); + int timeout(); + void setMaxSolverPasses (int count); + int maxSolverPasses (); + bool createSolverTestcase (const std::string & dumpPath = "/var/log/YaST2/solverTestcase"); + const solver::detail::ItemCapKindList isInstalledBy (const PoolItem_Ref item); + const std::list installs (const PoolItem_Ref item); + //const solver::detail::ItemCapKindList installs (const PoolItem_Ref item); + + protected: + + private: + solver::detail::Resolver_Ptr _pimpl; +}; + diff --git a/swig/perl5/CMakeLists.txt b/swig/perl5/CMakeLists.txt new file mode 100644 index 0000000..cfed831 --- /dev/null +++ b/swig/perl5/CMakeLists.txt @@ -0,0 +1,41 @@ +FIND_PACKAGE(Perl REQUIRED) + +EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -e "use Config; print \$Config{cppflags}" OUTPUT_VARIABLE PERL_CXX_FLAGS) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PERL_CXX_FLAGS}") + +EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -e "use Config; print \$Config{archlibexp}" OUTPUT_VARIABLE PERL_LIB_PATH) +SET( PERL_INS_PATH "${PERL_LIB_PATH}" ) +SET( PERL_LIB_PATH "${PERL_LIB_PATH}/CORE" ) + +MESSAGE(STATUS "Perl executable: ${PERL_EXECUTABLE}") +MESSAGE(STATUS "Perl cpp-flags: ${PERL_CXX_FLAGS}") +MESSAGE(STATUS "Perl lib path: ${PERL_LIB_PATH}") + +SET( SWIG_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/zypp_wrap.cxx" ) +SET( SWIG_INPUT "${CMAKE_CURRENT_SOURCE_DIR}/zypp.i" ) + +ADD_CUSTOM_COMMAND ( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zypp_wrap.cxx + COMMAND ${CMAKE_COMMAND} -E echo_append "Creating wrapper code for perl..." + COMMAND ${SWIG_EXECUTABLE} -c++ -perl5 -xmlout ${CMAKE_CURRENT_BINARY_DIR}/parse.xml -o ${CMAKE_CURRENT_BINARY_DIR}/zypp_wrap.cxx -I${ZYPP_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../zypp.i + COMMAND ${CMAKE_COMMAND} -E echo "Done." + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../*.i ${CMAKE_CURRENT_SOURCE_DIR}/*.i +) + +ADD_CUSTOM_TARGET( glue + DEPENDS ${SWIG_OUTPUT} +) + +ADD_LIBRARY( zypp SHARED "${CMAKE_CURRENT_BINARY_DIR}/zypp_wrap.cxx" ) +SET_TARGET_PROPERTIES( zypp PROPERTIES PREFIX "" ) +ADD_DEPENDENCIES( zypp glue ) + +INCLUDE_DIRECTORIES( ${PERL_LIB_PATH} ) +INCLUDE_DIRECTORIES( ${ZYPP_INCLUDE_DIR} ) +TARGET_LINK_LIBRARIES( zypp ${ZYPP_LIBRARY} ) + +INSTALL(TARGETS zypp LIBRARY DESTINATION ${PERL_INS_PATH}) +INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/zypp.pm DESTINATION ${PERL_INS_PATH}) + diff --git a/swig/perl5/perl.i b/swig/perl5/perl.i new file mode 100644 index 0000000..e69de29 diff --git a/swig/zypp.i b/swig/zypp.i index fb88268..121d9a6 100644 --- a/swig/zypp.i +++ b/swig/zypp.i @@ -1,11 +1,17 @@ %module zypp +#ifdef SWIGPERL5 +%{ + #define SWIGPERLHACK + #undef NORMAL +%} +#endif + %{ /* Includes the header in the wrapper code */ #include "zypp/base/PtrTypes.h" #include #include -#include #include #include #include @@ -14,7 +20,10 @@ #include "zypp/ResObject.h" #include "zypp/ResPoolManager.h" #include "zypp/Target.h" -#include "zypp/target/TargetImpl.h" +#ifndef SWIGPERLHACK + #include "zypp/target/TargetImpl.h" + #include "zypp/MediaSetAccess.h" +#endif #include "zypp/TranslatedText.h" #include "zypp/CapFactory.h" #include "zypp/Package.h" @@ -23,8 +32,8 @@ #include "zypp/Repository.h" #include "zypp/RepoManager.h" #include "zypp/repo/RepoType.h" -#include "zypp/MediaSetAccess.h" #include "zypp/TmpPath.h" +#include "zypp/Resolver.h" using namespace boost; using namespace zypp; @@ -33,6 +42,7 @@ using namespace zypp::resfilter; using namespace zypp::filesystem; typedef std::set UrlSet; +typedef std::list StringList; %} %rename("+") "operator+"; @@ -65,9 +75,13 @@ class intrusive_ptr { %include "python/python.i" #endif +#ifdef SWIGPERL5 +%include "std_list.i" +#endif %include "Pathname.i" %include "Url.i" +%include "ResStatus.i" %include "NeedAType.i" %include "Arch.i" %include "ResStore.i" @@ -96,15 +110,18 @@ class intrusive_ptr { %include "Package.i" %include "PublicKey.i" %include "KeyRing.i" -%include "Target.i" -%include "ResStatus.i" +#ifndef SWIGPERL5 + %include "Target.i" + %include "MediaSetAccess.i" +#endif %include "PoolItem.i" %include "ResPool.i" %include "ResPoolManager.i" %include "ZYppCommitPolicy.i" %include "ZYppCommitResult.i" -%include "MediaSetAccess.i" %include "TmpPath.i" +%include "Resolver.i" +%include "ItemCapKind.i" class ZYpp -- 2.7.4