summaryrefslogtreecommitdiffstats
path: root/Source/cmCTest.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/cmCTest.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/cmCTest.cxx')
-rw-r--r--Source/cmCTest.cxx23
1 files changed, 8 insertions, 15 deletions
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index 3f7fdc7..4aff64b 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -48,7 +48,7 @@
#include <float.h>
#include <ctype.h>
-#include <memory> // auto_ptr
+#include <cmsys/auto_ptr.hxx>
#include <cm_zlib.h>
#include <cmsys/Base64.h>
@@ -509,7 +509,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
cmake cm;
cmGlobalGenerator gg;
gg.SetCMakeInstance(&cm);
- std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
+ cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
cmMakefile *mf = lg->GetMakefile();
if ( !this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), mf) )
{
@@ -1277,7 +1277,6 @@ int cmCTest::RunTest(std::vector<const char*> argv,
std::ostream* log, double testTimeOut,
std::vector<std::string>* environment)
{
- std::vector<std::string> origEnv;
bool modifyEnv = (environment && environment->size()>0);
// determine how much time we have
@@ -1334,9 +1333,11 @@ int cmCTest::RunTest(std::vector<const char*> argv,
}
std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory();
+ cmsys::auto_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv;
if (modifyEnv)
{
- origEnv = cmSystemTools::AppendEnv(environment);
+ saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment);
+ cmSystemTools::AppendEnv(*environment);
}
*retVal = inst.Run(args, output);
@@ -1351,11 +1352,6 @@ int cmCTest::RunTest(std::vector<const char*> argv,
"Internal cmCTest object used to run test." << std::endl
<< *output << std::endl);
- if (modifyEnv)
- {
- cmSystemTools::RestoreEnv(origEnv);
- }
-
return cmsysProcess_State_Exited;
}
std::vector<char> tempOutput;
@@ -1364,9 +1360,11 @@ int cmCTest::RunTest(std::vector<const char*> argv,
*output = "";
}
+ cmsys::auto_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv;
if (modifyEnv)
{
- origEnv = cmSystemTools::AppendEnv(environment);
+ saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment);
+ cmSystemTools::AppendEnv(*environment);
}
cmsysProcess* cp = cmsysProcess_New();
@@ -1436,11 +1434,6 @@ int cmCTest::RunTest(std::vector<const char*> argv,
}
cmsysProcess_Delete(cp);
- if (modifyEnv)
- {
- cmSystemTools::RestoreEnv(origEnv);
- }
-
return result;
}