mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-03 04:40:18 -05:00
cmSystemTools: Add EnvDiff class to hold ENVIRONMENT_MODIFICATION logic
Prepare to re-use this logic when enhancing `cmake -E env`.
This commit is contained in:
@@ -6,9 +6,12 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/optional>
|
||||
#include <cm/string_view>
|
||||
|
||||
#include "cmsys/Process.h"
|
||||
@@ -377,6 +380,30 @@ public:
|
||||
/** Append multiple variables to the current environment. */
|
||||
static void AppendEnv(std::vector<std::string> const& env);
|
||||
|
||||
/**
|
||||
* Helper class to represent an environment diff directly. This is to avoid
|
||||
* repeated in-place environment modification (i.e. via setenv/putenv), which
|
||||
* could be slow.
|
||||
*/
|
||||
class EnvDiff
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Apply an ENVIRONMENT_MODIFICATION operation to this diff. Returns
|
||||
* false and issues an error on parse failure.
|
||||
*/
|
||||
bool ParseOperation(const std::string& envmod);
|
||||
|
||||
/**
|
||||
* Apply this diff to the actual environment, optionally writing out the
|
||||
* modifications to a CTest-compatible measurement stream.
|
||||
*/
|
||||
void ApplyToCurrentEnv(std::ostringstream* measurement = nullptr);
|
||||
|
||||
private:
|
||||
std::map<std::string, cm::optional<std::string>> diff;
|
||||
};
|
||||
|
||||
/** Helper class to save and restore the environment.
|
||||
Instantiate this class as an automatic variable on
|
||||
the stack. Its constructor saves a copy of the current
|
||||
|
||||
Reference in New Issue
Block a user