From dfff470d156b70b71a2349b51dee4da4275a75bd Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 29 Jun 2022 16:26:33 -0400 Subject: file(ARCHIVE*): Add test for keyword arguments with missing values --- Tests/RunCMake/File_Archive/RunCMakeTest.cmake | 3 +++ Tests/RunCMake/File_Archive/create-missing-args-result.txt | 1 + Tests/RunCMake/File_Archive/create-missing-args-stderr.txt | 9 +++++++++ Tests/RunCMake/File_Archive/create-missing-args.cmake | 8 ++++++++ Tests/RunCMake/File_Archive/extract-missing-args-result.txt | 1 + Tests/RunCMake/File_Archive/extract-missing-args-stderr.txt | 7 +++++++ Tests/RunCMake/File_Archive/extract-missing-args.cmake | 5 +++++ 7 files changed, 34 insertions(+) create mode 100644 Tests/RunCMake/File_Archive/create-missing-args-result.txt create mode 100644 Tests/RunCMake/File_Archive/create-missing-args-stderr.txt create mode 100644 Tests/RunCMake/File_Archive/create-missing-args.cmake create mode 100644 Tests/RunCMake/File_Archive/extract-missing-args-result.txt create mode 100644 Tests/RunCMake/File_Archive/extract-missing-args-stderr.txt create mode 100644 Tests/RunCMake/File_Archive/extract-missing-args.cmake diff --git a/Tests/RunCMake/File_Archive/RunCMakeTest.cmake b/Tests/RunCMake/File_Archive/RunCMakeTest.cmake index 3908f42..dad0dd3 100644 --- a/Tests/RunCMake/File_Archive/RunCMakeTest.cmake +++ b/Tests/RunCMake/File_Archive/RunCMakeTest.cmake @@ -13,6 +13,9 @@ run_cmake(zip) # Extracting only selected files or directories run_cmake(zip-filtered) +run_cmake(create-missing-args) +run_cmake(extract-missing-args) + run_cmake(unsupported-format) run_cmake(zip-with-bad-compression) run_cmake(7zip-with-bad-compression) diff --git a/Tests/RunCMake/File_Archive/create-missing-args-result.txt b/Tests/RunCMake/File_Archive/create-missing-args-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/File_Archive/create-missing-args-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/File_Archive/create-missing-args-stderr.txt b/Tests/RunCMake/File_Archive/create-missing-args-stderr.txt new file mode 100644 index 0000000..ecfe401 --- /dev/null +++ b/Tests/RunCMake/File_Archive/create-missing-args-stderr.txt @@ -0,0 +1,9 @@ +^CMake Error at create-missing-args.cmake:[0-9]+ \(file\): + file Keywords missing values: + + OUTPUT + FORMAT + COMPRESSION + COMPRESSION_LEVEL +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/File_Archive/create-missing-args.cmake b/Tests/RunCMake/File_Archive/create-missing-args.cmake new file mode 100644 index 0000000..a0c84d2 --- /dev/null +++ b/Tests/RunCMake/File_Archive/create-missing-args.cmake @@ -0,0 +1,8 @@ +file(ARCHIVE_CREATE + OUTPUT # missing output path + FORMAT # missing output format + COMPRESSION # missing compression type + COMPRESSION_LEVEL # missing compression level + MTIME # missing modification time + PATHS # no paths + ) diff --git a/Tests/RunCMake/File_Archive/extract-missing-args-result.txt b/Tests/RunCMake/File_Archive/extract-missing-args-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/File_Archive/extract-missing-args-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/File_Archive/extract-missing-args-stderr.txt b/Tests/RunCMake/File_Archive/extract-missing-args-stderr.txt new file mode 100644 index 0000000..96c779f --- /dev/null +++ b/Tests/RunCMake/File_Archive/extract-missing-args-stderr.txt @@ -0,0 +1,7 @@ +^CMake Error at extract-missing-args.cmake:[0-9]+ \(file\): + file Keywords missing values: + + INPUT + DESTINATION +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/File_Archive/extract-missing-args.cmake b/Tests/RunCMake/File_Archive/extract-missing-args.cmake new file mode 100644 index 0000000..21c5d99 --- /dev/null +++ b/Tests/RunCMake/File_Archive/extract-missing-args.cmake @@ -0,0 +1,5 @@ +file(ARCHIVE_EXTRACT + INPUT # missing input + DESTINATION # missing destination + PATTERNS # no patterns + ) -- cgit v0.12 From 7c83265e594247013f4cba9b45c252a9425ad657 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 29 Jun 2022 17:08:03 -0400 Subject: file(ARCHIVE*): Simplify acceptance of empty list arguments In `cmArgumentParser`, a keyword bound to a `std::vector` value is reported in the list of keywords with missing values if the keyword appears followed by an empty list. For cases where we want to tolerate empty lists, clients need to filter out such keywords themselves before producing an error message. This may be improved in the future, but that is out of scope here. In commit c7e1198a23 (file: Add ARCHIVE_{CREATE|EXTRACT} subcommands, 2020-03-13, v3.18.0-rc1~530^2), a pattern for filtering out keywords that accept empty lists was copied from commit c998c8d560 (file(GET_RUNTIME_DEPENDENCIES): Tolerate empty list arguments, 2020-01-22, v3.17.0-rc1~111^2~1) incorrectly in two ways: * Keywords were included in the filter that do not accept empty lists. * Keywords were not in sorted order, breaking the filter operation. Those two bugs mostly canceled each other out, and the resulting behavior was to correctly report keywords with missing values. However, the `MTIME` keyword was accidentally accepted with no value by pretending the keyword was not given at all. Simplify the logic by removing keywords from the filters that should not be there. Leave `MTIME` in the filter for compatibility. --- Source/cmFileCommand.cxx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 7d05347..1cfe29c 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -3113,6 +3113,7 @@ bool HandleGetRuntimeDependenciesCommand(std::vector const& args, return false; } + // Arguments that are allowed to be empty lists. Keep entries sorted! const std::vector LIST_ARGS = { "DIRECTORIES", "EXECUTABLES", @@ -3402,8 +3403,13 @@ bool HandleArchiveCreateCommand(std::vector const& args, return false; } + // Arguments that are allowed to be empty lists. Keep entries sorted! const std::vector LIST_ARGS = { - "OUTPUT", "FORMAT", "COMPRESSION", "COMPRESSION_LEVEL", "MTIME", "PATHS" + "MTIME", // "MTIME" should not be in this list because it requires one + // value, but it has long been accidentally accepted without + // one and treated as if an empty value were given. + // Fixing this would require a policy. + "PATHS", // "PATHS" is here only so we can issue a custom error below. }; auto kwbegin = keywordsMissingValues.cbegin(); auto kwend = cmRemoveMatching(keywordsMissingValues, LIST_ARGS); @@ -3530,8 +3536,8 @@ bool HandleArchiveExtractCommand(std::vector const& args, return false; } - const std::vector LIST_ARGS = { "INPUT", "DESTINATION", - "PATTERNS" }; + // Arguments that are allowed to be empty lists. Keep entries sorted! + const std::vector LIST_ARGS = { "PATTERNS" }; auto kwbegin = keywordsMissingValues.cbegin(); auto kwend = cmRemoveMatching(keywordsMissingValues, LIST_ARGS); if (kwend != kwbegin) { -- cgit v0.12