cmSystemTools: use an enumeration for compression formats
Juggling 3 booleans was unwieldy.
This commit is contained in:
parent
df16dcfb44
commit
d811d238ab
|
@ -1675,7 +1675,7 @@ std::string cmCTest::Base64GzipEncodeFile(std::string file)
|
||||||
files.push_back(file);
|
files.push_back(file);
|
||||||
|
|
||||||
if(!cmSystemTools::CreateTar(tarFile.c_str(), files,
|
if(!cmSystemTools::CreateTar(tarFile.c_str(), files,
|
||||||
true, false, false, false))
|
cmSystemTools::TarCompressGZip, false))
|
||||||
{
|
{
|
||||||
cmCTestLog(this, ERROR_MESSAGE, "Error creating tar while "
|
cmCTestLog(this, ERROR_MESSAGE, "Error creating tar while "
|
||||||
"encoding file: " << file << std::endl);
|
"encoding file: " << file << std::endl);
|
||||||
|
|
|
@ -1482,7 +1482,7 @@ bool cmSystemTools::IsPathToFramework(const char* path)
|
||||||
|
|
||||||
bool cmSystemTools::CreateTar(const char* outFileName,
|
bool cmSystemTools::CreateTar(const char* outFileName,
|
||||||
const std::vector<std::string>& files,
|
const std::vector<std::string>& files,
|
||||||
bool gzip, bool bzip2, bool xz,
|
cmTarCompression compressType,
|
||||||
bool verbose)
|
bool verbose)
|
||||||
{
|
{
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
|
@ -1497,11 +1497,24 @@ bool cmSystemTools::CreateTar(const char* outFileName,
|
||||||
cmSystemTools::Error(e.c_str());
|
cmSystemTools::Error(e.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cmArchiveWrite a(fout, (gzip? cmArchiveWrite::CompressGZip :
|
cmArchiveWrite::Compress compress = cmArchiveWrite::CompressNone;
|
||||||
(bzip2? cmArchiveWrite::CompressBZip2 :
|
switch (compressType)
|
||||||
(xz? cmArchiveWrite::CompressXZ :
|
{
|
||||||
cmArchiveWrite::CompressNone))),
|
case TarCompressGZip:
|
||||||
cmArchiveWrite::TypeTAR);
|
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);
|
a.SetVerbose(verbose);
|
||||||
for(std::vector<std::string>::const_iterator i = files.begin();
|
for(std::vector<std::string>::const_iterator i = files.begin();
|
||||||
i != files.end(); ++i)
|
i != files.end(); ++i)
|
||||||
|
@ -1526,7 +1539,6 @@ bool cmSystemTools::CreateTar(const char* outFileName,
|
||||||
#else
|
#else
|
||||||
(void)outFileName;
|
(void)outFileName;
|
||||||
(void)files;
|
(void)files;
|
||||||
(void)gzip;
|
|
||||||
(void)verbose;
|
(void)verbose;
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1787,7 +1799,7 @@ bool extract_tar(const char* outFileName, bool verbose,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool cmSystemTools::ExtractTar(const char* outFileName,
|
bool cmSystemTools::ExtractTar(const char* outFileName,
|
||||||
bool , bool verbose)
|
bool verbose)
|
||||||
{
|
{
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
return extract_tar(outFileName, verbose, true);
|
return extract_tar(outFileName, verbose, true);
|
||||||
|
@ -1799,7 +1811,6 @@ bool cmSystemTools::ExtractTar(const char* outFileName,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmSystemTools::ListTar(const char* outFileName,
|
bool cmSystemTools::ListTar(const char* outFileName,
|
||||||
bool ,
|
|
||||||
bool verbose)
|
bool verbose)
|
||||||
{
|
{
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
|
|
|
@ -383,12 +383,19 @@ public:
|
||||||
static void EnableVSConsoleOutput();
|
static void EnableVSConsoleOutput();
|
||||||
|
|
||||||
/** Create tar */
|
/** Create tar */
|
||||||
|
enum cmTarCompression
|
||||||
|
{
|
||||||
|
TarCompressGZip,
|
||||||
|
TarCompressBZip2,
|
||||||
|
TarCompressXZ,
|
||||||
|
TarCompressNone
|
||||||
|
};
|
||||||
static bool ListTar(const char* outFileName,
|
static bool ListTar(const char* outFileName,
|
||||||
bool gzip, bool verbose);
|
bool verbose);
|
||||||
static bool CreateTar(const char* outFileName,
|
static bool CreateTar(const char* outFileName,
|
||||||
const std::vector<std::string>& files, bool gzip,
|
const std::vector<std::string>& files,
|
||||||
bool bzip2, bool xz, bool verbose);
|
cmTarCompression compressType, bool verbose);
|
||||||
static bool ExtractTar(const char* inFileName, bool gzip,
|
static bool ExtractTar(const char* inFileName,
|
||||||
bool verbose);
|
bool verbose);
|
||||||
// This should be called first thing in main
|
// This should be called first thing in main
|
||||||
// it will keep child processes from inheriting the
|
// it will keep child processes from inheriting the
|
||||||
|
|
|
@ -733,21 +733,20 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
files.push_back(args[cc]);
|
files.push_back(args[cc]);
|
||||||
}
|
}
|
||||||
bool gzip = false;
|
cmSystemTools::cmTarCompression compress =
|
||||||
bool bzip2 = false;
|
cmSystemTools::TarCompressNone;
|
||||||
bool xz = false;
|
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
if ( flags.find_first_of('j') != flags.npos )
|
if ( flags.find_first_of('j') != flags.npos )
|
||||||
{
|
{
|
||||||
bzip2 = true;
|
compress = cmSystemTools::TarCompressBZip2;
|
||||||
}
|
}
|
||||||
if ( flags.find_first_of('J') != flags.npos )
|
if ( flags.find_first_of('J') != flags.npos )
|
||||||
{
|
{
|
||||||
xz = true;
|
compress = cmSystemTools::TarCompressXZ;
|
||||||
}
|
}
|
||||||
if ( flags.find_first_of('z') != flags.npos )
|
if ( flags.find_first_of('z') != flags.npos )
|
||||||
{
|
{
|
||||||
gzip = true;
|
compress = cmSystemTools::TarCompressGZip;
|
||||||
}
|
}
|
||||||
if ( flags.find_first_of('v') != flags.npos )
|
if ( flags.find_first_of('v') != flags.npos )
|
||||||
{
|
{
|
||||||
|
@ -756,7 +755,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
|
||||||
|
|
||||||
if ( flags.find_first_of('t') != flags.npos )
|
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 creating tar: ", outFile.c_str());
|
cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -765,7 +764,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
|
||||||
else if ( flags.find_first_of('c') != flags.npos )
|
else if ( flags.find_first_of('c') != flags.npos )
|
||||||
{
|
{
|
||||||
if ( !cmSystemTools::CreateTar(
|
if ( !cmSystemTools::CreateTar(
|
||||||
outFile.c_str(), files, gzip, bzip2, xz, verbose) )
|
outFile.c_str(), files, compress, verbose) )
|
||||||
{
|
{
|
||||||
cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
|
cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -774,7 +773,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
|
||||||
else if ( flags.find_first_of('x') != flags.npos )
|
else if ( flags.find_first_of('x') != flags.npos )
|
||||||
{
|
{
|
||||||
if ( !cmSystemTools::ExtractTar(
|
if ( !cmSystemTools::ExtractTar(
|
||||||
outFile.c_str(), gzip, verbose) )
|
outFile.c_str(), verbose) )
|
||||||
{
|
{
|
||||||
cmSystemTools::Error("Problem extracting tar: ", outFile.c_str());
|
cmSystemTools::Error("Problem extracting tar: ", outFile.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue