diff options
author | Cristian Le <git@lecris.dev> | 2024-01-03 19:34:56 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-01-09 21:36:55 (GMT) |
commit | fa00928bcded97d20c9aa2813f68f1df41591125 (patch) | |
tree | c84c88485c075b94d2f92d3e6467fb776a217f41 /Source/cmFileCommand.cxx | |
parent | ff0085cf74eb10a7e5f9c906258022c6b8b68413 (diff) | |
download | CMake-fa00928bcded97d20c9aa2813f68f1df41591125.zip CMake-fa00928bcded97d20c9aa2813f68f1df41591125.tar.gz CMake-fa00928bcded97d20c9aa2813f68f1df41591125.tar.bz2 |
file: `STRINGS` + `REGEX` store match results
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r-- | Source/cmFileCommand.cxx | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index c1b7b48..e3f5b96 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -315,6 +315,7 @@ bool HandleStringsCommand(std::vector<std::string> const& args, unsigned int limit_count = 0; cmsys::RegularExpression regex; bool have_regex = false; + bool store_regex = true; bool newline_consume = false; bool hex_conversion_enabled = true; enum @@ -399,6 +400,26 @@ bool HandleStringsCommand(std::vector<std::string> const& args, return false; } have_regex = true; + switch (status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0159)) { + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::NEW: + // store_regex = true + break; + case cmPolicies::WARN: + if (status.GetMakefile().PolicyOptionalWarningEnabled( + "CMAKE_POLICY_WARNING_CMP0159")) { + status.GetMakefile().IssueMessage( + MessageType::AUTHOR_WARNING, + cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0159), '\n', + "For compatibility, CMake is leaving CMAKE_MATCH_<n> " + "unchanged.")); + } + CM_FALLTHROUGH; + case cmPolicies::OLD: + store_regex = false; + break; + } arg_mode = arg_none; } else if (arg_mode == arg_encoding) { if (args[i] == "UTF-8") { @@ -539,6 +560,10 @@ bool HandleStringsCommand(std::vector<std::string> const& args, // string matches the requirements. The length may now be as // low as zero since blank lines are allowed. if (s.length() >= minlen && (!have_regex || regex.find(s))) { + if (store_regex) { + status.GetMakefile().ClearMatches(); + status.GetMakefile().StoreMatches(regex); + } output_size += static_cast<int>(s.size()) + 1; if (limit_output >= 0 && output_size >= limit_output) { s.clear(); @@ -555,6 +580,10 @@ bool HandleStringsCommand(std::vector<std::string> const& args, // be at least one no matter what the user specified. if (s.length() >= minlen && !s.empty() && (!have_regex || regex.find(s))) { + if (store_regex) { + status.GetMakefile().ClearMatches(); + status.GetMakefile().StoreMatches(regex); + } output_size += static_cast<int>(s.size()) + 1; if (limit_output >= 0 && output_size >= limit_output) { s.clear(); @@ -572,6 +601,10 @@ bool HandleStringsCommand(std::vector<std::string> const& args, if (maxlen > 0 && s.size() == maxlen) { // Terminate a string if the maximum length is reached. if (s.length() >= minlen && (!have_regex || regex.find(s))) { + if (store_regex) { + status.GetMakefile().ClearMatches(); + status.GetMakefile().StoreMatches(regex); + } output_size += static_cast<int>(s.size()) + 1; if (limit_output >= 0 && output_size >= limit_output) { s.clear(); @@ -588,6 +621,10 @@ bool HandleStringsCommand(std::vector<std::string> const& args, // matches the requirements. if ((!limit_count || strings.size() < limit_count) && !s.empty() && s.length() >= minlen && (!have_regex || regex.find(s))) { + if (store_regex) { + status.GetMakefile().ClearMatches(); + status.GetMakefile().StoreMatches(regex); + } output_size += static_cast<int>(s.size()) + 1; if (limit_output < 0 || output_size < limit_output) { strings.push_back(s); |