Allow building libzypp with rpm-5 (experimental)
authorMichael Andres <ma@suse.de>
Tue, 23 Jun 2009 11:32:46 +0000 (13:32 +0200)
committerMichael Andres <ma@suse.de>
Tue, 23 Jun 2009 11:32:46 +0000 (13:32 +0200)
CMakeLists.txt
cmake/modules/FindRpm.cmake
zypp/target/rpm/BinHeader.cc
zypp/target/rpm/RpmDb.cc
zypp/target/rpm/RpmHeader.cc
zypp/target/rpm/librpm.h
zypp/target/rpm/librpmDb.cc
zypp/target/rpm/librpmDb.cv3.cc

index 9fb552d..a323ce5 100644 (file)
@@ -52,10 +52,13 @@ ELSE ( NOT RPM_FOUND)
   INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR})
   # fix includes not relative to rpm
   INCLUDE_DIRECTORIES(${RPM_INCLUDE_DIR}/rpm)
-  if (RPM_4_4_LEGACY)
-    MESSAGE( STATUS "Enable rpm 4.4 legacy interface")
-    ADD_DEFINITIONS(-D_RPM_4_4_COMPAT)
-  endif (RPM_4_4_LEGACY)
+  if ( RPM_SUSPECT_VERSION STREQUAL "5.x" )
+       MESSAGE( STATUS "rpm found: enable rpm-4 compat interface." )
+       ADD_DEFINITIONS(-D_RPM_5)
+  elseif ( RPM_SUSPECT_VERSION STREQUAL "4.x" )
+       MESSAGE( STATUS "rpm found: enable rpm-4.4 legacy interface." )
+       ADD_DEFINITIONS(-D_RPM_4_4_COMPAT)
+  endif ( RPM_SUSPECT_VERSION STREQUAL "5.x" )
 ENDIF( NOT RPM_FOUND)
 
 FIND_PACKAGE(Boost REQUIRED)
index e1a9d44..29696e3 100644 (file)
@@ -6,17 +6,33 @@ endif(RPM_INCLUDE_DIR AND RPM_LIBRARY)
 
 set(RPM_LIBRARY)
 set(RPM_INCLUDE_DIR)
-set(RPM_4_4_LEGACY)
 
 FIND_PATH(RPM_INCLUDE_DIR rpm/rpmdb.h
        /usr/include
        /usr/local/include
 )
 
-FIND_PATH(RPM_4_4_LEGACY rpm/rpmlegacy.h
-       ${RPM_INCLUDE_DIR}
-       NO_DEFAULT_PATH
-)
+set(RPM_SUSPECT_VERSION "RPM_SUSPECT_VERSION-NOTFOUND" )
+if ( RPM_INCLUDE_DIR )
+       FIND_PATH(RPM_SUSPECT_VERSION rpm/rpm4compat.h
+               ${RPM_INCLUDE_DIR}
+               NO_DEFAULT_PATH
+       )
+       if ( RPM_SUSPECT_VERSION )
+               set(RPM_SUSPECT_VERSION "5.x" )
+       else ( RPM_SUSPECT_VERSION )
+               FIND_PATH(RPM_SUSPECT_VERSION rpm/rpmlegacy.h
+                       ${RPM_INCLUDE_DIR}
+                       NO_DEFAULT_PATH
+               )
+               if ( RPM_SUSPECT_VERSION )
+                       set(RPM_SUSPECT_VERSION "4.x" )
+               else ( RPM_SUSPECT_VERSION )
+                       set(RPM_SUSPECT_VERSION "4.4" )
+               endif ( RPM_SUSPECT_VERSION )
+       endif ( RPM_SUSPECT_VERSION )
+endif ( RPM_INCLUDE_DIR )
+
 
 FIND_LIBRARY(RPM_LIBRARY NAMES rpm
        PATHS
@@ -25,10 +41,7 @@ FIND_LIBRARY(RPM_LIBRARY NAMES rpm
 )
 
 if(RPM_INCLUDE_DIR AND RPM_LIBRARY)
-   MESSAGE( STATUS "rpm found: includes in ${RPM_INCLUDE_DIR}, library in ${RPM_LIBRARY}")
-   if ( RPM_4_4_LEGACY )
-     MESSAGE( STATUS "rpm provides 4.4 legacy interface")
-   endif ( RPM_4_4_LEGACY )
+   MESSAGE( STATUS "rpm found: includes in ${RPM_INCLUDE_DIR}, library in ${RPM_LIBRARY} (suspect ${RPM_SUSPECT_VERSION})")
    set(RPM_FOUND TRUE)
 else(RPM_INCLUDE_DIR AND RPM_LIBRARY)
    MESSAGE( STATUS "rpm not found")
index 73dc748..e9ad382 100644 (file)
 #include "librpm.h"
 extern "C"
 {
+#ifdef _RPM_5
+#undef RPM_NULL_TYPE
+#define RPM_NULL_TYPE rpmTagType(0)
+#endif
+
 #ifndef _RPM_4_4_COMPAT
+#ifdef _RPM_5
+typedef rpmuint32_t rpm_count_t;
+#else
 typedef int32_t rpm_count_t;
 #endif
+#endif
 }
 
 #include <iostream>
@@ -59,8 +68,10 @@ int BinHeader::intList::operator[]( const unsigned idx_r ) const
   {
     switch ( type )
     {
+#if RPM_CHAR_TYPE != RPM_INT8_TYPE
     case RPM_CHAR_TYPE:
       return ((char*)val)[idx_r];
+#endif
     case RPM_INT8_TYPE:
       return ((int8_t*)val)[idx_r];
     case RPM_INT16_TYPE:
@@ -120,7 +131,7 @@ BinHeader::BinHeader( Header h_r )
 {
   if ( _h )
   {
-    ::headerLink( _h );
+    headerLink( _h );
   }
 }
 
@@ -155,7 +166,7 @@ BinHeader::~BinHeader()
 {
   if ( _h )
   {
-    ::headerFree( _h );
+    headerFree( _h );
   }
 }
 
@@ -215,7 +226,9 @@ unsigned BinHeader::int_list( tag tag_r, intList & lst_r ) const
       {
       case RPM_NULL_TYPE:
         return lst_r.set( 0, 0, type );
+#if RPM_CHAR_TYPE != RPM_INT8_TYPE
       case RPM_CHAR_TYPE:
+#endif
       case RPM_INT8_TYPE:
       case RPM_INT16_TYPE:
       case RPM_INT32_TYPE:
@@ -289,8 +302,10 @@ int BinHeader::int_val( tag tag_r ) const
       {
       case RPM_NULL_TYPE:
         return 0;
+#if RPM_CHAR_TYPE != RPM_INT8_TYPE
       case RPM_CHAR_TYPE:
         return *((char*)val);
+#endif
       case RPM_INT8_TYPE:
         return *((int8_t*)val);
       case RPM_INT16_TYPE:
index a207cf5..c1f4721 100644 (file)
@@ -1646,7 +1646,7 @@ RpmDb::checkPackageResult RpmDb::checkPackage( const Pathname & path_r )
   ::rpmtsSetRootDir( ts, root().asString().c_str() );
   ::rpmtsSetVSFlags( ts, RPMVSF_DEFAULT );
   int res = ::rpmReadPackageFile( ts, fd, path_r.asString().c_str(), NULL );
-  ts = ::rpmtsFree(ts);
+  ts = rpmtsFree(ts);
 
   ::Fclose( fd );
 
index efa588e..78b44b5 100644 (file)
@@ -10,7 +10,7 @@
  *
 */
 #include "librpm.h"
-#ifndef _RPM_4_4_COMPAT
+#if !defined(_RPM_4_4_COMPAT) && !defined(_RPM_5)
 #include <rpm/ugid.h>
 #else
 ////////////////////////////////////////////////////////////////////
@@ -237,7 +237,7 @@ RpmHeader::constPtr RpmHeader::readPackage( const Pathname & path_r,
   Header nh = 0;
   int res = ::rpmReadPackageFile( ts, fd, path_r.asString().c_str(), &nh );
 
-  ts = ::rpmtsFree(ts);
+  ts = rpmtsFree(ts);
 
   ::Fclose( fd );
 
index 430f77e..2d7425d 100644 (file)
 #ifndef ZYPP_TARGET_RPM_LIBRPM_H
 #define ZYPP_TARGET_RPM_LIBRPM_H
 
+#ifdef _RPM_5
+// needs to be outside 'extern "C"'
+#include <rpm/rpm4compat.h>
+#endif // _RPM_5
+
 extern "C"
 {
+#ifdef _RPM_5
+#include <rpm/rpmtag.h>
+#else
 #include <rpm/rpmlib.h>
+#endif // _RPM_5
+
 #include <rpm/rpmmacro.h>
 #include <rpm/rpmdb.h>
 #include <rpm/rpmts.h>
index 7f72999..738107c 100644 (file)
@@ -455,13 +455,12 @@ unsigned librpmDb::size() const
   unsigned count = 0;
   if ( valid() )
   {
-#ifdef _RPM_4_4_COMPAT
+#if defined(_RPM_4_4_COMPAT) || defined(_RPM_5)
     // looks like rpm-4.7 has no public dbi interface anymore
     int dbi = ::rpmdbOpen("/", &_d._db, O_RDONLY, 0);
     if (dbi == 0) {
         rpmdbMatchIterator mi = ::rpmdbInitIterator(_d._db, RPMTAG_NAME, NULL, 0);
         if (mi != NULL) {
-            rpmtd item;
             for (;;) {
                 Header rpmHeader = ::rpmdbNextIterator(mi);
                 if (rpmHeader != NULL)
index cc353ff..630bf11 100644 (file)
@@ -9,13 +9,24 @@
 /** \file zypp/target/rpm/librpmDb.cv3.cc
  *
 */
-
 #include "librpm.h"
 extern "C"
 {
 #ifndef _RPM_4_4_COMPAT
+#ifdef _RPM_5
+typedef rpmuint32_t rpm_count_t;
+#else
 typedef int32_t rpm_count_t;
 #endif
+#endif
+
+#ifdef _RPM_5
+#define HGEPtr_t void *
+#define headerGetEntryMinMemory headerGetEntry
+#define headerNVR(h,n,v,r) headerNEVRA(h,n,NULL,v,r,NULL)
+#else
+#define HGEPtr_t const void *
+#endif
 }
 
 #include <iostream>
@@ -162,17 +173,13 @@ static int dncmp(const void * a, const void * b)
 static void compressFilelist(Header h)
 /*@*/
 {
-  HGE_t hge = (HGE_t)headerGetEntryMinMemory;
-  HAE_t hae = (HAE_t)headerAddEntry;
-  HRE_t hre = (HRE_t)headerRemoveEntry;
-  HFD_t hfd = headerFreeData;
   char ** fileNames;
   const char ** dirNames;
   const char ** baseNames;
   int_32 * dirIndexes;
   rpmTagType fnt;
   rpm_count_t count;
-  int i, xx;
+  int xx;
   int dirIndex = -1;
 
   /*
@@ -183,12 +190,12 @@ static void compressFilelist(Header h)
 
   if (headerIsEntry(h, RPMTAG_DIRNAMES))
   {
-    xx = hre(h, RPMTAG_OLDFILENAMES);
+    xx = headerRemoveEntry(h, RPMTAG_OLDFILENAMES);
     return;            /* Already converted. */
   }
 
-  void *hgePtr = NULL;
-  if (!hge(h, RPMTAG_OLDFILENAMES, &fnt, &hgePtr, &count))
+  HGEPtr_t hgePtr = NULL;
+  if (!headerGetEntryMinMemory(h, RPMTAG_OLDFILENAMES, hTYP_t(&fnt), &hgePtr, &count))
     return;            /* no file list */
   fileNames = (char **)hgePtr;
   if (fileNames == NULL || count <= 0)
@@ -203,7 +210,7 @@ static void compressFilelist(Header h)
     /* HACK. Source RPM, so just do things differently */
     dirIndex = 0;
     dirNames[dirIndex] = "";
-    for (i = 0; i < count; i++)
+    for (rpm_count_t i = 0; i < count; i++)
     {
       dirIndexes[i] = dirIndex;
       baseNames[i] = fileNames[i];
@@ -212,7 +219,7 @@ static void compressFilelist(Header h)
   }
 
   /*@-branchstate@*/
-  for (i = 0; i < count; i++)
+  for (rpm_count_t i = 0; i < count; i++)
   {
     const char ** needle;
     char savechar;
@@ -248,16 +255,16 @@ static void compressFilelist(Header h)
 exit:
   if (count > 0)
   {
-    xx = hae(h, RPMTAG_DIRINDEXES, RPM_INT32_TYPE, dirIndexes, count);
-    xx = hae(h, RPMTAG_BASENAMES, RPM_STRING_ARRAY_TYPE,
+    xx = headerAddEntry(h, RPMTAG_DIRINDEXES, RPM_INT32_TYPE, dirIndexes, count);
+    xx = headerAddEntry(h, RPMTAG_BASENAMES, RPM_STRING_ARRAY_TYPE,
              baseNames, count);
-    xx = hae(h, RPMTAG_DIRNAMES, RPM_STRING_ARRAY_TYPE,
+    xx = headerAddEntry(h, RPMTAG_DIRNAMES, RPM_STRING_ARRAY_TYPE,
              dirNames, dirIndex + 1);
   }
 
-  fileNames = (char**)hfd(fileNames, fnt);
+  fileNames = (char**)headerFreeData(fileNames, fnt);
 
-  xx = hre(h, RPMTAG_OLDFILENAMES);
+  xx = headerRemoveEntry(h, RPMTAG_OLDFILENAMES);
 }
 /*@=bounds@*/
 
@@ -267,10 +274,8 @@ exit:
  */
 void providePackageNVR(Header h)
 {
-  HGE_t hge = (HGE_t)headerGetEntryMinMemory;
-  HFD_t hfd = headerFreeData;
   const char *name, *version, *release;
-  void *hgePtr = NULL;
+  HGEPtr_t hgePtr = NULL;
   int_32 * epoch;
   const char *pEVR;
   char *p;
@@ -280,7 +285,7 @@ void providePackageNVR(Header h)
   rpmTagType pnt, pvt;
   int_32 * provideFlags = NULL;
   rpm_count_t providesCount;
-  int i, xx;
+  int xx;
   int bingo = 1;
 
   /* Generate provides for this package name-version-release. */
@@ -289,7 +294,7 @@ void providePackageNVR(Header h)
     return;
   pEVR = p = (char *)alloca(21 + strlen(version) + 1 + strlen(release) + 1);
   *p = '\0';
-  if (hge(h, RPMTAG_EPOCH, NULL, &hgePtr, NULL))
+  if (headerGetEntryMinMemory(h, RPMTAG_EPOCH, NULL, &hgePtr, NULL))
   {
     epoch = (int_32 *)hgePtr;
     sprintf(p, "%d:", *epoch);
@@ -302,17 +307,17 @@ void providePackageNVR(Header h)
    * Rpm prior to 3.0.3 does not have versioned provides.
    * If no provides at all are available, we can just add.
    */
-  if (!hge(h, RPMTAG_PROVIDENAME, &pnt, &hgePtr, &providesCount))
+  if (!headerGetEntryMinMemory(h, RPMTAG_PROVIDENAME, hTYP_t(&pnt), &hgePtr, &providesCount))
     goto exit;
   provides = (const char **)hgePtr;
 
   /*
    * Otherwise, fill in entries on legacy packages.
    */
-  if (!hge(h, RPMTAG_PROVIDEVERSION, &pvt, &hgePtr, NULL))
+  if (!headerGetEntryMinMemory(h, RPMTAG_PROVIDEVERSION, hTYP_t(&pvt), &hgePtr, NULL))
   {
     providesEVR = (const char **)hgePtr;
-    for (i = 0; i < providesCount; i++)
+    for (rpm_count_t i = 0; i < providesCount; i++)
     {
       const char * vdummy = "";
       int_32 fdummy = RPMSENSE_ANY;
@@ -324,12 +329,12 @@ void providePackageNVR(Header h)
     goto exit;
   }
 
-  xx = hge(h, RPMTAG_PROVIDEFLAGS, NULL, &hgePtr, NULL);
+  xx = headerGetEntryMinMemory(h, RPMTAG_PROVIDEFLAGS, NULL, &hgePtr, NULL);
   provideFlags = (int_32 *)hgePtr;
 
   /*@-nullderef@*/    /* LCL: providesEVR is not NULL */
   if (provides && providesEVR && provideFlags)
-    for (i = 0; i < providesCount; i++)
+    for (rpm_count_t i = 0; i < providesCount; i++)
     {
       if (!(provides[i] && providesEVR[i]))
         continue;
@@ -342,8 +347,8 @@ void providePackageNVR(Header h)
   /*@=nullderef@*/
 
 exit:
-  provides = (const char **)hfd(provides, pnt);
-  providesEVR = (const char **)hfd(providesEVR, pvt);
+  provides = (const char **)headerFreeData(provides, pnt);
+  providesEVR = (const char **)headerFreeData(providesEVR, pvt);
 
   if (bingo)
   {
@@ -499,7 +504,11 @@ void internal_convertV3toV4( const Pathname & v3db_r, const librpmDb::constPtr &
       continue;
     }
     rpmdbFreeIterator(mi);
+#ifdef _RPM_5
+    if (rpmdbAdd(db, -1, h, 0))
+#else
     if (rpmdbAdd(db, -1, h, 0, 0))
+#endif
     {
 //      report.dbWriteError( nrv );
       proceed = false;//CBSuggest::CANCEL; // immediately stop loop