ENH: Simplify TarCompress to only require compress. Use cmake's tar
This commit is contained in:
parent
12e07f910e
commit
7e788fed35
|
@ -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,6 +87,8 @@ int cmCPackTGZ_Data_Open(void *client_data, const char* pathname,
|
|||
{
|
||||
cmCPackTGZ_Data *mydata = (cmCPackTGZ_Data*)client_data;
|
||||
|
||||
if ( mydata->Compress )
|
||||
{
|
||||
mydata->ZLibStream.zalloc = Z_NULL;
|
||||
mydata->ZLibStream.zfree = Z_NULL;
|
||||
mydata->ZLibStream.opaque = Z_NULL;
|
||||
|
@ -93,6 +98,7 @@ int cmCPackTGZ_Data_Open(void *client_data, const char* pathname,
|
|||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
cmGeneratedFileStream* gf = new cmGeneratedFileStream;
|
||||
// Open binary
|
||||
|
@ -108,7 +114,10 @@ int cmCPackTGZ_Data_Open(void *client_data, const char* pathname,
|
|||
return -1;
|
||||
}
|
||||
|
||||
if ( mydata->Compress )
|
||||
{
|
||||
mydata->CRC = crc32(0L, Z_NULL, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -118,6 +127,8 @@ ssize_t cmCPackTGZ_Data_Write(void *client_data, void *buff, size_t n)
|
|||
{
|
||||
cmCPackTGZ_Data *mydata = (cmCPackTGZ_Data*)client_data;
|
||||
|
||||
if ( mydata->Compress )
|
||||
{
|
||||
mydata->ZLibStream.avail_in = n;
|
||||
mydata->ZLibStream.next_in = reinterpret_cast<Bytef*>(buff);
|
||||
|
||||
|
@ -148,6 +159,11 @@ ssize_t cmCPackTGZ_Data_Write(void *client_data, void *buff, size_t n)
|
|||
{
|
||||
mydata->CRC = crc32(mydata->CRC, reinterpret_cast<Bytef *>(buff), n);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mydata->OutputStream->write(buff, n);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
@ -156,6 +172,8 @@ int cmCPackTGZ_Data_Close(void *client_data)
|
|||
{
|
||||
cmCPackTGZ_Data *mydata = (cmCPackTGZ_Data*)client_data;
|
||||
|
||||
if ( mydata->Compress )
|
||||
{
|
||||
cmCPackTGZ_Data_Write(client_data, 0, 0);
|
||||
|
||||
char buffer[8];
|
||||
|
@ -173,6 +191,7 @@ int cmCPackTGZ_Data_Close(void *client_data)
|
|||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue