diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2006-05-02 21:34:27 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2006-05-02 21:34:27 (GMT) |
commit | 7e788fed35074f0befde72d924621392f020f794 (patch) | |
tree | 09da6e6b4f80dbc48df024f35bc100112b57affb /Source | |
parent | 12e07f910e339fbdfdd4a16c2b6dcf9017e0546b (diff) | |
download | CMake-7e788fed35074f0befde72d924621392f020f794.zip CMake-7e788fed35074f0befde72d924621392f020f794.tar.gz CMake-7e788fed35074f0befde72d924621392f020f794.tar.bz2 |
ENH: Simplify TarCompress to only require compress. Use cmake's tar
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CPack/cmCPackTGZGenerator.cxx | 136 | ||||
-rw-r--r-- | Source/CPack/cmCPackTGZGenerator.h | 2 | ||||
-rw-r--r-- | Source/CPack/cmCPackTarCompressGenerator.cxx | 43 | ||||
-rw-r--r-- | Source/CPack/cmCPackTarCompressGenerator.h | 8 |
4 files changed, 89 insertions, 100 deletions
diff --git a/Source/CPack/cmCPackTGZGenerator.cxx b/Source/CPack/cmCPackTGZGenerator.cxx index 1daaee9..3784a75 100644 --- a/Source/CPack/cmCPackTGZGenerator.cxx +++ b/Source/CPack/cmCPackTGZGenerator.cxx @@ -45,6 +45,7 @@ class cmCPackTGZGeneratorForward //---------------------------------------------------------------------- cmCPackTGZGenerator::cmCPackTGZGenerator() { + this->Compress = true; } //---------------------------------------------------------------------- @@ -58,15 +59,17 @@ static const size_t cmCPackTGZ_Data_BlockSize = 16384; class cmCPackTGZ_Data { public: - cmCPackTGZ_Data(cmCPackTGZGenerator* gen) : + cmCPackTGZ_Data(cmCPackTGZGenerator* gen, bool compress) : OutputStream(0), Generator(gen), - CompressionLevel(Z_DEFAULT_COMPRESSION) {} + CompressionLevel(Z_DEFAULT_COMPRESSION), + Compress(compress) {} std::ostream* OutputStream; cmCPackTGZGenerator* Generator; char CompressedBuffer[cmCPackTGZ_Data_BlockSize]; int CompressionLevel; z_stream ZLibStream; uLong CRC; + bool Compress; }; //---------------------------------------------------------------------- @@ -84,14 +87,17 @@ int cmCPackTGZ_Data_Open(void *client_data, const char* pathname, { cmCPackTGZ_Data *mydata = (cmCPackTGZ_Data*)client_data; - mydata->ZLibStream.zalloc = Z_NULL; - mydata->ZLibStream.zfree = Z_NULL; - mydata->ZLibStream.opaque = Z_NULL; - int strategy = Z_DEFAULT_STRATEGY; - if ( deflateInit2(&mydata->ZLibStream, mydata->CompressionLevel, - Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy) != Z_OK ) + if ( mydata->Compress ) { - return -1; + mydata->ZLibStream.zalloc = Z_NULL; + mydata->ZLibStream.zfree = Z_NULL; + mydata->ZLibStream.opaque = Z_NULL; + int strategy = Z_DEFAULT_STRATEGY; + if ( deflateInit2(&mydata->ZLibStream, mydata->CompressionLevel, + Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy) != Z_OK ) + { + return -1; + } } cmGeneratedFileStream* gf = new cmGeneratedFileStream; @@ -108,7 +114,10 @@ int cmCPackTGZ_Data_Open(void *client_data, const char* pathname, return -1; } - mydata->CRC = crc32(0L, Z_NULL, 0); + if ( mydata->Compress ) + { + mydata->CRC = crc32(0L, Z_NULL, 0); + } return 0; } @@ -118,35 +127,42 @@ ssize_t cmCPackTGZ_Data_Write(void *client_data, void *buff, size_t n) { cmCPackTGZ_Data *mydata = (cmCPackTGZ_Data*)client_data; - mydata->ZLibStream.avail_in = n; - mydata->ZLibStream.next_in = reinterpret_cast<Bytef*>(buff); - - do { - mydata->ZLibStream.avail_out = cmCPackTGZ_Data_BlockSize; - mydata->ZLibStream.next_out - = reinterpret_cast<Bytef*>(mydata->CompressedBuffer); - // no bad return value - int ret = deflate(&mydata->ZLibStream, (n?Z_NO_FLUSH:Z_FINISH)); - if(ret == Z_STREAM_ERROR) + if ( mydata->Compress ) + { + mydata->ZLibStream.avail_in = n; + mydata->ZLibStream.next_in = reinterpret_cast<Bytef*>(buff); + + do { + mydata->ZLibStream.avail_out = cmCPackTGZ_Data_BlockSize; + mydata->ZLibStream.next_out + = reinterpret_cast<Bytef*>(mydata->CompressedBuffer); + // no bad return value + int ret = deflate(&mydata->ZLibStream, (n?Z_NO_FLUSH:Z_FINISH)); + if(ret == Z_STREAM_ERROR) + { + return 0; + } + + size_t compressedSize + = cmCPackTGZ_Data_BlockSize - mydata->ZLibStream.avail_out; + + mydata->OutputStream->write( + reinterpret_cast<const char*>(mydata->CompressedBuffer), + compressedSize); + } while ( mydata->ZLibStream.avail_out == 0 ); + + if ( !*mydata->OutputStream ) { return 0; } - - size_t compressedSize - = cmCPackTGZ_Data_BlockSize - mydata->ZLibStream.avail_out; - - mydata->OutputStream->write( - reinterpret_cast<const char*>(mydata->CompressedBuffer), - compressedSize); - } while ( mydata->ZLibStream.avail_out == 0 ); - - if ( !*mydata->OutputStream ) - { - return 0; + if ( n ) + { + mydata->CRC = crc32(mydata->CRC, reinterpret_cast<Bytef *>(buff), n); + } } - if ( n ) + else { - mydata->CRC = crc32(mydata->CRC, reinterpret_cast<Bytef *>(buff), n); + mydata->OutputStream->write(buff, n); } return n; } @@ -156,23 +172,26 @@ int cmCPackTGZ_Data_Close(void *client_data) { cmCPackTGZ_Data *mydata = (cmCPackTGZ_Data*)client_data; - cmCPackTGZ_Data_Write(client_data, 0, 0); - - char buffer[8]; - int n; - uLong x = mydata->CRC; - for (n = 0; n < 4; n++) { - buffer[n] = (int)(x & 0xff); - x >>= 8; - } - x = mydata->ZLibStream.total_in; - for (n = 0; n < 4; n++) { - buffer[n+4] = (int)(x & 0xff); - x >>= 8; - } - - mydata->OutputStream->write(buffer, 8); - (void)deflateEnd(&mydata->ZLibStream); + if ( mydata->Compress ) + { + cmCPackTGZ_Data_Write(client_data, 0, 0); + + char buffer[8]; + int n; + uLong x = mydata->CRC; + for (n = 0; n < 4; n++) { + buffer[n] = (int)(x & 0xff); + x >>= 8; + } + x = mydata->ZLibStream.total_in; + for (n = 0; n < 4; n++) { + buffer[n+4] = (int)(x & 0xff); + x >>= 8; + } + + mydata->OutputStream->write(buffer, 8); + (void)deflateEnd(&mydata->ZLibStream); + } delete mydata->OutputStream; mydata->OutputStream = 0; return (0); @@ -190,7 +209,7 @@ int cmCPackTGZGenerator::CompressFiles(const char* outFileName, const char* toplevel, const std::vector<std::string>& files) { cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl); - cmCPackTGZ_Data mydata(this); + cmCPackTGZ_Data mydata(this, this->Compress); TAR *t; char buf[TAR_MAXPATHLEN]; char pathname[TAR_MAXPATHLEN]; @@ -257,10 +276,13 @@ int cmCPackTGZGenerator::CompressFiles(const char* outFileName, //---------------------------------------------------------------------- int cmCPackTGZGenerator::GenerateHeader(std::ostream* os) { - const int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */ - char header[11]; - sprintf(header, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], - Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); - os->write(header, 10); + if ( this->Compress ) + { + const int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */ + char header[11]; + sprintf(header, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], + Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); + os->write(header, 10); + } return 1; } diff --git a/Source/CPack/cmCPackTGZGenerator.h b/Source/CPack/cmCPackTGZGenerator.h index 7dd5875..4323a53 100644 --- a/Source/CPack/cmCPackTGZGenerator.h +++ b/Source/CPack/cmCPackTGZGenerator.h @@ -45,6 +45,8 @@ protected: int CompressFiles(const char* outFileName, const char* toplevel, const std::vector<std::string>& files); virtual const char* GetOutputExtension() { return "tar.gz"; } + + bool Compress; }; #endif diff --git a/Source/CPack/cmCPackTarCompressGenerator.cxx b/Source/CPack/cmCPackTarCompressGenerator.cxx index c279f9a..066b384 100644 --- a/Source/CPack/cmCPackTarCompressGenerator.cxx +++ b/Source/CPack/cmCPackTarCompressGenerator.cxx @@ -26,10 +26,12 @@ #include "cmCPackLog.h" #include <cmsys/SystemTools.hxx> +#include <sys/stat.h> //---------------------------------------------------------------------- cmCPackTarCompressGenerator::cmCPackTarCompressGenerator() { + this->Compress = false; } //---------------------------------------------------------------------- @@ -42,20 +44,7 @@ int cmCPackTarCompressGenerator::InitializeInternal() { this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1"); std::vector<std::string> path; - std::vector<std::string> names; - names.push_back("tar"); - names.push_back("gtar"); - std::string pkgPath = cmSystemTools::FindProgram(names, path, false); - if ( pkgPath.empty() ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find Tar" << std::endl); - return 0; - } - this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_TAR", pkgPath.c_str()); - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found Tar program: " - << pkgPath.c_str() - << std::endl); - pkgPath = cmSystemTools::FindProgram("compress", path, false); + std::string pkgPath = cmSystemTools::FindProgram("compress", path, false); if ( pkgPath.empty() ) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find Compress" << std::endl); @@ -76,32 +65,10 @@ int cmCPackTarCompressGenerator::CompressFiles(const char* outFileName, std::string packageDirFileName = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); packageDirFileName += ".tar"; - cmOStringStream dmgCmd; - dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_TAR") - << "\" cvf \"" << packageDirFileName - << "\""; - std::vector<std::string>::const_iterator fileIt; - for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt ) - { - dmgCmd << " \"" - << cmSystemTools::RelativePath(toplevel, fileIt->c_str()) - << "\""; - } std::string output; int retVal = -1; - int res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, - &retVal, toplevel, this->GeneratorVerbose, 0); - if ( !res || retVal ) + if ( !this->Superclass::CompressFiles(packageDirFileName.c_str(), toplevel, files) ) { - std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); - tmpFile += "/CompressTar.log"; - cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl - << "# Output:" << std::endl - << output.c_str() << std::endl; - cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running Tar command: " - << dmgCmd.str().c_str() << std::endl - << "Please check " << tmpFile.c_str() << " for errors" << std::endl); return 0; } @@ -110,7 +77,7 @@ int cmCPackTarCompressGenerator::CompressFiles(const char* outFileName, << "\" \"" << packageDirFileName << "\""; retVal = -1; - res = cmSystemTools::RunSingleCommand(dmgCmd1.str().c_str(), &output, + int res = cmSystemTools::RunSingleCommand(dmgCmd1.str().c_str(), &output, &retVal, toplevel, this->GeneratorVerbose, 0); if ( !res || retVal ) { diff --git a/Source/CPack/cmCPackTarCompressGenerator.h b/Source/CPack/cmCPackTarCompressGenerator.h index 0573a80..efd5579 100644 --- a/Source/CPack/cmCPackTarCompressGenerator.h +++ b/Source/CPack/cmCPackTarCompressGenerator.h @@ -18,18 +18,16 @@ #ifndef cmCPackTarCompressGenerator_h #define cmCPackTarCompressGenerator_h -#include "cmCPackGenericGenerator.h" - -class cmCPackTarCompressGeneratorForward; +#include "cmCPackTGZGenerator.h" /** \class cmCPackTarCompressGenerator * \brief A generator for TarCompress files */ -class cmCPackTarCompressGenerator : public cmCPackGenericGenerator +class cmCPackTarCompressGenerator : public cmCPackTGZGenerator { public: friend class cmCPackTarCompressGeneratorForward; - cmCPackTypeMacro(cmCPackTarCompressGenerator, cmCPackGenericGenerator); + cmCPackTypeMacro(cmCPackTarCompressGenerator, cmCPackTGZGenerator); /** * Construct generator |