From b0a5d3932d2a6633d05eca3eb7fd632f433dca05 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 8 Jan 2015 16:56:17 -0500 Subject: [PATCH 1/4] cmake -E tar: clean up flag documentation --- Source/cmcmd.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index a97444d1a..f2f028a83 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -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][zj] file.tar [file/dir1 file/dir2 ...]\n" << " - create or extract a tar or zip archive\n" << " sleep ... - sleep for given number of seconds\n" << " time command [args] ... - run command and return elapsed time\n" From df16dcfb4478bb05932a1abb0e42433e60f1a565 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 8 Jan 2015 16:56:33 -0500 Subject: [PATCH 2/4] cmake -E tar: add support for .xz files with 'J' --- Help/release/dev/add-xz-support.rst | 5 +++++ Source/cmCTest.cxx | 3 ++- Source/cmSystemTools.cxx | 6 ++++-- Source/cmSystemTools.h | 2 +- Source/cmcmd.cxx | 9 +++++++-- 5 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 Help/release/dev/add-xz-support.rst diff --git a/Help/release/dev/add-xz-support.rst b/Help/release/dev/add-xz-support.rst new file mode 100644 index 000000000..9bdf5287c --- /dev/null +++ b/Help/release/dev/add-xz-support.rst @@ -0,0 +1,5 @@ +add-xz-support +-------------- + +* The :manual:`cmake(1)` ``-E tar`` command now supports creating + ``.xz``-compressed archives with the ``J`` flag. diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 80dbaf30a..f02d78e69 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1674,7 +1674,8 @@ std::string cmCTest::Base64GzipEncodeFile(std::string file) std::vector files; files.push_back(file); - if(!cmSystemTools::CreateTar(tarFile.c_str(), files, true, false, false)) + if(!cmSystemTools::CreateTar(tarFile.c_str(), files, + true, false, false, false)) { cmCTestLog(this, ERROR_MESSAGE, "Error creating tar while " "encoding file: " << file << std::endl); diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 1c8c38788..cd633472a 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1482,7 +1482,8 @@ bool cmSystemTools::IsPathToFramework(const char* path) bool cmSystemTools::CreateTar(const char* outFileName, const std::vector& files, - bool gzip, bool bzip2, bool verbose) + bool gzip, bool bzip2, bool xz, + bool verbose) { #if defined(CMAKE_BUILD_WITH_CMAKE) std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); @@ -1498,7 +1499,8 @@ bool cmSystemTools::CreateTar(const char* outFileName, } cmArchiveWrite a(fout, (gzip? cmArchiveWrite::CompressGZip : (bzip2? cmArchiveWrite::CompressBZip2 : - cmArchiveWrite::CompressNone)), + (xz? cmArchiveWrite::CompressXZ : + cmArchiveWrite::CompressNone))), cmArchiveWrite::TypeTAR); a.SetVerbose(verbose); for(std::vector::const_iterator i = files.begin(); diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index d49af7402..47d2771b0 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -387,7 +387,7 @@ public: bool gzip, bool verbose); static bool CreateTar(const char* outFileName, const std::vector& files, bool gzip, - bool bzip2, bool verbose); + bool bzip2, bool xz, bool verbose); static bool ExtractTar(const char* inFileName, bool gzip, bool verbose); // This should be called first thing in main diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index f2f028a83..6b3efb565 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -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][vf][zj] 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 ... - sleep for given number of seconds\n" << " time command [args] ... - run command and return elapsed time\n" @@ -735,11 +735,16 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) } bool gzip = false; bool bzip2 = false; + bool xz = false; bool verbose = false; if ( flags.find_first_of('j') != flags.npos ) { bzip2 = true; } + if ( flags.find_first_of('J') != flags.npos ) + { + xz = true; + } if ( flags.find_first_of('z') != flags.npos ) { gzip = true; @@ -760,7 +765,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) else if ( flags.find_first_of('c') != flags.npos ) { if ( !cmSystemTools::CreateTar( - outFile.c_str(), files, gzip, bzip2, verbose) ) + outFile.c_str(), files, gzip, bzip2, xz, verbose) ) { cmSystemTools::Error("Problem creating tar: ", outFile.c_str()); return 1; From d811d238abe2dcd04cebd7ee4c3f07f4b6da093f Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 9 Jan 2015 10:33:00 -0500 Subject: [PATCH 3/4] cmSystemTools: use an enumeration for compression formats Juggling 3 booleans was unwieldy. --- Source/cmCTest.cxx | 2 +- Source/cmSystemTools.cxx | 29 ++++++++++++++++++++--------- Source/cmSystemTools.h | 15 +++++++++++---- Source/cmcmd.cxx | 17 ++++++++--------- 4 files changed, 40 insertions(+), 23 deletions(-) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index f02d78e69..e1391a71b 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1675,7 +1675,7 @@ std::string cmCTest::Base64GzipEncodeFile(std::string file) files.push_back(file); if(!cmSystemTools::CreateTar(tarFile.c_str(), files, - true, false, false, false)) + cmSystemTools::TarCompressGZip, false)) { cmCTestLog(this, ERROR_MESSAGE, "Error creating tar while " "encoding file: " << file << std::endl); diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index cd633472a..963ca77e5 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1482,7 +1482,7 @@ bool cmSystemTools::IsPathToFramework(const char* path) bool cmSystemTools::CreateTar(const char* outFileName, const std::vector& files, - bool gzip, bool bzip2, bool xz, + cmTarCompression compressType, bool verbose) { #if defined(CMAKE_BUILD_WITH_CMAKE) @@ -1497,11 +1497,24 @@ bool cmSystemTools::CreateTar(const char* outFileName, cmSystemTools::Error(e.c_str()); return false; } - cmArchiveWrite a(fout, (gzip? cmArchiveWrite::CompressGZip : - (bzip2? cmArchiveWrite::CompressBZip2 : - (xz? cmArchiveWrite::CompressXZ : - 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::const_iterator i = files.begin(); i != files.end(); ++i) @@ -1526,7 +1539,6 @@ bool cmSystemTools::CreateTar(const char* outFileName, #else (void)outFileName; (void)files; - (void)gzip; (void)verbose; return false; #endif @@ -1787,7 +1799,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); @@ -1799,7 +1811,6 @@ bool cmSystemTools::ExtractTar(const char* outFileName, } bool cmSystemTools::ListTar(const char* outFileName, - bool , bool verbose) { #if defined(CMAKE_BUILD_WITH_CMAKE) diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 47d2771b0..09ceea6e8 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -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& files, bool gzip, - bool bzip2, bool xz, bool verbose); - static bool ExtractTar(const char* inFileName, bool gzip, + const std::vector& 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 diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 6b3efb565..91b9e94e0 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -733,21 +733,20 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) { files.push_back(args[cc]); } - bool gzip = false; - bool bzip2 = false; - bool xz = false; + cmSystemTools::cmTarCompression compress = + cmSystemTools::TarCompressNone; bool verbose = false; if ( flags.find_first_of('j') != flags.npos ) { - bzip2 = true; + compress = cmSystemTools::TarCompressBZip2; } if ( flags.find_first_of('J') != flags.npos ) { - xz = true; + compress = cmSystemTools::TarCompressXZ; } if ( flags.find_first_of('z') != flags.npos ) { - gzip = true; + compress = cmSystemTools::TarCompressGZip; } if ( flags.find_first_of('v') != flags.npos ) { @@ -756,7 +755,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector& 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 creating tar: ", outFile.c_str()); return 1; @@ -765,7 +764,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) else if ( flags.find_first_of('c') != flags.npos ) { 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()); return 1; @@ -774,7 +773,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector& 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; From 4035ef786de80d4d2fc27cd5f03c629702f54762 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 9 Jan 2015 10:33:36 -0500 Subject: [PATCH 4/4] cmake -E tar: error out on multiple compression formats --- Source/cmcmd.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 91b9e94e0..27dd08b78 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -736,17 +736,27 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) cmSystemTools::cmTarCompression compress = cmSystemTools::TarCompressNone; bool verbose = false; + int nCompress = 0; if ( flags.find_first_of('j') != flags.npos ) { compress = cmSystemTools::TarCompressBZip2; + ++nCompress; } if ( flags.find_first_of('J') != flags.npos ) { compress = cmSystemTools::TarCompressXZ; + ++nCompress; } if ( flags.find_first_of('z') != flags.npos ) { 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 ) {