summaryrefslogtreecommitdiffstats
path: root/Source/cmcmd.cxx
diff options
context:
space:
mode:
authorBartosz Kosiorek <gang65@poczta.onet.pl>2019-03-08 22:20:52 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2019-03-20 13:28:49 (GMT)
commitea9a2c175929f8276ef80ee85f81675fccd9c757 (patch)
tree2aafcc99a5d6f39fa5001017600923c7c0d91ba1 /Source/cmcmd.cxx
parent51f3a76ab23fda217e61f0d2a53272836897717f (diff)
downloadCMake-ea9a2c175929f8276ef80ee85f81675fccd9c757.zip
CMake-ea9a2c175929f8276ef80ee85f81675fccd9c757.tar.gz
CMake-ea9a2c175929f8276ef80ee85f81675fccd9c757.tar.bz2
cmake: tar: Parse 'cmake -E tar' arguments
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r--Source/cmcmd.cxx62
1 files changed, 44 insertions, 18 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 0828a16..8d63971 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -1078,21 +1078,47 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
files.push_back(arg);
}
}
+ cmSystemTools::cmTarAction action = cmSystemTools::TarActionNone;
cmSystemTools::cmTarCompression compress =
cmSystemTools::TarCompressNone;
bool verbose = false;
int nCompress = 0;
- if (flags.find_first_of('j') != std::string::npos) {
- compress = cmSystemTools::TarCompressBZip2;
- ++nCompress;
- }
- if (flags.find_first_of('J') != std::string::npos) {
- compress = cmSystemTools::TarCompressXZ;
- ++nCompress;
- }
- if (flags.find_first_of('z') != std::string::npos) {
- compress = cmSystemTools::TarCompressGZip;
- ++nCompress;
+
+ for (auto flag : flags) {
+ switch (flag) {
+ case '-':
+ case 'f': {
+ // Keep for backward compatibility. Ignored
+ } break;
+ case 'j': {
+ compress = cmSystemTools::TarCompressBZip2;
+ ++nCompress;
+ } break;
+ case 'J': {
+ compress = cmSystemTools::TarCompressXZ;
+ ++nCompress;
+ } break;
+ case 'z': {
+ compress = cmSystemTools::TarCompressGZip;
+ ++nCompress;
+ } break;
+ case 'v': {
+ verbose = true;
+ } break;
+ case 't': {
+ action = cmSystemTools::TarActionList;
+ } break;
+ case 'c': {
+ action = cmSystemTools::TarActionCreate;
+ } break;
+ case 'x': {
+ action = cmSystemTools::TarActionExtract;
+ } break;
+ default: {
+ cmSystemTools::Message(
+ std::string("tar: Unknown argument: ") + flag, "Warning");
+ }
+ }
}
if ((format == "7zip" || format == "zip") && nCompress > 0) {
cmSystemTools::Error("Can not use compression flags with format: " +
@@ -1104,16 +1130,12 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
"at most one flag of z, j, or J may be used");
return 1;
}
- if (flags.find_first_of('v') != std::string::npos) {
- verbose = true;
- }
-
- if (flags.find_first_of('t') != std::string::npos) {
+ if (action == cmSystemTools::TarActionList) {
if (!cmSystemTools::ListTar(outFile.c_str(), verbose)) {
cmSystemTools::Error("Problem listing tar: " + outFile);
return 1;
}
- } else if (flags.find_first_of('c') != std::string::npos) {
+ } else if (action == cmSystemTools::TarActionCreate) {
if (files.empty()) {
cmSystemTools::Message("tar: No files or directories specified",
"Warning");
@@ -1123,7 +1145,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
cmSystemTools::Error("Problem creating tar: " + outFile);
return 1;
}
- } else if (flags.find_first_of('x') != std::string::npos) {
+ } else if (action == cmSystemTools::TarActionExtract) {
if (!cmSystemTools::ExtractTar(outFile.c_str(), verbose)) {
cmSystemTools::Error("Problem extracting tar: " + outFile);
return 1;
@@ -1144,6 +1166,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
cmSystemTools::Delay(delay);
}
#endif
+ } else {
+ cmSystemTools::Error("tar: No action specified. Please choose: 't' "
+ "(list), 'c' (create) or 'x' (extract)");
+ return 1;
}
return 0;
}