[cmake-developers] [PATCH] Added FILTER subcommand to list command
In response to issue 0003986, I've implemented a FILTER subcommand to the "list" command that filters a list using a regular expression. This doesn't implement an optional "OUTPUT_VARIABLE" parameter. There was a discussion on the issue as to whether or not the user using a macro would be a better option. Therefore I've submitted a sample macro for the reporter on the issue as well if this patch isn't accepted. --- Help/command/list.rst | 12 +++-- Source/cmListCommand.cxx | 54 ++ Source/cmListCommand.h | 1 + Tests/RunCMake/list/EmptyFilter-result.txt | 1 + Tests/RunCMake/list/EmptyFilter-stderr.txt | 0 Tests/RunCMake/list/EmptyFilter.cmake | 2 + Tests/RunCMake/list/FILTER-InvalidRegex-result.txt | 1 + Tests/RunCMake/list/FILTER-InvalidRegex-stderr.txt | 4 ++ Tests/RunCMake/list/FILTER-InvalidRegex.cmake | 2 + Tests/RunCMake/list/FILTER-NotList-result.txt | 1 + Tests/RunCMake/list/FILTER-NotList-stderr.txt | 4 ++ Tests/RunCMake/list/FILTER-NotList.cmake | 2 + .../list/FILTER-TooManyArguments-result.txt| 1 + .../list/FILTER-TooManyArguments-stderr.txt| 4 ++ Tests/RunCMake/list/FILTER-TooManyArguments.cmake | 1 + Tests/RunCMake/list/FILTER-Valid0-result.txt | 1 + Tests/RunCMake/list/FILTER-Valid0-stderr.txt | 2 + Tests/RunCMake/list/FILTER-Valid0.cmake| 4 ++ Tests/RunCMake/list/RunCMakeTest.cmake | 6 +++ 19 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 Tests/RunCMake/list/EmptyFilter-result.txt create mode 100644 Tests/RunCMake/list/EmptyFilter-stderr.txt create mode 100644 Tests/RunCMake/list/EmptyFilter.cmake create mode 100644 Tests/RunCMake/list/FILTER-InvalidRegex-result.txt create mode 100644 Tests/RunCMake/list/FILTER-InvalidRegex-stderr.txt create mode 100644 Tests/RunCMake/list/FILTER-InvalidRegex.cmake create mode 100644 Tests/RunCMake/list/FILTER-NotList-result.txt create mode 100644 Tests/RunCMake/list/FILTER-NotList-stderr.txt create mode 100644 Tests/RunCMake/list/FILTER-NotList.cmake create mode 100644 Tests/RunCMake/list/FILTER-TooManyArguments-result.txt create mode 100644 Tests/RunCMake/list/FILTER-TooManyArguments-stderr.txt create mode 100644 Tests/RunCMake/list/FILTER-TooManyArguments.cmake create mode 100644 Tests/RunCMake/list/FILTER-Valid0-result.txt create mode 100644 Tests/RunCMake/list/FILTER-Valid0-stderr.txt create mode 100644 Tests/RunCMake/list/FILTER-Valid0.cmake diff --git a/Help/command/list.rst b/Help/command/list.rst index a7a05c7..797cc14 100644 --- a/Help/command/list.rst +++ b/Help/command/list.rst @@ -9,6 +9,7 @@ List operations. list(GET [ ...] ) list(APPEND [ ...]) + list(FILTER ) list(FIND ) list(INSERT[ ...]) list(REMOVE_ITEM [ ...]) @@ -23,6 +24,11 @@ List operations. ``APPEND`` will append elements to the list. +``FILTER`` will remove the items from the list that match the given regular +expression. +For more information on regular expressions see also the :command:`string` +command. + ``FIND`` will return the index of the element specified in the list or -1 if it wasn't found. @@ -38,9 +44,9 @@ difference is that ``REMOVE_ITEM`` will remove the given items, while ``SORT`` sorts the list in-place alphabetically. -The list subcommands ``APPEND``, ``INSERT``, ``REMOVE_AT``, ``REMOVE_ITEM``, -``REMOVE_DUPLICATES``, ``REVERSE`` and ``SORT`` may create new values for -the list within the current CMake variable scope. Similar to the +The list subcommands ``APPEND``, ``INSERT``, ``FILTER``, ``REMOVE_AT``, +``REMOVE_ITEM``, ``REMOVE_DUPLICATES``, ``REVERSE`` and ``SORT`` may create new +values for the list within the current CMake variable scope. Similar to the :command:`set` command, the LIST command creates new variable values in the current scope, even if the list itself is actually defined in a parent scope. To propagate the results of these operations upwards, use diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 6041fb7..bafd647 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -14,6 +14,7 @@ #include #include "cmAlgorithms.h" +#include #include // required for atoi #include #include @@ -68,6 +69,10 @@ bool cmListCommand { return this->HandleReverseCommand(args); } + if(subCommand == "FILTER") +{ +return this->HandleFilterCommand(args); +} std::string e = "does not recognize sub-command "+subCommand; this->SetError(e); @@ -517,3 +522,52 @@ bool cmListCommand::HandleRemoveAtCommand( return true; } +// +class MatchesRegex { +public: + MatchesRegex(cmsys::RegularExpression& in_regex) : regex(in_regex) {} + + bool operator()(const std::string& target) { +re
[cmake-developers] [PATCH] Added FILTER subcommand to list command
--- Taking the previous comments into consideration, the filter subcommand is now of the format: list(FILTER REGEX ) so that the user can choose to include or exclude matches, and so that it's easier to add future modes of operation to the subcommand. I opted for list(FILTER REGEX ) rather than list(FILTER REGEX ) because I think that it reads more nicely this way around. Ashley Help/command/list.rst | 13 ++- Source/cmListCommand.cxx | 109 + Source/cmListCommand.h | 6 ++ Tests/RunCMake/list/EmptyFilterRegex-result.txt| 1 + Tests/RunCMake/list/EmptyFilterRegex-stderr.txt| 0 Tests/RunCMake/list/EmptyFilterRegex.cmake | 2 + Tests/RunCMake/list/FILTER-NotList-result.txt | 1 + Tests/RunCMake/list/FILTER-NotList-stderr.txt | 4 + Tests/RunCMake/list/FILTER-NotList.cmake | 2 + .../list/FILTER-REGEX-InvalidMode-result.txt | 1 + .../list/FILTER-REGEX-InvalidMode-stderr.txt | 4 + Tests/RunCMake/list/FILTER-REGEX-InvalidMode.cmake | 2 + .../list/FILTER-REGEX-InvalidOperator-result.txt | 1 + .../list/FILTER-REGEX-InvalidOperator-stderr.txt | 4 + .../list/FILTER-REGEX-InvalidOperator.cmake| 2 + .../list/FILTER-REGEX-InvalidRegex-result.txt | 1 + .../list/FILTER-REGEX-InvalidRegex-stderr.txt | 4 + .../RunCMake/list/FILTER-REGEX-InvalidRegex.cmake | 2 + .../list/FILTER-REGEX-TooManyArguments-result.txt | 1 + .../list/FILTER-REGEX-TooManyArguments-stderr.txt | 4 + .../list/FILTER-REGEX-TooManyArguments.cmake | 2 + Tests/RunCMake/list/FILTER-REGEX-Valid0-result.txt | 1 + Tests/RunCMake/list/FILTER-REGEX-Valid0-stderr.txt | 2 + Tests/RunCMake/list/FILTER-REGEX-Valid0.cmake | 4 + Tests/RunCMake/list/FILTER-REGEX-Valid1-result.txt | 1 + Tests/RunCMake/list/FILTER-REGEX-Valid1-stderr.txt | 2 + Tests/RunCMake/list/FILTER-REGEX-Valid1.cmake | 4 + Tests/RunCMake/list/RunCMakeTest.cmake | 9 ++ 28 files changed, 186 insertions(+), 3 deletions(-) create mode 100644 Tests/RunCMake/list/EmptyFilterRegex-result.txt create mode 100644 Tests/RunCMake/list/EmptyFilterRegex-stderr.txt create mode 100644 Tests/RunCMake/list/EmptyFilterRegex.cmake create mode 100644 Tests/RunCMake/list/FILTER-NotList-result.txt create mode 100644 Tests/RunCMake/list/FILTER-NotList-stderr.txt create mode 100644 Tests/RunCMake/list/FILTER-NotList.cmake create mode 100644 Tests/RunCMake/list/FILTER-REGEX-InvalidMode-result.txt create mode 100644 Tests/RunCMake/list/FILTER-REGEX-InvalidMode-stderr.txt create mode 100644 Tests/RunCMake/list/FILTER-REGEX-InvalidMode.cmake create mode 100644 Tests/RunCMake/list/FILTER-REGEX-InvalidOperator-result.txt create mode 100644 Tests/RunCMake/list/FILTER-REGEX-InvalidOperator-stderr.txt create mode 100644 Tests/RunCMake/list/FILTER-REGEX-InvalidOperator.cmake create mode 100644 Tests/RunCMake/list/FILTER-REGEX-InvalidRegex-result.txt create mode 100644 Tests/RunCMake/list/FILTER-REGEX-InvalidRegex-stderr.txt create mode 100644 Tests/RunCMake/list/FILTER-REGEX-InvalidRegex.cmake create mode 100644 Tests/RunCMake/list/FILTER-REGEX-TooManyArguments-result.txt create mode 100644 Tests/RunCMake/list/FILTER-REGEX-TooManyArguments-stderr.txt create mode 100644 Tests/RunCMake/list/FILTER-REGEX-TooManyArguments.cmake create mode 100644 Tests/RunCMake/list/FILTER-REGEX-Valid0-result.txt create mode 100644 Tests/RunCMake/list/FILTER-REGEX-Valid0-stderr.txt create mode 100644 Tests/RunCMake/list/FILTER-REGEX-Valid0.cmake create mode 100644 Tests/RunCMake/list/FILTER-REGEX-Valid1-result.txt create mode 100644 Tests/RunCMake/list/FILTER-REGEX-Valid1-stderr.txt create mode 100644 Tests/RunCMake/list/FILTER-REGEX-Valid1.cmake diff --git a/Help/command/list.rst b/Help/command/list.rst index a7a05c7..f6b75bc 100644 --- a/Help/command/list.rst +++ b/Help/command/list.rst @@ -9,6 +9,7 @@ List operations. list(GET [ ...] ) list(APPEND [ ...]) + list(FILTER REGEX ) list(FIND ) list(INSERT[ ...]) list(REMOVE_ITEM [ ...]) @@ -23,6 +24,12 @@ List operations. ``APPEND`` will append elements to the list. +``FILTER`` will include or remove items from the list that match the +mode's pattern. +In ``REGEX`` mode, items will be matched against the given regular expression. +For more information on regular expressions see also the :command:`string` +command. + ``FIND`` will return the index of the element specified in the list or -1 if it wasn't found. @@ -38,9 +45,9 @@ difference is that ``REMOVE_ITEM`` will remove the given items, while ``SORT`` sorts the list in-place alphabetically. -The list subcommands ``APPEND``, ``INSERT``, ``REMOVE_AT``, ``REMOVE_ITEM``, -``REMOVE_DUPLICATES``, ``REVERSE`` and ``SORT`` may create new values for -the list within the current CMake variable scope. Simi
Re: [cmake-developers] [PATCH] Added FILTER subcommand to list command
On 01/16/2016 12:10 PM, Ashley Whetter wrote: > In response to issue 0003986, I've implemented a FILTER subcommand to the > "list" > command that filters a list using a regular expression. Nice work. The change looks good except I'd like to bikeshed the name of the option. This is the first list() API that will use a regular expression as an argument, so I think "REGEX" should appear in the name, e.g. "FILTER_REGEX". Also the name should clarify whether the filter result includes or excludes the matches. Perhaps list(FILTER_REGEX_INCLUDE ) ? Alternatively the name could still be "FILTER" and there could be named arguments to control the rest of the details. I have no preference but would welcome other opinions. Thanks, -Brad -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH] Added FILTER subcommand to list command
I am in favour to use FILTER keyword and named arguments for filter behaviour. I think this approach is more elegant and also more flexible for any future enhancements. On 19/01/16 16:43, "cmake-developers on behalf of Brad King" wrote: >On 01/16/2016 12:10 PM, Ashley Whetter wrote: >> In response to issue 0003986, I've implemented a FILTER subcommand to the >> "list" >> command that filters a list using a regular expression. > >Nice work. The change looks good except I'd like to bikeshed the name >of the option. This is the first list() API that will use a regular >expression as an argument, so I think "REGEX" should appear in the >name, e.g. "FILTER_REGEX". Also the name should clarify whether the >filter result includes or excludes the matches. Perhaps > > list(FILTER_REGEX_INCLUDE ) > >? Alternatively the name could still be "FILTER" and there could >be named arguments to control the rest of the details. I have no >preference but would welcome other opinions. > >Thanks, >-Brad > >-- > >Powered by www.kitware.com > >Please keep messages on-topic and check the CMake FAQ at: >http://www.cmake.org/Wiki/CMake_FAQ > >Kitware offers various services to support the CMake community. For more >information on each offering, please visit: > >CMake Support: http://cmake.org/cmake/help/support.html >CMake Consulting: http://cmake.org/cmake/help/consulting.html >CMake Training Courses: http://cmake.org/cmake/help/training.html > >Visit other Kitware open-source projects at >http://www.kitware.com/opensource/opensource.html > >Follow this link to subscribe/unsubscribe: >http://public.kitware.com/mailman/listinfo/cmake-developers -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
Re: [cmake-developers] [PATCH] Added FILTER subcommand to list command
On 01/28/2016 04:29 PM, Ashley Whetter wrote: > Taking the previous comments into consideration Nice work. Applied: list: Add FILTER subcommand (#3986) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0205f882 > I opted for > list(FILTER REGEX ) > rather than > list(FILTER REGEX ) > because I think that it reads more nicely this way around. Yes, I agree. Thanks! -Brad -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers