diff options
author | David Cole <david.cole@kitware.com> | 2008-11-26 19:38:43 (GMT) |
---|---|---|
committer | David Cole <david.cole@kitware.com> | 2008-11-26 19:38:43 (GMT) |
commit | ceaef94cccf10a02e1bcce29d3cfa6955acf4565 (patch) | |
tree | a0cbd04050fee7082c6e3e3ad38c73877fa6f806 /Source/cmSystemTools.cxx | |
parent | 003dbff85d58d6fc2668f2e1819b413a6357b2bc (diff) | |
download | CMake-ceaef94cccf10a02e1bcce29d3cfa6955acf4565.zip CMake-ceaef94cccf10a02e1bcce29d3cfa6955acf4565.tar.gz CMake-ceaef94cccf10a02e1bcce29d3cfa6955acf4565.tar.bz2 |
ENH: Implement feature request from issue 7885. Allow setting environment variables on a per-test basis for ctest using set_test_properties ENVIRONMENT.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r-- | Source/cmSystemTools.cxx | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 298d779..e47ca19 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1556,6 +1556,7 @@ bool cmSystemTools::PutEnv(const char* value) } #ifdef CMAKE_BUILD_WITH_CMAKE +//---------------------------------------------------------------------- bool cmSystemTools::UnsetEnv(const char* value) { #if !defined(HAVE_UNSETENV) @@ -1568,6 +1569,7 @@ bool cmSystemTools::UnsetEnv(const char* value) #endif } +//---------------------------------------------------------------------- std::vector<std::string> cmSystemTools::GetEnvironmentVariables() { std::vector<std::string> env; @@ -1578,6 +1580,54 @@ std::vector<std::string> cmSystemTools::GetEnvironmentVariables() } return env; } + +//---------------------------------------------------------------------- +std::vector<std::string> cmSystemTools::AppendEnv( + std::vector<std::string>* env) +{ + std::vector<std::string> origEnv = GetEnvironmentVariables(); + + if (env && env->size()>0) + { + std::vector<std::string>::const_iterator eit; + + for (eit = env->begin(); eit!= env->end(); ++eit) + { + PutEnv(eit->c_str()); + } + } + + return origEnv; +} + +//---------------------------------------------------------------------- +void cmSystemTools::RestoreEnv(const std::vector<std::string>& env) +{ + std::vector<std::string>::const_iterator eit; + + // First clear everything in the current environment: + // + std::vector<std::string> currentEnv = GetEnvironmentVariables(); + for (eit = currentEnv.begin(); eit!= currentEnv.end(); ++eit) + { + std::string var(*eit); + + int pos = var.find("="); + if (pos != std::string::npos) + { + var = var.substr(0, pos); + } + + UnsetEnv(var.c_str()); + } + + // Then put back each entry from the original environment: + // + for (eit = env.begin(); eit!= env.end(); ++eit) + { + PutEnv(eit->c_str()); + } +} #endif void cmSystemTools::EnableVSConsoleOutput() |