summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Help/manual/cmake.1.rst4
-rw-r--r--Help/release/dev/tar-write-format.rst6
-rw-r--r--Source/CPack/cmCPack7zGenerator.cxx2
-rw-r--r--Source/CPack/cmCPackArchiveGenerator.cxx6
-rw-r--r--Source/CPack/cmCPackArchiveGenerator.h4
-rw-r--r--Source/CPack/cmCPackTGZGenerator.cxx2
-rw-r--r--Source/CPack/cmCPackTXZGenerator.cxx2
-rw-r--r--Source/CPack/cmCPackTarBZip2Generator.cxx2
-rw-r--r--Source/CPack/cmCPackTarCompressGenerator.cxx2
-rw-r--r--Source/CPack/cmCPackZIPGenerator.cxx2
-rw-r--r--Source/cmArchiveWrite.cxx44
-rw-r--r--Source/cmArchiveWrite.h12
-rw-r--r--Source/cmSystemTools.cxx7
-rw-r--r--Source/cmSystemTools.h3
-rw-r--r--Source/cmcmd.cxx33
-rw-r--r--Tests/RunCMake/CommandLine/E_tar-bad-format-result.txt1
-rw-r--r--Tests/RunCMake/CommandLine/E_tar-bad-format-stderr.txt1
-rw-r--r--Tests/RunCMake/CommandLine/RunCMakeTest.cmake1
18 files changed, 78 insertions, 56 deletions
diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst
index da41bbb..b2f7e9d 100644
--- a/Help/manual/cmake.1.rst
+++ b/Help/manual/cmake.1.rst
@@ -215,6 +215,10 @@ Available commands are:
names start in ``-``.
``--mtime=<date>``
Specify modification time recorded in tarball entries.
+ ``--format=<format>``
+ Specify the format of the archive to be created.
+ Supported formats are: ``7zip``, ``gnutar``, ``pax``,
+ ``paxr`` (restricted pax, default), and ``zip``.
``time <command> [<args>...]``
Run command and return elapsed time.
diff --git a/Help/release/dev/tar-write-format.rst b/Help/release/dev/tar-write-format.rst
new file mode 100644
index 0000000..004df21
--- /dev/null
+++ b/Help/release/dev/tar-write-format.rst
@@ -0,0 +1,6 @@
+tar-write-format
+----------------
+
+* The :manual:`cmake(1)` ``-E tar`` command learned a new
+ ``--format<format>`` option to specify the archive format to
+ be written.
diff --git a/Source/CPack/cmCPack7zGenerator.cxx b/Source/CPack/cmCPack7zGenerator.cxx
index ce31ad4..2809e56 100644
--- a/Source/CPack/cmCPack7zGenerator.cxx
+++ b/Source/CPack/cmCPack7zGenerator.cxx
@@ -15,7 +15,7 @@
//----------------------------------------------------------------------
cmCPack7zGenerator::cmCPack7zGenerator()
:cmCPackArchiveGenerator(cmArchiveWrite::CompressNone,
- cmArchiveWrite::Type7Zip)
+ "7zip")
{
}
diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx
index 05b5cd9..58bd947 100644
--- a/Source/CPack/cmCPackArchiveGenerator.cxx
+++ b/Source/CPack/cmCPackArchiveGenerator.cxx
@@ -27,10 +27,10 @@
//----------------------------------------------------------------------
cmCPackArchiveGenerator::cmCPackArchiveGenerator(cmArchiveWrite::Compress t,
- cmArchiveWrite::Type at)
+ std::string const& format)
{
this->Compress = t;
- this->Archive = at;
+ this->ArchiveFormat = format;
}
//----------------------------------------------------------------------
@@ -108,7 +108,7 @@ if (!GenerateHeader(&gf)) \
<< ">." << std::endl); \
return 0; \
} \
-cmArchiveWrite archive(gf,this->Compress, this->Archive); \
+cmArchiveWrite archive(gf,this->Compress, this->ArchiveFormat); \
if (!archive) \
{ \
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem to create archive < " \
diff --git a/Source/CPack/cmCPackArchiveGenerator.h b/Source/CPack/cmCPackArchiveGenerator.h
index 6411b1e..16e7632 100644
--- a/Source/CPack/cmCPackArchiveGenerator.h
+++ b/Source/CPack/cmCPackArchiveGenerator.h
@@ -31,7 +31,7 @@ public:
/**
* Construct generator
*/
- cmCPackArchiveGenerator(cmArchiveWrite::Compress, cmArchiveWrite::Type);
+ cmCPackArchiveGenerator(cmArchiveWrite::Compress, std::string const& format);
virtual ~cmCPackArchiveGenerator();
// Used to add a header to the archive
virtual int GenerateHeader(std::ostream* os);
@@ -68,7 +68,7 @@ protected:
int PackageComponentsAllInOne();
virtual const char* GetOutputExtension() = 0;
cmArchiveWrite::Compress Compress;
- cmArchiveWrite::Type Archive;
+ std::string ArchiveFormat;
};
#endif
diff --git a/Source/CPack/cmCPackTGZGenerator.cxx b/Source/CPack/cmCPackTGZGenerator.cxx
index 509c7f8..3fa2b64 100644
--- a/Source/CPack/cmCPackTGZGenerator.cxx
+++ b/Source/CPack/cmCPackTGZGenerator.cxx
@@ -15,7 +15,7 @@
//----------------------------------------------------------------------
cmCPackTGZGenerator::cmCPackTGZGenerator()
:cmCPackArchiveGenerator(cmArchiveWrite::CompressGZip,
- cmArchiveWrite::TypeTAR)
+ "paxr")
{
}
diff --git a/Source/CPack/cmCPackTXZGenerator.cxx b/Source/CPack/cmCPackTXZGenerator.cxx
index ecfc177..6d4ede1 100644
--- a/Source/CPack/cmCPackTXZGenerator.cxx
+++ b/Source/CPack/cmCPackTXZGenerator.cxx
@@ -15,7 +15,7 @@
//----------------------------------------------------------------------
cmCPackTXZGenerator::cmCPackTXZGenerator()
:cmCPackArchiveGenerator(cmArchiveWrite::CompressXZ,
- cmArchiveWrite::TypeTAR)
+ "paxr")
{
}
diff --git a/Source/CPack/cmCPackTarBZip2Generator.cxx b/Source/CPack/cmCPackTarBZip2Generator.cxx
index ae73c37..9ff588b 100644
--- a/Source/CPack/cmCPackTarBZip2Generator.cxx
+++ b/Source/CPack/cmCPackTarBZip2Generator.cxx
@@ -14,7 +14,7 @@
//----------------------------------------------------------------------
cmCPackTarBZip2Generator::cmCPackTarBZip2Generator()
:cmCPackArchiveGenerator(cmArchiveWrite::CompressBZip2,
- cmArchiveWrite::TypeTAR)
+ "paxr")
{
}
diff --git a/Source/CPack/cmCPackTarCompressGenerator.cxx b/Source/CPack/cmCPackTarCompressGenerator.cxx
index df29408..1c8311b 100644
--- a/Source/CPack/cmCPackTarCompressGenerator.cxx
+++ b/Source/CPack/cmCPackTarCompressGenerator.cxx
@@ -15,7 +15,7 @@
//----------------------------------------------------------------------
cmCPackTarCompressGenerator::cmCPackTarCompressGenerator()
:cmCPackArchiveGenerator(cmArchiveWrite::CompressCompress,
- cmArchiveWrite::TypeTAR)
+ "paxr")
{
}
diff --git a/Source/CPack/cmCPackZIPGenerator.cxx b/Source/CPack/cmCPackZIPGenerator.cxx
index e6e4e77..7ef7729 100644
--- a/Source/CPack/cmCPackZIPGenerator.cxx
+++ b/Source/CPack/cmCPackZIPGenerator.cxx
@@ -15,7 +15,7 @@
//----------------------------------------------------------------------
cmCPackZIPGenerator::cmCPackZIPGenerator()
:cmCPackArchiveGenerator(cmArchiveWrite::CompressNone,
- cmArchiveWrite::TypeZIP)
+ "zip")
{
}
diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx
index cf2fe82..72818f5 100644
--- a/Source/cmArchiveWrite.cxx
+++ b/Source/cmArchiveWrite.cxx
@@ -79,11 +79,12 @@ struct cmArchiveWrite::Callback
};
//----------------------------------------------------------------------------
-cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, Type t):
- Stream(os),
- Archive(archive_write_new()),
- Disk(archive_read_disk_new()),
- Verbose(false)
+cmArchiveWrite::cmArchiveWrite(
+ std::ostream& os, Compress c, std::string const& format):
+ Stream(os),
+ Archive(archive_write_new()),
+ Disk(archive_read_disk_new()),
+ Verbose(false)
{
switch (c)
{
@@ -141,35 +142,16 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, Type t):
{
this->Error = "archive_read_disk_set_standard_lookup: ";
this->Error += cm_archive_error_string(this->Archive);
- return;;
+ return;
}
#endif
- switch (t)
+
+ if(archive_write_set_format_by_name(this->Archive, format.c_str())
+ != ARCHIVE_OK)
{
- case TypeZIP:
- if(archive_write_set_format_zip(this->Archive) != ARCHIVE_OK)
- {
- this->Error = "archive_write_set_format_zip: ";
- this->Error += cm_archive_error_string(this->Archive);
- return;
- }
- break;
- case TypeTAR:
- if(archive_write_set_format_pax_restricted(this->Archive) != ARCHIVE_OK)
- {
- this->Error = "archive_write_set_format_pax_restricted: ";
- this->Error += cm_archive_error_string(this->Archive);
- return;
- }
- break;
- case Type7Zip:
- if(archive_write_set_format_7zip(this->Archive) != ARCHIVE_OK)
- {
- this->Error = "archive_write_set_format_7zip: ";
- this->Error += cm_archive_error_string(this->Archive);
- return;
- }
- break;
+ this->Error = "archive_write_set_format_by_name: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
}
// do not pad the last block!!
diff --git a/Source/cmArchiveWrite.h b/Source/cmArchiveWrite.h
index 17357b4..794cb28 100644
--- a/Source/cmArchiveWrite.h
+++ b/Source/cmArchiveWrite.h
@@ -38,16 +38,10 @@ public:
CompressXZ
};
- /** Archive Type */
- enum Type
- {
- TypeTAR,
- TypeZIP,
- Type7Zip
- };
-
/** Construct with output stream to which to write archive. */
- cmArchiveWrite(std::ostream& os, Compress c = CompressNone, Type = TypeTAR);
+ cmArchiveWrite(std::ostream& os, Compress c = CompressNone,
+ std::string const& format = "paxr");
+
~cmArchiveWrite();
/**
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 5264123..95d05a6 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -1475,7 +1475,8 @@ bool cmSystemTools::IsPathToFramework(const char* path)
bool cmSystemTools::CreateTar(const char* outFileName,
const std::vector<std::string>& files,
cmTarCompression compressType,
- bool verbose, std::string const& mtime)
+ bool verbose, std::string const& mtime,
+ std::string const& format)
{
#if defined(CMAKE_BUILD_WITH_CMAKE)
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
@@ -1505,8 +1506,10 @@ bool cmSystemTools::CreateTar(const char* outFileName,
compress = cmArchiveWrite::CompressNone;
break;
}
+
cmArchiveWrite a(fout, compress,
- cmArchiveWrite::TypeTAR);
+ format.empty() ? "paxr" : format);
+
a.SetMTime(mtime);
a.SetVerbose(verbose);
for(std::vector<std::string>::const_iterator i = files.begin();
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index c59ae96..433ef46 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -395,7 +395,8 @@ public:
static bool CreateTar(const char* outFileName,
const std::vector<std::string>& files,
cmTarCompression compressType, bool verbose,
- std::string const& mtime = std::string());
+ std::string const& mtime = std::string(),
+ std::string const& format = std::string());
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 9f2ea46..2ef04ef 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -703,10 +703,20 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
// Tar files
else if (args[1] == "tar" && args.size() > 3)
{
+ const char* knownFormats[] =
+ {
+ "7zip",
+ "gnutar",
+ "pax",
+ "paxr",
+ "zip"
+ };
+
std::string flags = args[2];
std::string outFile = args[3];
std::vector<std::string> files;
std::string mtime;
+ std::string format;
bool doing_options = true;
for (std::string::size_type cc = 4; cc < args.size(); cc ++)
{
@@ -729,6 +739,19 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
return 1;
}
}
+ else if (cmHasLiteralPrefix(arg, "--format="))
+ {
+ format = arg.substr(9);
+ bool isKnown = std::find(cmArrayBegin(knownFormats),
+ cmArrayEnd(knownFormats), format) != cmArrayEnd(knownFormats);
+
+ if(!isKnown)
+ {
+ cmSystemTools::Error("Unknown -E tar --format= argument: ",
+ format.c_str());
+ return 1;
+ }
+ }
else
{
cmSystemTools::Error("Unknown option to -E tar: ", arg.c_str());
@@ -759,7 +782,13 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
compress = cmSystemTools::TarCompressGZip;
++nCompress;
}
- if ( nCompress > 1 )
+ if ( (format == "7zip" || format == "zip") && nCompress > 0 )
+ {
+ cmSystemTools::Error("Can not use compression flags with format: ",
+ format.c_str());
+ return 1;
+ }
+ else 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");
@@ -781,7 +810,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, compress, verbose, mtime) )
+ outFile.c_str(), files, compress, verbose, mtime, format) )
{
cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
return 1;
diff --git a/Tests/RunCMake/CommandLine/E_tar-bad-format-result.txt b/Tests/RunCMake/CommandLine/E_tar-bad-format-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_tar-bad-format-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CommandLine/E_tar-bad-format-stderr.txt b/Tests/RunCMake/CommandLine/E_tar-bad-format-stderr.txt
new file mode 100644
index 0000000..fe9e2dc
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E_tar-bad-format-stderr.txt
@@ -0,0 +1 @@
+CMake Error: Unknown -E tar --format= argument: bad-format
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index e8b4584..e3942a8 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -10,6 +10,7 @@ run_cmake_command(E_tar-bad-from5 ${CMAKE_COMMAND} -E tar cvf bad.tar --files-f
run_cmake_command(E_tar-end-opt1 ${CMAKE_COMMAND} -E tar cvf bad.tar -- --bad)
run_cmake_command(E_tar-end-opt2 ${CMAKE_COMMAND} -E tar cvf bad.tar --)
run_cmake_command(E_tar-mtime ${CMAKE_COMMAND} -E tar cvf bad.tar "--mtime=1970-01-01 00:00:00 UTC")
+run_cmake_command(E_tar-bad-format ${CMAKE_COMMAND} -E tar cvf bad.tar "--format=bad-format")
run_cmake_command(build-no-cache
${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR})