Merge topic 'add-xz-support'

4035ef78 cmake -E tar: error out on multiple compression formats
d811d238 cmSystemTools: use an enumeration for compression formats
df16dcfb cmake -E tar: add support for .xz files with 'J'
b0a5d393 cmake -E tar: clean up flag documentation
This commit is contained in:
Brad King 2015-01-12 09:39:40 -05:00 committed by CMake Topic Stage
commit d9a6ea4599
5 changed files with 61 additions and 21 deletions

View File

@ -0,0 +1,5 @@
add-xz-support
--------------
* The :manual:`cmake(1)` ``-E tar`` command now supports creating
``.xz``-compressed archives with the ``J`` flag.

View File

@ -1674,7 +1674,8 @@ std::string cmCTest::Base64GzipEncodeFile(std::string file)
std::vector<std::string> files;
files.push_back(file);
if(!cmSystemTools::CreateTar(tarFile.c_str(), files, true, false, false))
if(!cmSystemTools::CreateTar(tarFile.c_str(), files,
cmSystemTools::TarCompressGZip, false))
{
cmCTestLog(this, ERROR_MESSAGE, "Error creating tar while "
"encoding file: " << file << std::endl);

View File

@ -1474,7 +1474,8 @@ bool cmSystemTools::IsPathToFramework(const char* path)
bool cmSystemTools::CreateTar(const char* outFileName,
const std::vector<std::string>& files,
bool gzip, bool bzip2, bool verbose)
cmTarCompression compressType,
bool verbose)
{
#if defined(CMAKE_BUILD_WITH_CMAKE)
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
@ -1488,10 +1489,24 @@ bool cmSystemTools::CreateTar(const char* outFileName,
cmSystemTools::Error(e.c_str());
return false;
}
cmArchiveWrite a(fout, (gzip? cmArchiveWrite::CompressGZip :
(bzip2? cmArchiveWrite::CompressBZip2 :
cmArchiveWrite::CompressNone)),
cmArchiveWrite::TypeTAR);
cmArchiveWrite::Compress compress = cmArchiveWrite::CompressNone;
switch (compressType)
{
case TarCompressGZip:
compress = cmArchiveWrite::CompressGZip;
break;
case TarCompressBZip2:
compress = cmArchiveWrite::CompressBZip2;
break;
case TarCompressXZ:
compress = cmArchiveWrite::CompressXZ;
break;
case TarCompressNone:
compress = cmArchiveWrite::CompressNone;
break;
}
cmArchiveWrite a(fout, compress,
cmArchiveWrite::TypeTAR);
a.SetVerbose(verbose);
for(std::vector<std::string>::const_iterator i = files.begin();
i != files.end(); ++i)
@ -1516,7 +1531,6 @@ bool cmSystemTools::CreateTar(const char* outFileName,
#else
(void)outFileName;
(void)files;
(void)gzip;
(void)verbose;
return false;
#endif
@ -1777,7 +1791,7 @@ bool extract_tar(const char* outFileName, bool verbose,
#endif
bool cmSystemTools::ExtractTar(const char* outFileName,
bool , bool verbose)
bool verbose)
{
#if defined(CMAKE_BUILD_WITH_CMAKE)
return extract_tar(outFileName, verbose, true);
@ -1789,7 +1803,6 @@ bool cmSystemTools::ExtractTar(const char* outFileName,
}
bool cmSystemTools::ListTar(const char* outFileName,
bool ,
bool verbose)
{
#if defined(CMAKE_BUILD_WITH_CMAKE)

View File

@ -383,12 +383,19 @@ public:
static void EnableVSConsoleOutput();
/** Create tar */
enum cmTarCompression
{
TarCompressGZip,
TarCompressBZip2,
TarCompressXZ,
TarCompressNone
};
static bool ListTar(const char* outFileName,
bool gzip, bool verbose);
bool verbose);
static bool CreateTar(const char* outFileName,
const std::vector<std::string>& files, bool gzip,
bool bzip2, bool verbose);
static bool ExtractTar(const char* inFileName, bool gzip,
const std::vector<std::string>& files,
cmTarCompression compressType, bool verbose);
static bool ExtractTar(const char* inFileName,
bool verbose);
// This should be called first thing in main
// it will keep child processes from inheriting the

View File

@ -71,7 +71,7 @@ void CMakeCommandUsage(const char* program)
<< " remove_directory dir - remove a directory and its contents\n"
<< " rename oldname newname - rename a file or directory "
"(on one volume)\n"
<< " tar [cxt][vfz][cvfj] file.tar [file/dir1 file/dir2 ...]\n"
<< " tar [cxt][vf][zjJ] file.tar [file/dir1 file/dir2 ...]\n"
<< " - create or extract a tar or zip archive\n"
<< " sleep <number>... - sleep for given number of seconds\n"
<< " time command [args] ... - run command and return elapsed time\n"
@ -733,16 +733,30 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
{
files.push_back(args[cc]);
}
bool gzip = false;
bool bzip2 = false;
cmSystemTools::cmTarCompression compress =
cmSystemTools::TarCompressNone;
bool verbose = false;
int nCompress = 0;
if ( flags.find_first_of('j') != flags.npos )
{
bzip2 = true;
compress = cmSystemTools::TarCompressBZip2;
++nCompress;
}
if ( flags.find_first_of('J') != flags.npos )
{
compress = cmSystemTools::TarCompressXZ;
++nCompress;
}
if ( flags.find_first_of('z') != flags.npos )
{
gzip = true;
compress = cmSystemTools::TarCompressGZip;
++nCompress;
}
if ( nCompress > 1 )
{
cmSystemTools::Error("Can only compress a tar file one way; "
"at most one flag of z, j, or J may be used");
return 1;
}
if ( flags.find_first_of('v') != flags.npos )
{
@ -751,7 +765,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
if ( flags.find_first_of('t') != flags.npos )
{
if ( !cmSystemTools::ListTar(outFile.c_str(), gzip, verbose) )
if ( !cmSystemTools::ListTar(outFile.c_str(), verbose) )
{
cmSystemTools::Error("Problem listing tar: ", outFile.c_str());
return 1;
@ -760,7 +774,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
else if ( flags.find_first_of('c') != flags.npos )
{
if ( !cmSystemTools::CreateTar(
outFile.c_str(), files, gzip, bzip2, verbose) )
outFile.c_str(), files, compress, verbose) )
{
cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
return 1;
@ -769,7 +783,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
else if ( flags.find_first_of('x') != flags.npos )
{
if ( !cmSystemTools::ExtractTar(
outFile.c_str(), gzip, verbose) )
outFile.c_str(), verbose) )
{
cmSystemTools::Error("Problem extracting tar: ", outFile.c_str());
return 1;