cmake -E env: Add --modify flag

When `cmake -E env` is given the `--modify` flag, try to parse the
following argument as an `ENVIRONMENT_MODIFICATION` operation and apply
it to the environment.

This generalizes `--unset=`:

1.  When implementing `ENVIRONMENT_MODIFICATION` features for other CMake
    commands, the `MYVAR=OP:VALUE` strings do not need to be translated
    to OP-specific flags.
2.  This provides a natural and consistent extension point to introduce
    new operations without introducing very many flags.
3.  Users need to learn only one syntax to access the same functionality.

There is one difference between the behavior here as compared to CTest's
interpretation of the `ENVIRONMENT_MODIFICATION` test property.
The `MYVAR=reset:` command when run in `cmake -E env` will reset `MYVAR`
to whatever its value was when `cmake -E env` launched, rather than try
to checkpoint after plain `MYVAR=VALUE` options.  This makes `MYVAR=VALUE`
and `--modify MYVAR=set:VALUE` semantically equivalent.
This commit is contained in:
Alex Reinking
2022-08-14 04:42:11 -04:00
parent 5b949bbb91
commit c9d70a7cc3
19 changed files with 152 additions and 6 deletions
+20 -2
View File
@@ -862,11 +862,29 @@ Available commands are:
Displays arguments as text but no new line.
.. option:: env [--unset=NAME ...] [NAME=VALUE ...] [--] <command> [<arg>...]
.. option:: env [<options>] [--] <command> [<arg>...]
.. versionadded:: 3.1
Run command in a modified environment.
Run command in a modified environment. Options are:
``NAME=VALUE``
Replaces the current value of ``NAME`` with ``VALUE``.
``--unset=NAME``
Unsets the current value of ``NAME``.
``--modify ENVIRONMENT_MODIFICATION``
.. versionadded:: 3.25
Apply a single :prop_test:`ENVIRONMENT_MODIFICATION` operation to the
modified environment.
The ``NAME=VALUE`` and ``--unset=NAME`` options are equivalent to
``--modify NAME=set:VALUE`` and ``--modify NAME=unset:``, respectively.
Note that ``--modify NAME=reset:`` resets ``NAME`` to the value it had
when ``cmake`` launched (or unsets it), not to the most recent
``NAME=VALUE`` option.
.. versionadded:: 3.24
Added support for the double dash argument ``--``. Use ``--`` to stop
+5
View File
@@ -0,0 +1,5 @@
cmake-E-env-modify
------------------
* A new ``--modify`` flag was added to :option:`cmake -E env <cmake_E env>` to support :prop_test:`ENVIRONMENT_MODIFICATION`
operations.