Brad,

I began working on backporting my previous cmCPackArchiveGenerator component
support to redesigned CPackAPI **and** the use of libarchive-wrapper (step3).

The current libarchive-wrapper is missing:
   - support for ZIP archive which is needed
   - support for LZMA compression which not needed since not used

Those change would bring the same features set as the current
cmCPackArchiveGenerator
which does not rely on libarchive-wrapper but directly calls libarchive.

This is the first patch.

I added a second patch for support for XZ compression because
when we are at it, this does not cost much and will bring more
compression options
as soon as CMAKE_USE_SYSTEM_LIBARCHIVE is ON.

This may help to solve this bug afterwards:
see eg: http://public.kitware.com/Bug/view.php?id=11040

As you will see I added some mysterious changes directly coming
from the current cmCPackArchiveGenerator.cxx.
Most notably:

#if !defined(_WIN32) || defined(__CYGWIN__)
  if (archive_read_disk_set_standard_lookup(this->Disk) != ARCHIVE_OK)
    {
    this->Error = "archive_read_disk_set_standard_lookup: ";
    this->Error += archive_error_string(this->Archive);
    return;;
    }
#endif

which wasn't conditional before. Since the call has no error check before
it may have been failing silently on _WIN32 and __CYGWIN....?

Other thing I just "copy/paste" was the 'not padding last block thing':

  // do not pad the last block!!
  if (archive_write_set_bytes_in_last_block(this->Archive, 1))
    {
    this->Error = "archive_write_set_format_pax_restricted: ";
    this->Error += archive_error_string(this->Archive);
    return;
    }

Even with those changes the whole CMake testsuite is ok.
(obviously I miss some Win32 / Cygwin tests).

Now that I am fully aware of "stage" I may push those to your
libarchive-wrapper stage if you want.

May not be tonight because it's getting late :-]

-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
From 1c97d10c332d2bad205d3170b6bd170de83a6f0c Mon Sep 17 00:00:00 2001
From: Eric NOULARD <[email protected]>
Date: Thu, 12 Aug 2010 23:06:11 +0200
Subject: [PATCH 1/2] Add ZIP archive format and LZMA compress support to libarchive-wrapper

This will be needed to use cmArchiveWrire in cmCPackArchiveGenerator
with the same feature set as before. Note that adding zip
support to libarchive-wrapper would also makes it easy to add
a new -E zip command to cmake commands.

Signed-off-by: Eric NOULARD <[email protected]>
---
 Source/cmArchiveWrite.cxx |   42 +++++++++++++++++++++++++++++++++++++++---
 Source/cmArchiveWrite.h   |   12 ++++++++++--
 Source/cmSystemTools.cxx  |    3 ++-
 3 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx
index 88874aa..df20e4a 100644
--- a/Source/cmArchiveWrite.cxx
+++ b/Source/cmArchiveWrite.cxx
@@ -47,7 +47,7 @@ struct cmArchiveWrite::Callback
 };
 
 //----------------------------------------------------------------------------
-cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c):
+cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, Type t):
   Stream(os),
   Archive(archive_write_new()),
   Disk(archive_read_disk_new()),
@@ -79,9 +79,45 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c):
         return;
         }
       break;
+    case CompressLZMA:
+      if(archive_write_set_compression_lzma(this->Archive) != ARCHIVE_OK)
+        {
+        this->Error = "archive_write_set_compression_lzma: ";
+        this->Error += archive_error_string(this->Archive);
+        return;
+        }
+      break;
     };
-  archive_read_disk_set_standard_lookup(this->Disk);
-  if(archive_write_set_format_pax_restricted(this->Archive) != ARCHIVE_OK)
+#if !defined(_WIN32) || defined(__CYGWIN__)
+  if (archive_read_disk_set_standard_lookup(this->Disk) != ARCHIVE_OK)
+    {
+    this->Error = "archive_read_disk_set_standard_lookup: ";
+    this->Error += archive_error_string(this->Archive);
+    return;;
+    }
+#endif
+  switch (t)
+    {
+    case TypeZIP:
+      if(archive_write_set_format_zip(this->Archive) != ARCHIVE_OK)
+        {
+        this->Error = "archive_write_set_format_zip: ";
+        this->Error += archive_error_string(this->Archive);
+        return;
+        }
+      break;
+    case TypeTAR:
+      if(archive_write_set_format_pax_restricted(this->Archive) != ARCHIVE_OK)
+        {
+        this->Error = "archive_write_set_format_pax_restricted: ";
+        this->Error += archive_error_string(this->Archive);
+        return;
+        }
+    break;
+    }
+
+  // do not pad the last block!!
+  if (archive_write_set_bytes_in_last_block(this->Archive, 1))
     {
     this->Error = "archive_write_set_format_pax_restricted: ";
     this->Error += archive_error_string(this->Archive);
diff --git a/Source/cmArchiveWrite.h b/Source/cmArchiveWrite.h
index 92c0c73..0bd3e9b 100644
--- a/Source/cmArchiveWrite.h
+++ b/Source/cmArchiveWrite.h
@@ -32,11 +32,19 @@ public:
   {
     CompressNone,
     CompressGZip,
-    CompressBZip2
+    CompressBZip2,
+    CompressLZMA
+  };
+
+  /** Archive Type */
+  enum Type
+  {
+    TypeTAR,
+    TypeZIP
   };
 
   /** Construct with output stream to which to write archive.  */
-  cmArchiveWrite(std::ostream& os, Compress c = CompressNone);
+  cmArchiveWrite(std::ostream& os, Compress c = CompressNone, Type = TypeTAR);
   ~cmArchiveWrite();
 
   /**
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index a26452c..0e0a770 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -1732,7 +1732,8 @@ bool cmSystemTools::CreateTar(const char* outFileName,
     }
   cmArchiveWrite a(fout, (gzip? cmArchiveWrite::CompressGZip :
                           (bzip2? cmArchiveWrite::CompressBZip2 :
-                           cmArchiveWrite::CompressNone)));
+                           cmArchiveWrite::CompressNone)),
+                           cmArchiveWrite::TypeTAR);
   a.SetVerbose(verbose);
   for(std::vector<cmStdString>::const_iterator i = files.begin();
       i != files.end(); ++i)
-- 
1.7.1

From 5e3935bb85f6b9b26c26644837d3251895064b8b Mon Sep 17 00:00:00 2001
From: Eric NOULARD <[email protected]>
Date: Thu, 12 Aug 2010 23:18:37 +0200
Subject: [PATCH 2/2] Add XZ compress support to libarchive-wrapper

This is not needed but it does not cost much to do it for all
potentially supported format in libarchive. XZ and LZMA are not
builtin libarchive and require external lib but if
CMAKE_USE_SYSTEM_LIBARCHIVE is ON then we may get it for free.

Signed-off-by: Eric NOULARD <[email protected]>
---
 Source/cmArchiveWrite.cxx |    8 ++++++++
 Source/cmArchiveWrite.h   |    3 ++-
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx
index df20e4a..e30bf2d 100644
--- a/Source/cmArchiveWrite.cxx
+++ b/Source/cmArchiveWrite.cxx
@@ -87,6 +87,14 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, Type t):
         return;
         }
       break;
+    case CompressXZ:
+      if(archive_write_set_compression_xz(this->Archive) != ARCHIVE_OK)
+        {
+        this->Error = "archive_write_set_compression_xz: ";
+        this->Error += archive_error_string(this->Archive);
+        return;
+        }
+      break;
     };
 #if !defined(_WIN32) || defined(__CYGWIN__)
   if (archive_read_disk_set_standard_lookup(this->Disk) != ARCHIVE_OK)
diff --git a/Source/cmArchiveWrite.h b/Source/cmArchiveWrite.h
index 0bd3e9b..ce7f961 100644
--- a/Source/cmArchiveWrite.h
+++ b/Source/cmArchiveWrite.h
@@ -33,7 +33,8 @@ public:
     CompressNone,
     CompressGZip,
     CompressBZip2,
-    CompressLZMA
+    CompressLZMA,
+    CompressXZ
   };
 
   /** Archive Type */
-- 
1.7.1

_______________________________________________
cmake-developers mailing list
[email protected]
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Reply via email to