From 7c47fd8cd1e7d9aae60412ce7544fdfa82c9e798 Mon Sep 17 00:00:00 2001 From: Bartosz Kosiorek Date: Fri, 8 Mar 2019 17:04:17 +0100 Subject: cmake: tar: Display warning when no files provided during archive creation --- Source/cmcmd.cxx | 4 ++++ Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake | 9 +++++---- Tests/RunCMake/CommandLineTar/end-opt2-stderr.txt | 1 + Tests/RunCMake/CommandLineTar/without-files-stderr.txt | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 Tests/RunCMake/CommandLineTar/end-opt2-stderr.txt create mode 100644 Tests/RunCMake/CommandLineTar/without-files-stderr.txt diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index f996a3e..0828a16 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1114,6 +1114,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) return 1; } } else if (flags.find_first_of('c') != std::string::npos) { + if (files.empty()) { + cmSystemTools::Message("tar: No files or directories specified", + "Warning"); + } if (!cmSystemTools::CreateTar(outFile.c_str(), files, compress, verbose, mtime, format)) { cmSystemTools::Error("Problem creating tar: " + outFile); diff --git a/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake b/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake index 12635db..24bb9a9 100644 --- a/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake @@ -4,6 +4,7 @@ function(external_command_test NAME) run_cmake_command(${NAME} ${CMAKE_COMMAND} -E ${ARGN}) endfunction() +external_command_test(without-files tar cvf bad.tar) external_command_test(bad-opt1 tar cvf bad.tar --bad) external_command_test(bad-mtime1 tar cvf bad.tar --mtime=bad .) external_command_test(bad-from1 tar cvf bad.tar --files-from=bad) @@ -13,10 +14,10 @@ external_command_test(bad-from4 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LI external_command_test(bad-from5 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from5.txt) external_command_test(end-opt1 tar cvf bad.tar -- --bad) external_command_test(end-opt2 tar cvf bad.tar --) -external_command_test(mtime tar cvf bad.tar "--mtime=1970-01-01 00:00:00 UTC") -external_command_test(bad-format tar cvf bad.tar "--format=bad-format") -external_command_test(zip-bz2 tar cvjf bad.tar "--format=zip") -external_command_test(7zip-gz tar cvzf bad.tar "--format=7zip") +external_command_test(mtime tar cvf bad.tar "--mtime=1970-01-01 00:00:00 UTC" .) +external_command_test(bad-format tar cvf bad.tar "--format=bad-format" .) +external_command_test(zip-bz2 tar cvjf bad.tar "--format=zip" .) +external_command_test(7zip-gz tar cvzf bad.tar "--format=7zip" .) run_cmake(7zip) run_cmake(gnutar) diff --git a/Tests/RunCMake/CommandLineTar/end-opt2-stderr.txt b/Tests/RunCMake/CommandLineTar/end-opt2-stderr.txt new file mode 100644 index 0000000..70166f5 --- /dev/null +++ b/Tests/RunCMake/CommandLineTar/end-opt2-stderr.txt @@ -0,0 +1 @@ +^tar: No files or directories specified diff --git a/Tests/RunCMake/CommandLineTar/without-files-stderr.txt b/Tests/RunCMake/CommandLineTar/without-files-stderr.txt new file mode 100644 index 0000000..70166f5 --- /dev/null +++ b/Tests/RunCMake/CommandLineTar/without-files-stderr.txt @@ -0,0 +1 @@ +^tar: No files or directories specified -- cgit v0.12