some updates to handle inline cache files and environment variables

This commit is contained in:
Ken Martin 2003-12-09 08:22:55 -05:00
parent ec78910bac
commit e3e4a7892b
1 changed files with 49 additions and 13 deletions

View File

@ -31,7 +31,7 @@
#include <cmsys/Process.h> #include <cmsys/Process.h>
#include <cmsys/Base64.h> #include <cmsys/Base64.h>
#include <stdlib.h> // required for atoi #include <stdlib.h>
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
#include <float.h> #include <float.h>
@ -2591,12 +2591,13 @@ int cmCTest::RunConfigurationScript()
// no popup widows // no popup widows
cmSystemTools::SetRunCommandHideConsole(true); cmSystemTools::SetRunCommandHideConsole(true);
// get some info that should be set // get some info that should be set
cmMakefile *mf = lg->GetMakefile(); cmMakefile *mf = lg->GetMakefile();
const char *srcDir = mf->GetDefinition("CTEST_SOURCE_DIRECTORY"); const char *srcDir = mf->GetDefinition("CTEST_SOURCE_DIRECTORY");
const char *binDir = mf->GetDefinition("CTEST_BINARY_DIRECTORY"); const char *binDir = mf->GetDefinition("CTEST_BINARY_DIRECTORY");
const char *ctestCmd = mf->GetDefinition("CTEST_COMMAND"); const char *ctestCmd = mf->GetDefinition("CTEST_COMMAND");
const char *ctestEnv = mf->GetDefinition("CTEST_ENVIRONMENT");
// make sure the required info is here // make sure the required info is here
if (!srcDir || !binDir || !ctestCmd) if (!srcDir || !binDir || !ctestCmd)
@ -2605,6 +2606,34 @@ int cmCTest::RunConfigurationScript()
return -3; return -3;
} }
// set any environment variables
if (ctestEnv)
{
static char ctestEnvStatic[100][5000];
std::vector<std::string> envArgs;
cmSystemTools::ExpandListArgument(ctestEnv,envArgs);
int numArgs = envArgs.size();
// we have a hard limit of 100 env args due to stupid format of putenv
if (numArgs > 100)
{
numArgs = 100;
}
// for each variable/argument do a putenv
int i;
for (i = 0; i < numArgs; ++i)
{
// also limit args to be at most 4K long
std::string::size_type size = envArgs[i].size();
if(size > 4999)
{
size = 4999;
}
strncpy(ctestEnvStatic[i], envArgs[i].c_str(), size);
ctestEnvStatic[i][4999] = 0;
putenv(ctestEnvStatic[i]);
}
}
// clear the binary directory? // clear the binary directory?
if (mf->IsOn("CTEST_START_WITH_EMPTY_BINARY_DIRECTORY")) if (mf->IsOn("CTEST_START_WITH_EMPTY_BINARY_DIRECTORY"))
{ {
@ -2652,15 +2681,22 @@ int cmCTest::RunConfigurationScript()
// put the initial cache into the bin dir // put the initial cache into the bin dir
if (mf->GetDefinition("CTEST_INITIAL_CACHE")) if (mf->GetDefinition("CTEST_INITIAL_CACHE"))
{ {
// the cache file will always be next to the configuration script const char *initCache = mf->GetDefinition("CTEST_INITIAL_CACHE");
std::string initialCache = std::string cacheFile = binDir;
cmSystemTools::GetFilenamePath(m_ConfigurationScript); cacheFile += "/CMakeCache.txt";
initialCache += "/"; std::ofstream fout(cacheFile.c_str());
initialCache += mf->GetDefinition("CTEST_INITIAL_CACHE"); if(!fout)
std::string destCache = binDir; {
destCache += "/CMakeCache.txt"; return -6;
cmSystemTools::CopyFileIfDifferent(initialCache.c_str(), }
destCache.c_str());
fout.write(initCache, strlen(initCache));
// Make sure the operating system has finished writing the file
// before closing it. This will ensure the file is finished before
// the check below.
fout.flush();
fout.close();
} }
// do an initial cmake to setup the DartConfig file // do an initial cmake to setup the DartConfig file
@ -2679,7 +2715,7 @@ int cmCTest::RunConfigurationScript()
if (!res || retVal != 0) if (!res || retVal != 0)
{ {
cmSystemTools::Error("Unable to run cmake"); cmSystemTools::Error("Unable to run cmake");
return -6; return -7;
} }
} }
@ -2695,7 +2731,7 @@ int cmCTest::RunConfigurationScript()
if (!res /* || retVal != 0 */) if (!res /* || retVal != 0 */)
{ {
cmSystemTools::Error("Unable to run ctest"); cmSystemTools::Error("Unable to run ctest");
return -6; return -8;
} }
return 0; return 0;