BUG: fix put/get env problems
This commit is contained in:
parent
dd7f85a9dc
commit
222e9a2876
|
@ -3019,28 +3019,12 @@ int cmCTest::RunConfigurationScript()
|
|||
// 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)
|
||||
for (unsigned i = 0; i < envArgs.size(); ++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][size] = 0;
|
||||
putenv(ctestEnvStatic[i]);
|
||||
cmSystemTools::PutEnv(envArgs[i].c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ cmGlobalGenerator::~cmGlobalGenerator()
|
|||
m_LocalGenerators.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void cmGlobalGenerator::EnableLanguage(const char* lang,
|
||||
cmMakefile *mf)
|
||||
{
|
||||
|
@ -116,7 +116,6 @@ void cmGlobalGenerator::EnableLanguage(const char* lang,
|
|||
systemFile += "/Modules/CMakeDetermineSystem.cmake";
|
||||
mf->ReadListFile(0, systemFile.c_str());
|
||||
}
|
||||
|
||||
// check for a C compiler and configure it
|
||||
if(!isLocal &&
|
||||
!this->GetLanguageEnabled("C") &&
|
||||
|
@ -137,20 +136,11 @@ void cmGlobalGenerator::EnableLanguage(const char* lang,
|
|||
this->SetLanguageEnabled("C");
|
||||
// put CC in the environment in case user scripts want
|
||||
// to run configure
|
||||
// see man putenv for explaination of this stupid code...
|
||||
if(mf->GetDefinition("CMAKE_C_COMPILER"))
|
||||
{
|
||||
static char envCC[5000];
|
||||
std::string env = "CC=${CMAKE_C_COMPILER}";
|
||||
mf->ExpandVariablesInString(env);
|
||||
unsigned int size = static_cast<unsigned int>(env.size());
|
||||
if(size > 4999)
|
||||
{
|
||||
size = 4999;
|
||||
}
|
||||
strncpy(envCC, env.c_str(), size);
|
||||
envCC[size] = 0;
|
||||
putenv(envCC);
|
||||
cmSystemTools::PutEnv(env.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,20 +156,11 @@ void cmGlobalGenerator::EnableLanguage(const char* lang,
|
|||
this->SetLanguageEnabled("CXX");
|
||||
// put CXX in the environment in case user scripts want
|
||||
// to run configure
|
||||
// see man putenv for explaination of this stupid code...
|
||||
static char envCXX[5000];
|
||||
if(mf->GetDefinition("CMAKE_CXX_COMPILER"))
|
||||
{
|
||||
std::string env = "CXX=${CMAKE_CXX_COMPILER}";
|
||||
mf->ExpandVariablesInString(env);
|
||||
unsigned int size = static_cast<unsigned int>(env.size());
|
||||
if(size > 4999)
|
||||
{
|
||||
size = 4999;
|
||||
}
|
||||
strncpy(envCXX, env.c_str(), size);
|
||||
envCXX[size] = 0;
|
||||
putenv(envCXX);
|
||||
cmSystemTools::PutEnv(env.c_str());
|
||||
}
|
||||
}
|
||||
// check for a Java compiler and configure it
|
||||
|
|
|
@ -1177,3 +1177,27 @@ std::string cmSystemTools::RelativePath(const char* local, const char* remote)
|
|||
relativePath += relativeSplit[i];
|
||||
return relativePath;
|
||||
}
|
||||
class cmDeletingCharVector : public std::vector<char*>
|
||||
{
|
||||
public:
|
||||
~cmDeletingCharVector()
|
||||
{
|
||||
for(std::vector<char*>::iterator i = this->begin();
|
||||
i != this->end(); ++i)
|
||||
{
|
||||
delete *i;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
bool cmSystemTools::PutEnv(const char* value)
|
||||
{
|
||||
static cmDeletingCharVector localEnvironment;
|
||||
char* envVar = new char[strlen(value)+1];
|
||||
strcpy(envVar, value);
|
||||
putenv(envVar);
|
||||
// save the pointer in the static vector so that it can
|
||||
// be deleted on exit
|
||||
localEnvironment.push_back(envVar);
|
||||
}
|
||||
|
|
|
@ -256,6 +256,10 @@ public:
|
|||
static std::string RelativePath(const char* local, const char* remote);
|
||||
///! split a path by separator into an array of strings, default is /
|
||||
static std::vector<cmStdString> SplitString(const char* s, char separator = '/');
|
||||
/** put a string into the environment
|
||||
of the form var=value */
|
||||
static bool PutEnv(const char* value);
|
||||
|
||||
private:
|
||||
static bool s_ForceUnixPaths;
|
||||
static bool s_RunCommandHideConsole;
|
||||
|
|
|
@ -84,8 +84,7 @@ cmake::cmake()
|
|||
// encode the MAKEFLAGS variable in a strange way.
|
||||
if(getenv("MAKEFLAGS"))
|
||||
{
|
||||
static char makeflags[] = "MAKEFLAGS=";
|
||||
putenv(makeflags);
|
||||
cmSystemTools::PutEnv("MAKEFLAGS=");
|
||||
}
|
||||
|
||||
m_Local = false;
|
||||
|
@ -876,36 +875,18 @@ void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
|
|||
delete m_GlobalGenerator;
|
||||
// restore the original environment variables CXX and CC
|
||||
// Restor CC
|
||||
static char envCC[5000];
|
||||
std::string env = "CC=";
|
||||
if(m_CCEnvironment)
|
||||
if(m_CCEnvironment.size())
|
||||
{
|
||||
env += m_CCEnvironment;
|
||||
}
|
||||
std::string::size_type size = env.size();
|
||||
if(size > 4999)
|
||||
{
|
||||
size = 4999;
|
||||
}
|
||||
strncpy(envCC, env.c_str(), size);
|
||||
envCC[size] = 0;
|
||||
putenv(envCC);
|
||||
|
||||
// Restore CXX
|
||||
static char envCXX[5000];
|
||||
cmSystemTools::PutEnv(env.c_str());
|
||||
env = "CXX=";
|
||||
if(m_CXXEnvironment)
|
||||
if(m_CXXEnvironment.size())
|
||||
{
|
||||
env += m_CXXEnvironment;
|
||||
}
|
||||
size = env.size();
|
||||
if(size > 4999)
|
||||
{
|
||||
size = 4999;
|
||||
}
|
||||
strncpy(envCXX, env.c_str(), size);
|
||||
envCXX[size] = 0;
|
||||
putenv(envCXX);
|
||||
cmSystemTools::PutEnv(env.c_str());
|
||||
}
|
||||
|
||||
// set the new
|
||||
|
@ -915,9 +896,24 @@ void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
|
|||
// on windows.
|
||||
cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
|
||||
// Save the environment variables CXX and CC
|
||||
m_CXXEnvironment = getenv("CXX");
|
||||
m_CCEnvironment = getenv("CC");
|
||||
|
||||
const char* cxx = getenv("CXX");
|
||||
const char* cc = getenv("CC");
|
||||
if(cxx)
|
||||
{
|
||||
m_CXXEnvironment = cxx;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_CXXEnvironment = "";
|
||||
}
|
||||
if(cc)
|
||||
{
|
||||
m_CCEnvironment = cc;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_CCEnvironment = "";
|
||||
}
|
||||
// set the cmake instance just to be sure
|
||||
gg->SetCMakeInstance(this);
|
||||
}
|
||||
|
|
|
@ -298,8 +298,8 @@ private:
|
|||
bool m_InTryCompile;
|
||||
bool m_ScriptMode;
|
||||
std::string m_CMakeCommand;
|
||||
const char* m_CXXEnvironment;
|
||||
const char* m_CCEnvironment;
|
||||
std::string m_CXXEnvironment;
|
||||
std::string m_CCEnvironment;
|
||||
bool m_DebugTryCompile;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue