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
|
// set any environment variables
|
||||||
if (ctestEnv)
|
if (ctestEnv)
|
||||||
{
|
{
|
||||||
static char ctestEnvStatic[100][5000];
|
|
||||||
std::vector<std::string> envArgs;
|
std::vector<std::string> envArgs;
|
||||||
cmSystemTools::ExpandListArgument(ctestEnv,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
|
// for each variable/argument do a putenv
|
||||||
int i;
|
for (unsigned i = 0; i < envArgs.size(); ++i)
|
||||||
for (i = 0; i < numArgs; ++i)
|
|
||||||
{
|
{
|
||||||
// also limit args to be at most 4K long
|
cmSystemTools::PutEnv(envArgs[i].c_str());
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,6 @@ void cmGlobalGenerator::EnableLanguage(const char* lang,
|
||||||
systemFile += "/Modules/CMakeDetermineSystem.cmake";
|
systemFile += "/Modules/CMakeDetermineSystem.cmake";
|
||||||
mf->ReadListFile(0, systemFile.c_str());
|
mf->ReadListFile(0, systemFile.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for a C compiler and configure it
|
// check for a C compiler and configure it
|
||||||
if(!isLocal &&
|
if(!isLocal &&
|
||||||
!this->GetLanguageEnabled("C") &&
|
!this->GetLanguageEnabled("C") &&
|
||||||
|
@ -137,20 +136,11 @@ void cmGlobalGenerator::EnableLanguage(const char* lang,
|
||||||
this->SetLanguageEnabled("C");
|
this->SetLanguageEnabled("C");
|
||||||
// put CC in the environment in case user scripts want
|
// put CC in the environment in case user scripts want
|
||||||
// to run configure
|
// to run configure
|
||||||
// see man putenv for explaination of this stupid code...
|
|
||||||
if(mf->GetDefinition("CMAKE_C_COMPILER"))
|
if(mf->GetDefinition("CMAKE_C_COMPILER"))
|
||||||
{
|
{
|
||||||
static char envCC[5000];
|
|
||||||
std::string env = "CC=${CMAKE_C_COMPILER}";
|
std::string env = "CC=${CMAKE_C_COMPILER}";
|
||||||
mf->ExpandVariablesInString(env);
|
mf->ExpandVariablesInString(env);
|
||||||
unsigned int size = static_cast<unsigned int>(env.size());
|
cmSystemTools::PutEnv(env.c_str());
|
||||||
if(size > 4999)
|
|
||||||
{
|
|
||||||
size = 4999;
|
|
||||||
}
|
|
||||||
strncpy(envCC, env.c_str(), size);
|
|
||||||
envCC[size] = 0;
|
|
||||||
putenv(envCC);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,20 +156,11 @@ void cmGlobalGenerator::EnableLanguage(const char* lang,
|
||||||
this->SetLanguageEnabled("CXX");
|
this->SetLanguageEnabled("CXX");
|
||||||
// put CXX in the environment in case user scripts want
|
// put CXX in the environment in case user scripts want
|
||||||
// to run configure
|
// to run configure
|
||||||
// see man putenv for explaination of this stupid code...
|
|
||||||
static char envCXX[5000];
|
|
||||||
if(mf->GetDefinition("CMAKE_CXX_COMPILER"))
|
if(mf->GetDefinition("CMAKE_CXX_COMPILER"))
|
||||||
{
|
{
|
||||||
std::string env = "CXX=${CMAKE_CXX_COMPILER}";
|
std::string env = "CXX=${CMAKE_CXX_COMPILER}";
|
||||||
mf->ExpandVariablesInString(env);
|
mf->ExpandVariablesInString(env);
|
||||||
unsigned int size = static_cast<unsigned int>(env.size());
|
cmSystemTools::PutEnv(env.c_str());
|
||||||
if(size > 4999)
|
|
||||||
{
|
|
||||||
size = 4999;
|
|
||||||
}
|
|
||||||
strncpy(envCXX, env.c_str(), size);
|
|
||||||
envCXX[size] = 0;
|
|
||||||
putenv(envCXX);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check for a Java compiler and configure it
|
// 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];
|
relativePath += relativeSplit[i];
|
||||||
return relativePath;
|
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);
|
static std::string RelativePath(const char* local, const char* remote);
|
||||||
///! split a path by separator into an array of strings, default is /
|
///! split a path by separator into an array of strings, default is /
|
||||||
static std::vector<cmStdString> SplitString(const char* s, char separator = '/');
|
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:
|
private:
|
||||||
static bool s_ForceUnixPaths;
|
static bool s_ForceUnixPaths;
|
||||||
static bool s_RunCommandHideConsole;
|
static bool s_RunCommandHideConsole;
|
||||||
|
|
|
@ -84,8 +84,7 @@ cmake::cmake()
|
||||||
// encode the MAKEFLAGS variable in a strange way.
|
// encode the MAKEFLAGS variable in a strange way.
|
||||||
if(getenv("MAKEFLAGS"))
|
if(getenv("MAKEFLAGS"))
|
||||||
{
|
{
|
||||||
static char makeflags[] = "MAKEFLAGS=";
|
cmSystemTools::PutEnv("MAKEFLAGS=");
|
||||||
putenv(makeflags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Local = false;
|
m_Local = false;
|
||||||
|
@ -876,36 +875,18 @@ void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
|
||||||
delete m_GlobalGenerator;
|
delete m_GlobalGenerator;
|
||||||
// restore the original environment variables CXX and CC
|
// restore the original environment variables CXX and CC
|
||||||
// Restor CC
|
// Restor CC
|
||||||
static char envCC[5000];
|
|
||||||
std::string env = "CC=";
|
std::string env = "CC=";
|
||||||
if(m_CCEnvironment)
|
if(m_CCEnvironment.size())
|
||||||
{
|
{
|
||||||
env += m_CCEnvironment;
|
env += m_CCEnvironment;
|
||||||
}
|
}
|
||||||
std::string::size_type size = env.size();
|
cmSystemTools::PutEnv(env.c_str());
|
||||||
if(size > 4999)
|
|
||||||
{
|
|
||||||
size = 4999;
|
|
||||||
}
|
|
||||||
strncpy(envCC, env.c_str(), size);
|
|
||||||
envCC[size] = 0;
|
|
||||||
putenv(envCC);
|
|
||||||
|
|
||||||
// Restore CXX
|
|
||||||
static char envCXX[5000];
|
|
||||||
env = "CXX=";
|
env = "CXX=";
|
||||||
if(m_CXXEnvironment)
|
if(m_CXXEnvironment.size())
|
||||||
{
|
{
|
||||||
env += m_CXXEnvironment;
|
env += m_CXXEnvironment;
|
||||||
}
|
}
|
||||||
size = env.size();
|
cmSystemTools::PutEnv(env.c_str());
|
||||||
if(size > 4999)
|
|
||||||
{
|
|
||||||
size = 4999;
|
|
||||||
}
|
|
||||||
strncpy(envCXX, env.c_str(), size);
|
|
||||||
envCXX[size] = 0;
|
|
||||||
putenv(envCXX);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the new
|
// set the new
|
||||||
|
@ -915,9 +896,24 @@ void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
|
||||||
// on windows.
|
// on windows.
|
||||||
cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
|
cmSystemTools::SetForceUnixPaths(m_GlobalGenerator->GetForceUnixPaths());
|
||||||
// Save the environment variables CXX and CC
|
// Save the environment variables CXX and CC
|
||||||
m_CXXEnvironment = getenv("CXX");
|
const char* cxx = getenv("CXX");
|
||||||
m_CCEnvironment = getenv("CC");
|
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
|
// set the cmake instance just to be sure
|
||||||
gg->SetCMakeInstance(this);
|
gg->SetCMakeInstance(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,8 +298,8 @@ private:
|
||||||
bool m_InTryCompile;
|
bool m_InTryCompile;
|
||||||
bool m_ScriptMode;
|
bool m_ScriptMode;
|
||||||
std::string m_CMakeCommand;
|
std::string m_CMakeCommand;
|
||||||
const char* m_CXXEnvironment;
|
std::string m_CXXEnvironment;
|
||||||
const char* m_CCEnvironment;
|
std::string m_CCEnvironment;
|
||||||
bool m_DebugTryCompile;
|
bool m_DebugTryCompile;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue