[cmake-commits] hoffman committed cmCPackNSISGenerator.cxx 1.13.2.3 1.13.2.4 cmCPackTarCompressGenerator.cxx 1.3.2.2 1.3.2.3 cmCPackTarCompressGenerator.h 1.2.2.1 1.2.2.2 cmCPackZIPGenerator.cxx 1.2.2.2 1.2.2.3 cpack.cxx 1.16.2.4 1.16.2.5

cmake-commits at cmake.org cmake-commits at cmake.org
Fri Oct 13 10:52:09 EDT 2006


Update of /cvsroot/CMake/CMake/Source/CPack
In directory public:/mounts/ram/cvs-serv31017/Source/CPack

Modified Files:
      Tag: CMake-2-4
	cmCPackNSISGenerator.cxx cmCPackTarCompressGenerator.cxx 
	cmCPackTarCompressGenerator.h cmCPackZIPGenerator.cxx 
	cpack.cxx 
Log Message:
ENH: merge changes from the main tree to the 2.4 branch


Index: cmCPackZIPGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CPack/cmCPackZIPGenerator.cxx,v
retrieving revision 1.2.2.2
retrieving revision 1.2.2.3
diff -u -d -r1.2.2.2 -r1.2.2.3
--- cmCPackZIPGenerator.cxx	11 May 2006 14:33:21 -0000	1.2.2.2
+++ cmCPackZIPGenerator.cxx	13 Oct 2006 14:52:07 -0000	1.2.2.3
@@ -91,20 +91,22 @@
   const char* toplevel, const std::vector<std::string>& files)
 {
   std::string tempFileName;
+  tempFileName = toplevel;
+  tempFileName += "/winZip.filelist";
+  bool needQuotesInFile = false;
   cmOStringStream dmgCmd;
   switch ( this->ZipStyle )
     {
   case cmCPackZIPGenerator::StyleWinZip:
-    tempFileName = toplevel;
-    tempFileName += "/winZip.filelist";
     dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
       << "\" -P \"" << outFileName
-           << "\" @\"" << tempFileName.c_str() << "\"";
+           << "\" @winZip.filelist";
+    needQuotesInFile = true;
     break;
   case cmCPackZIPGenerator::StyleUnixZip:
     dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
-      << "\" \"" << outFileName
-      << "\"";
+      << "\" -r \"" << outFileName
+      << "\" . -i at winZip.filelist";
     break;
   default:
     cmCPackLogger(cmCPackLog::LOG_ERROR, "Unknown ZIP style"
@@ -117,9 +119,16 @@
     std::vector<std::string>::const_iterator fileIt;
     for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
       {
-      out << "\""
-          << cmSystemTools::RelativePath(toplevel, fileIt->c_str())
-          << "\"" << std::endl;
+      if ( needQuotesInFile )
+        {
+        out << "\"";
+        }
+      out << cmSystemTools::RelativePath(toplevel, fileIt->c_str());
+      if ( needQuotesInFile )
+        {
+        out << "\"";
+        }
+      out << std::endl;
       }
     }
   else

Index: cpack.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CPack/cpack.cxx,v
retrieving revision 1.16.2.4
retrieving revision 1.16.2.5
diff -u -d -r1.16.2.4 -r1.16.2.5
--- cpack.cxx	24 Jul 2006 15:19:36 -0000	1.16.2.4
+++ cpack.cxx	13 Oct 2006 14:52:07 -0000	1.16.2.5
@@ -308,6 +308,8 @@
         "CPack generator not specified" << std::endl);
       parsed = 0;
       }
+    else
+      {
     std::vector<std::string> generatorsVector;
     cmSystemTools::ExpandListArgument(genList,
       generatorsVector);
@@ -370,6 +372,47 @@
             << std::endl);
           parsed = 0;
         }
+            if ( parsed )
+              {
+#ifdef _WIN32
+              std::string comspec = "cmw9xcom.exe";
+              cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
+#endif
+
+              const char* projName = mf->GetDefinition("CPACK_PACKAGE_NAME");
+              cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Use generator: "
+                << cpackGenerator->GetNameOfClass() << std::endl);
+              cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "For project: "
+                << projName << std::endl);
+  
+              const char* projVersion = 
+                mf->GetDefinition("CPACK_PACKAGE_VERSION");
+              if ( !projVersion )
+                {
+                const char* projVersionMajor
+                  = mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR");
+                const char* projVersionMinor
+                  = mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR");
+                const char* projVersionPatch
+                  = mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH");
+                cmOStringStream ostr;
+                ostr << projVersionMajor << "." << projVersionMinor << "."
+                  << projVersionPatch;
+                mf->AddDefinition("CPACK_PACKAGE_VERSION", 
+                                  ostr.str().c_str());
+                }
+  
+              int res = cpackGenerator->ProcessGenerator();
+              if ( !res )
+                {
+                cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
+                  "Error when generating package: " << projName << std::endl);
+                return 1;
+                }
+              }
+            }
+          }
+        }
       }
     }
 
@@ -405,41 +448,6 @@
 #define cout no_cout_use_cmCPack_Log
     }
 
-#ifdef _WIN32
-  std::string comspec = "cmw9xcom.exe";
-  cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
-#endif
-
-  const char* projName = mf->GetDefinition("CPACK_PACKAGE_NAME");
-  cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Use generator: "
-    << cpackGenerator->GetNameOfClass() << std::endl);
-  cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "For project: "
-    << projName << std::endl);
-
-  const char* projVersion = mf->GetDefinition("CPACK_PACKAGE_VERSION");
-  if ( !projVersion )
-    {
-    const char* projVersionMajor
-      = mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR");
-    const char* projVersionMinor
-      = mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR");
-    const char* projVersionPatch
-      = mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH");
-    cmOStringStream ostr;
-    ostr << projVersionMajor << "." << projVersionMinor << "."
-      << projVersionPatch;
-    mf->AddDefinition("CPACK_PACKAGE_VERSION", ostr.str().c_str());
-    }
-
-  int res = cpackGenerator->ProcessGenerator();
-  if ( !res )
-    {
-    cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
-      "Error when generating package: " << projName << std::endl);
-    return 1;
-        }
-      }
-    }
 
   return 0;
 }

Index: cmCPackNSISGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CPack/cmCPackNSISGenerator.cxx,v
retrieving revision 1.13.2.3
retrieving revision 1.13.2.4
diff -u -d -r1.13.2.3 -r1.13.2.4
--- cmCPackNSISGenerator.cxx	14 May 2006 19:22:47 -0000	1.13.2.3
+++ cmCPackNSISGenerator.cxx	13 Oct 2006 14:52:06 -0000	1.13.2.4
@@ -248,7 +248,7 @@
     if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".") &&
         strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)),".."))
       {
-      kwsys_stl::string fullPath = topdir;
+      cmsys_stl::string fullPath = topdir;
       fullPath += "/";
       fullPath += dir.GetFile(static_cast<unsigned long>(fileNum));
       if(cmsys::SystemTools::FileIsDirectory(fullPath.c_str()) &&

Index: cmCPackTarCompressGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CPack/cmCPackTarCompressGenerator.cxx,v
retrieving revision 1.3.2.2
retrieving revision 1.3.2.3
diff -u -d -r1.3.2.2 -r1.3.2.3
--- cmCPackTarCompressGenerator.cxx	14 May 2006 19:22:47 -0000	1.3.2.2
+++ cmCPackTarCompressGenerator.cxx	13 Oct 2006 14:52:06 -0000	1.3.2.3
@@ -26,19 +26,25 @@
 #include "cmCPackLog.h"
 
 #include <cmsys/SystemTools.hxx>
+#include <cmcompress/cmcompress.h>
+#include <libtar/libtar.h>
+#include <memory> // auto_ptr
+#include <fcntl.h>
+#include <errno.h>
 
-// Includes needed for implementation of RenameFile.  This is not in
-// system tools because it is not implemented robustly enough to move
-// files across directories.
-#ifdef _WIN32
-# include <windows.h>
-# include <sys/stat.h>
-#endif
+//----------------------------------------------------------------------
+class cmCPackTarCompressGeneratorForward
+{
+public:
+  static int GenerateHeader(cmCPackTarCompressGenerator* gg, std::ostream* os)
+    {
+    return gg->GenerateHeader(os);
+    }
+};
 
 //----------------------------------------------------------------------
 cmCPackTarCompressGenerator::cmCPackTarCompressGenerator()
 {
-  this->Compress = false;
 }
 
 //----------------------------------------------------------------------
@@ -47,123 +53,192 @@
 }
 
 //----------------------------------------------------------------------
-int cmCPackTarCompressGenerator::InitializeInternal()
+class cmCPackTarCompress_Data
 {
-  this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
-  std::vector<std::string> path;
-  std::string pkgPath = cmSystemTools::FindProgram("compress", path, false);
-  if ( pkgPath.empty() )
-    {
-    cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find Compress" << std::endl);
-    return 0;
-    }
-  this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
-  cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found Compress program: "
-    << pkgPath.c_str()
-    << std::endl);
+public:
+  cmCPackTarCompress_Data(cmCPackTarCompressGenerator* gen) :
+    OutputStream(0), Generator(gen) {}
+  std::ostream* OutputStream;
+  cmCPackTarCompressGenerator* Generator;
+  cmcompress_stream CMCompressStream;
+};
 
-  return this->Superclass::InitializeInternal();
+//----------------------------------------------------------------------
+extern "C" {
+  // For cmTar
+  int cmCPackTarCompress_Data_Open(void *client_data, const char* name,
+    int oflags, mode_t mode);
+  ssize_t cmCPackTarCompress_Data_Write(void *client_data, void *buff,
+    size_t n);
+  int cmCPackTarCompress_Data_Close(void *client_data);
+
+  // For cmCompress
+  int cmCPackTarCompress_Compress_Output(void* cdata, const char* data,
+    int len);
 }
 
+
 //----------------------------------------------------------------------
-int cmCPackTarCompressGenerator::CompressFiles(const char* outFileName,
-  const char* toplevel, const std::vector<std::string>& files)
+int cmCPackTarCompress_Data_Open(void *client_data, const char* pathname,
+  int, mode_t)
 {
-  std::string packageDirFileName
-    = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
-  packageDirFileName += ".tar";
-  std::string output;
-  int retVal = -1;
-  if ( !this->Superclass::CompressFiles(packageDirFileName.c_str(), 
-                                        toplevel, files) )
+  cmCPackTarCompress_Data *mydata = (cmCPackTarCompress_Data*)client_data;
+
+  if ( !cmcompress_compress_initialize(&mydata->CMCompressStream) )
     {
-    return 0;
+    return -1;
     }
 
-  cmOStringStream dmgCmd1;
-  dmgCmd1 << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
-    << "\" \"" << packageDirFileName
-    << "\"";
-  retVal = -1;
-  int res = cmSystemTools::RunSingleCommand(dmgCmd1.str().c_str(), &output,
-    &retVal, toplevel, this->GeneratorVerbose, 0);
-  if ( !res || retVal )
+  mydata->CMCompressStream.client_data = mydata;
+  mydata->CMCompressStream.output_stream = cmCPackTarCompress_Compress_Output;
+
+  cmGeneratedFileStream* gf = new cmGeneratedFileStream;
+  // Open binary
+  gf->Open(pathname, false, true);
+  mydata->OutputStream = gf;
+  if ( !*mydata->OutputStream )
     {
-    std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
-    tmpFile += "/CompressCompress.log";
-    cmGeneratedFileStream ofs(tmpFile.c_str());
-    ofs << "# Run command: " << dmgCmd1.str().c_str() << std::endl
-      << "# Output:" << std::endl
-      << output.c_str() << std::endl;
-    cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running Compress command: "
-      << dmgCmd1.str().c_str() << std::endl
-      << "Please check " << tmpFile.c_str() << " for errors" << std::endl);
-    return 0;
+    return -1;
     }
 
-  std::string compressOutFile = packageDirFileName + ".Z";
-  if ( !cmSystemTools::SameFile(compressOutFile.c_str(), outFileName ) )
+  if ( !cmcompress_compress_start(&mydata->CMCompressStream) )
     {
-    if ( !this->RenameFile(compressOutFile.c_str(), outFileName) )
-      {
-      cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem renaming: \""
-        << compressOutFile.c_str() << "\" to \""
-        << outFileName << std::endl);
-      return 0;
+    return -1;
       }
+
+
+  if ( !cmCPackTarCompressGeneratorForward::GenerateHeader(
+      mydata->Generator,gf))
+    {
+    return -1;
     }
 
-  return 1;
+  return 0;
 }
 
-//----------------------------------------------------------------------------
-int cmCPackTarCompressGenerator::RenameFile(const char* oldname,
-                                          const char* newname)
+//----------------------------------------------------------------------
+ssize_t cmCPackTarCompress_Data_Write(void *client_data, void *buff, size_t n)
 {
-#ifdef _WIN32
-  /* On Windows the move functions will not replace existing files.
-     Check if the destination exists.  */
-  struct stat newFile;
-  if(stat(newname, &newFile) == 0)
+  cmCPackTarCompress_Data *mydata = (cmCPackTarCompress_Data*)client_data;
+
+  if ( !cmcompress_compress(&mydata->CMCompressStream, buff, n) )
     {
-    /* The destination exists.  We have to replace it carefully.  The
-       MoveFileEx function does what we need but is not available on
-       Win9x.  */
-    OSVERSIONINFO osv;
-    DWORD attrs;
+    return 0;
+    }
+  return n;
+}
 
-    /* Make sure the destination is not read only.  */
-    attrs = GetFileAttributes(newname);
-    if(attrs & FILE_ATTRIBUTE_READONLY)
+//----------------------------------------------------------------------
+int cmCPackTarCompress_Data_Close(void *client_data)
+{
+  cmCPackTarCompress_Data *mydata = (cmCPackTarCompress_Data*)client_data;
+
+  if ( !cmcompress_compress_finalize(&mydata->CMCompressStream) )
       {
-      SetFileAttributes(newname, attrs & ~FILE_ATTRIBUTE_READONLY);
+    delete mydata->OutputStream;
+    return -1;
       }
 
-    /* Check the windows version number.  */
-    osv.dwOSVersionInfoSize = sizeof(osv);
-    GetVersionEx(&osv);
-    if(osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
+  delete mydata->OutputStream;
+  mydata->OutputStream = 0;
+  return (0);
+}
+
+//----------------------------------------------------------------------
+int cmCPackTarCompressGenerator::InitializeInternal()
+{
+  this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
+  return this->Superclass::InitializeInternal();
+}
+
+//----------------------------------------------------------------------
+int cmCPackTarCompressGenerator::CompressFiles(const char* outFileName,
+  const char* toplevel, const std::vector<std::string>& files)
+{
+  cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl);
+  cmCPackTarCompress_Data mydata(this);
+  TAR *t;
+  char buf[TAR_MAXPATHLEN];
+  char pathname[TAR_MAXPATHLEN];
+
+  tartype_t compressType = {
+    (openfunc_t)cmCPackTarCompress_Data_Open,
+    (closefunc_t)cmCPackTarCompress_Data_Close,
+    (readfunc_t)0,
+    (writefunc_t)cmCPackTarCompress_Data_Write,
+    &mydata
+  };
+
+  // Ok, this libtar is not const safe. for now use auto_ptr hack
+  char* realName = new char[ strlen(outFileName) + 1 ];
+  std::auto_ptr<char> realNamePtr(realName);
+  strcpy(realName, outFileName);
+  int flags = O_WRONLY | O_CREAT;
+  if (tar_open(&t, realName,
+      &compressType,
+      flags, 0644,
+      (this->GeneratorVerbose?TAR_VERBOSE:0)
+      | 0) == -1)
       {
-      /* This is Win9x.  There is no MoveFileEx implementation.  We
-         cannot quite rename the file atomically.  Just delete the
-         destination and then move the file.  */
-      DeleteFile(newname);
-      return MoveFile(oldname, newname);
+    cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem with tar_open(): "
+      << strerror(errno) << std::endl);
+    return 0;
       }
-    else
+
+  std::vector<std::string>::const_iterator fileIt;
+  for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
       {
-      /* This is not Win9x.  Use the MoveFileEx implementation.  */
-      return MoveFileEx(oldname, newname, MOVEFILE_REPLACE_EXISTING);
+    std::string rp = cmSystemTools::RelativePath(toplevel, fileIt->c_str());
+    strncpy(pathname, fileIt->c_str(), sizeof(pathname));
+    pathname[sizeof(pathname)-1] = 0;
+    strncpy(buf, rp.c_str(), sizeof(buf));
+    buf[sizeof(buf)-1] = 0;
+    if (tar_append_tree(t, pathname, buf) != 0)
+      {
+      cmCPackLogger(cmCPackLog::LOG_ERROR,
+        "Problem with tar_append_tree(\"" << buf << "\", \""
+        << pathname << "\"): "
+        << strerror(errno) << std::endl);
+      tar_close(t);
+      return 0;
       }
     }
-  else
+  if (tar_append_eof(t) != 0)
     {
-    /* The destination does not exist.  Just move the file.  */
-    return MoveFile(oldname, newname);
+    cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem with tar_append_eof(): "
+      << strerror(errno) << std::endl);
+    tar_close(t);
+    return 0;
+      }
+
+  if (tar_close(t) != 0)
+    {
+    cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem with tar_close(): "
+      << strerror(errno) << std::endl);
+    return 0;
     }
-#else
-  /* On UNIX we have an OS-provided call to do this atomically.  */
-  return rename(oldname, newname) == 0;
-#endif
+  return 1;
 }
 
+//----------------------------------------------------------------------
+int cmCPackTarCompress_Compress_Output(void* client_data,
+  const char* data, int data_length)
+{
+  cmcompress_stream *cstream = static_cast<cmcompress_stream*>(client_data);
+  cmCPackTarCompress_Data *mydata
+    = static_cast<cmCPackTarCompress_Data*>(cstream->client_data);
+  mydata->OutputStream->write(data, data_length);
+
+  if ( !mydata->OutputStream )
+    {
+    return 0;
+    }
+  return data_length;
+}
+
+//----------------------------------------------------------------------
+int cmCPackTarCompressGenerator::GenerateHeader(std::ostream* os)
+{
+ (void)os;
+  return 1;
+}

Index: cmCPackTarCompressGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CPack/cmCPackTarCompressGenerator.h,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -u -d -r1.2.2.1 -r1.2.2.2
--- cmCPackTarCompressGenerator.h	7 May 2006 14:55:39 -0000	1.2.2.1
+++ cmCPackTarCompressGenerator.h	13 Oct 2006 14:52:06 -0000	1.2.2.2
@@ -42,6 +42,7 @@
   virtual const char* GetOutputExtension() { return "tar.Z"; }
 
   int RenameFile(const char* oldname, const char* newname);
+  int GenerateHeader(std::ostream* os);
 };
 
 #endif



More information about the Cmake-commits mailing list