mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-02 11:49:55 -06:00
file(ARCHIVE*): Simplify acceptance of empty list arguments
In `cmArgumentParser`, a keyword bound to a `std::vector<std::string>` 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 commitc7e1198a23(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 commitc998c8d560(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.
This commit is contained in:
@@ -3113,6 +3113,7 @@ bool HandleGetRuntimeDependenciesCommand(std::vector<std::string> const& args,
|
||||
return false;
|
||||
}
|
||||
|
||||
// Arguments that are allowed to be empty lists. Keep entries sorted!
|
||||
const std::vector<std::string> LIST_ARGS = {
|
||||
"DIRECTORIES",
|
||||
"EXECUTABLES",
|
||||
@@ -3402,8 +3403,13 @@ bool HandleArchiveCreateCommand(std::vector<std::string> const& args,
|
||||
return false;
|
||||
}
|
||||
|
||||
// Arguments that are allowed to be empty lists. Keep entries sorted!
|
||||
const std::vector<std::string> 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<std::string> const& args,
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::vector<std::string> LIST_ARGS = { "INPUT", "DESTINATION",
|
||||
"PATTERNS" };
|
||||
// Arguments that are allowed to be empty lists. Keep entries sorted!
|
||||
const std::vector<std::string> LIST_ARGS = { "PATTERNS" };
|
||||
auto kwbegin = keywordsMissingValues.cbegin();
|
||||
auto kwend = cmRemoveMatching(keywordsMissingValues, LIST_ARGS);
|
||||
if (kwend != kwbegin) {
|
||||
|
||||
Reference in New Issue
Block a user