summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2019-03-21 14:50:07 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-03-21 14:50:38 (GMT)
commitfac093802a85cad720efe9e42957014b3b5c5561 (patch)
tree88e80bdb596deb06889989c799a4a17524fc06f3 /Source
parente09c606eb47c13bd435892625943e95bb9452996 (diff)
parentea9a2c175929f8276ef80ee85f81675fccd9c757 (diff)
downloadCMake-fac093802a85cad720efe9e42957014b3b5c5561.zip
CMake-fac093802a85cad720efe9e42957014b3b5c5561.tar.gz
CMake-fac093802a85cad720efe9e42957014b3b5c5561.tar.bz2
Merge topic 'tar-improve-error-handling'
ea9a2c1759 cmake: tar: Parse 'cmake -E tar' arguments Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3081
Diffstat (limited to 'Source')
-rw-r--r--Source/cmSystemTools.h9
-rw-r--r--Source/cmcmd.cxx62
2 files changed, 53 insertions, 18 deletions
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index b5f65c7..0b75025 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -406,6 +406,14 @@ public:
/** Setup the environment to enable VS 8 IDE output. */
static void EnableVSConsoleOutput();
+ enum cmTarAction
+ {
+ TarActionCreate,
+ TarActionList,
+ TarActionExtract,
+ TarActionNone
+ };
+
/** Create tar */
enum cmTarCompression
{
@@ -414,6 +422,7 @@ public:
TarCompressXZ,
TarCompressNone
};
+
static bool ListTar(const char* outFileName, bool verbose);
static bool CreateTar(const char* outFileName,
const std::vector<std::string>& files,
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;
}