[Cmake-commits] [cmake-commits] david.cole committed cmCTest.cxx 1.340 1.341 cmCTest.h 1.102 1.103 cmSystemTools.cxx 1.385 1.386 cmSystemTools.h 1.155 1.156
cmake-commits at cmake.org
cmake-commits at cmake.org
Wed Nov 26 14:38:45 EST 2008
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv744/Source
Modified Files:
cmCTest.cxx cmCTest.h cmSystemTools.cxx cmSystemTools.h
Log Message:
ENH: Implement feature request from issue 7885. Allow setting environment variables on a per-test basis for ctest using set_test_properties ENVIRONMENT.
Index: cmCTest.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCTest.h,v
retrieving revision 1.102
retrieving revision 1.103
diff -C 2 -d -r1.102 -r1.103
*** cmCTest.h 22 Sep 2008 18:04:12 -0000 1.102
--- cmCTest.h 26 Nov 2008 19:38:42 -0000 1.103
***************
*** 247,253 ****
//! Run command specialized for tests. Returns process status and retVal is
! // return value or exception.
int RunTest(std::vector<const char*> args, std::string* output, int *retVal,
! std::ostream* logfile, double testTimeOut);
/**
--- 247,255 ----
//! Run command specialized for tests. Returns process status and retVal is
! // return value or exception. If environment is non-null, it is used to set
! // environment variables prior to running the test. After running the test,
! // environment variables are restored to their previous values.
int RunTest(std::vector<const char*> args, std::string* output, int *retVal,
! std::ostream* logfile, double testTimeOut, std::vector<std::string>* environment);
/**
Index: cmSystemTools.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSystemTools.h,v
retrieving revision 1.155
retrieving revision 1.156
diff -C 2 -d -r1.155 -r1.156
*** cmSystemTools.h 14 Aug 2008 13:53:26 -0000 1.155
--- cmSystemTools.h 26 Nov 2008 19:38:43 -0000 1.156
***************
*** 336,339 ****
--- 336,350 ----
/** Get the list of all environment variables */
static std::vector<std::string> GetEnvironmentVariables();
+
+ /** Append multiple variables to the current environment.
+ Return the original environment, as it was before the
+ append. */
+ static std::vector<std::string> AppendEnv(
+ std::vector<std::string>* env);
+
+ /** Restore the full environment to "env" - use after
+ AppendEnv to put the environment back to the way it
+ was. */
+ static void RestoreEnv(const std::vector<std::string>& env);
#endif
Index: cmSystemTools.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSystemTools.cxx,v
retrieving revision 1.385
retrieving revision 1.386
diff -C 2 -d -r1.385 -r1.386
*** cmSystemTools.cxx 15 Sep 2008 21:53:27 -0000 1.385
--- cmSystemTools.cxx 26 Nov 2008 19:38:43 -0000 1.386
***************
*** 1557,1560 ****
--- 1557,1561 ----
#ifdef CMAKE_BUILD_WITH_CMAKE
+ //----------------------------------------------------------------------
bool cmSystemTools::UnsetEnv(const char* value)
{
***************
*** 1569,1572 ****
--- 1570,1574 ----
}
+ //----------------------------------------------------------------------
std::vector<std::string> cmSystemTools::GetEnvironmentVariables()
{
***************
*** 1579,1582 ****
--- 1581,1632 ----
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
Index: cmCTest.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmCTest.cxx,v
retrieving revision 1.340
retrieving revision 1.341
diff -C 2 -d -r1.340 -r1.341
*** cmCTest.cxx 23 Nov 2008 15:49:45 -0000 1.340
--- cmCTest.cxx 26 Nov 2008 19:38:40 -0000 1.341
***************
*** 1106,1111 ****
int cmCTest::RunTest(std::vector<const char*> argv,
std::string* output, int *retVal,
! std::ostream* log, double testTimeOut)
{
// determine how much time we have
double timeout = this->GetRemainingTimeAllowed() - 120;
--- 1106,1115 ----
int cmCTest::RunTest(std::vector<const char*> argv,
std::string* output, int *retVal,
! 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
double timeout = this->GetRemainingTimeAllowed() - 120;
***************
*** 1157,1160 ****
--- 1161,1169 ----
std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory();
+ if (modifyEnv)
+ {
+ origEnv = cmSystemTools::AppendEnv(environment);
+ }
+
*retVal = inst.Run(args, output);
if ( *log )
***************
*** 1167,1170 ****
--- 1176,1185 ----
"Internal cmCTest object used to run test." << std::endl
<< *output << std::endl);
+
+ if (modifyEnv)
+ {
+ cmSystemTools::RestoreEnv(origEnv);
+ }
+
return cmsysProcess_State_Exited;
}
***************
*** 1175,1178 ****
--- 1190,1198 ----
}
+ if (modifyEnv)
+ {
+ origEnv = cmSystemTools::AppendEnv(environment);
+ }
+
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*argv.begin());
***************
*** 1234,1237 ****
--- 1254,1262 ----
cmsysProcess_Delete(cp);
+ if (modifyEnv)
+ {
+ cmSystemTools::RestoreEnv(origEnv);
+ }
+
return result;
}
More information about the Cmake-commits
mailing list