summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2012-04-24 20:24:17 (GMT)
committerBrad King <brad.king@kitware.com>2012-04-24 20:56:14 (GMT)
commitb10c5cbb878af541f4ffa35a9e287c31743c6e97 (patch)
treed812f0b9f60fb650f5f7cbee21bbfe73490f222e /Source/cmSystemTools.cxx
parent93e6069553874e11af8915da68996fb4323d4a52 (diff)
downloadCMake-b10c5cbb878af541f4ffa35a9e287c31743c6e97.zip
CMake-b10c5cbb878af541f4ffa35a9e287c31743c6e97.tar.gz
CMake-b10c5cbb878af541f4ffa35a9e287c31743c6e97.tar.bz2
CTest: Simplify environment save/restore
Replace use of AppendEnv/RestoreEnv pairs with instances of SaveRestoreEnvironment. Simplify the signature of AppendEnv and use it in place of similar loops elsewhere. Move the RestoreEnv implementation inside the SaveRestoreEnvironment destructor which is the only place left that calls it.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx49
1 files changed, 14 insertions, 35 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 1376a48..548fa74 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -1630,33 +1630,28 @@ std::vector<std::string> cmSystemTools::GetEnvironmentVariables()
}
//----------------------------------------------------------------------
-std::vector<std::string> cmSystemTools::AppendEnv(
- std::vector<std::string>* env)
+void cmSystemTools::AppendEnv(std::vector<std::string> const& env)
{
- std::vector<std::string> origEnv = GetEnvironmentVariables();
-
- if (env && env->size()>0)
+ for(std::vector<std::string>::const_iterator eit = env.begin();
+ eit != env.end(); ++eit)
{
- std::vector<std::string>::const_iterator eit;
-
- for (eit = env->begin(); eit!= env->end(); ++eit)
- {
- PutEnv(eit->c_str());
- }
+ cmSystemTools::PutEnv(eit->c_str());
}
-
- return origEnv;
}
//----------------------------------------------------------------------
-void cmSystemTools::RestoreEnv(const std::vector<std::string>& env)
+cmSystemTools::SaveRestoreEnvironment::SaveRestoreEnvironment()
{
- std::vector<std::string>::const_iterator eit;
+ this->Env = cmSystemTools::GetEnvironmentVariables();
+}
+//----------------------------------------------------------------------
+cmSystemTools::SaveRestoreEnvironment::~SaveRestoreEnvironment()
+{
// First clear everything in the current environment:
- //
std::vector<std::string> currentEnv = GetEnvironmentVariables();
- for (eit = currentEnv.begin(); eit!= currentEnv.end(); ++eit)
+ for(std::vector<std::string>::const_iterator
+ eit = currentEnv.begin(); eit != currentEnv.end(); ++eit)
{
std::string var(*eit);
@@ -1666,27 +1661,11 @@ void cmSystemTools::RestoreEnv(const std::vector<std::string>& env)
var = var.substr(0, pos);
}
- UnsetEnv(var.c_str());
+ cmSystemTools::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());
- }
-}
-
-//----------------------------------------------------------------------
-cmSystemTools::SaveRestoreEnvironment::SaveRestoreEnvironment()
-{
- this->Env = cmSystemTools::GetEnvironmentVariables();
-}
-
-//----------------------------------------------------------------------
-cmSystemTools::SaveRestoreEnvironment::~SaveRestoreEnvironment()
-{
- cmSystemTools::RestoreEnv(this->Env);
+ cmSystemTools::AppendEnv(this->Env);
}
#endif