better configure file command
This commit is contained in:
parent
51a8914630
commit
901d2626ce
@ -81,13 +81,6 @@ void cmConfigureFileCommand::FinalPass()
|
|||||||
{
|
{
|
||||||
m_Makefile->ExpandVariablesInString(m_InputFile);
|
m_Makefile->ExpandVariablesInString(m_InputFile);
|
||||||
m_Makefile->ExpandVariablesInString(m_OuputFile);
|
m_Makefile->ExpandVariablesInString(m_OuputFile);
|
||||||
std::ifstream fin(m_InputFile.c_str());
|
|
||||||
if(!fin)
|
|
||||||
{
|
|
||||||
cmSystemTools::Error("Could not open file for read in copy operatation",
|
|
||||||
m_InputFile.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cmSystemTools::ConvertToUnixSlashes(m_OuputFile);
|
cmSystemTools::ConvertToUnixSlashes(m_OuputFile);
|
||||||
std::string::size_type pos = m_OuputFile.rfind('/');
|
std::string::size_type pos = m_OuputFile.rfind('/');
|
||||||
if(pos != std::string::npos)
|
if(pos != std::string::npos)
|
||||||
@ -95,29 +88,43 @@ void cmConfigureFileCommand::FinalPass()
|
|||||||
std::string path = m_OuputFile.substr(0, pos);
|
std::string path = m_OuputFile.substr(0, pos);
|
||||||
cmSystemTools::MakeDirectory(path.c_str());
|
cmSystemTools::MakeDirectory(path.c_str());
|
||||||
}
|
}
|
||||||
std::string tempOutputFile = m_OuputFile;
|
|
||||||
tempOutputFile += ".tmp";
|
if(m_CopyOnly)
|
||||||
std::ofstream fout(tempOutputFile.c_str());
|
|
||||||
if(!fout)
|
|
||||||
{
|
{
|
||||||
cmSystemTools::Error("Could not open file for write in copy operatation",
|
cmSystemTools::CopyFileIfDifferent(m_InputFile.c_str(),
|
||||||
tempOutputFile.c_str());
|
m_OuputFile.c_str());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// now copy input to output and expand varibles in the
|
else
|
||||||
// input file at the same time
|
|
||||||
const int bufSize = 4096;
|
|
||||||
char buffer[bufSize];
|
|
||||||
std::string inLine;
|
|
||||||
cmRegularExpression cmdefine("#cmakedefine[ \t]*([A-Za-z_0-9]*)");
|
|
||||||
while(fin)
|
|
||||||
{
|
{
|
||||||
fin.getline(buffer, bufSize);
|
std::string tempOutputFile = m_OuputFile;
|
||||||
if(fin)
|
tempOutputFile += ".tmp";
|
||||||
|
std::ofstream fout(tempOutputFile.c_str());
|
||||||
|
if(!fout)
|
||||||
{
|
{
|
||||||
inLine = buffer;
|
cmSystemTools::Error("Could not open file for write in copy operatation",
|
||||||
if(!m_CopyOnly)
|
tempOutputFile.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::ifstream fin(m_InputFile.c_str());
|
||||||
|
if(!fin)
|
||||||
|
{
|
||||||
|
cmSystemTools::Error("Could not open file for read in copy operatation",
|
||||||
|
m_InputFile.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// now copy input to output and expand varibles in the
|
||||||
|
// input file at the same time
|
||||||
|
const int bufSize = 4096;
|
||||||
|
char buffer[bufSize];
|
||||||
|
std::string inLine;
|
||||||
|
cmRegularExpression cmdefine("#cmakedefine[ \t]*([A-Za-z_0-9]*)");
|
||||||
|
while(fin)
|
||||||
|
{
|
||||||
|
fin.getline(buffer, bufSize);
|
||||||
|
if(fin)
|
||||||
{
|
{
|
||||||
|
inLine = buffer;
|
||||||
m_Makefile->ExpandVariablesInString(inLine, m_EscapeQuotes);
|
m_Makefile->ExpandVariablesInString(inLine, m_EscapeQuotes);
|
||||||
m_Makefile->RemoveVariablesInString(inLine);
|
m_Makefile->RemoveVariablesInString(inLine);
|
||||||
// look for special cmakedefine symbol and handle it
|
// look for special cmakedefine symbol and handle it
|
||||||
@ -139,13 +146,13 @@ void cmConfigureFileCommand::FinalPass()
|
|||||||
}
|
}
|
||||||
fout << inLine << "\n";
|
fout << inLine << "\n";
|
||||||
}
|
}
|
||||||
|
// close the files before attempting to copy
|
||||||
|
fin.close();
|
||||||
|
fout.close();
|
||||||
|
cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(),
|
||||||
|
m_OuputFile.c_str());
|
||||||
|
cmSystemTools::RemoveFile(tempOutputFile.c_str());
|
||||||
}
|
}
|
||||||
// close the files before attempting to copy
|
|
||||||
fin.close();
|
|
||||||
fout.close();
|
|
||||||
cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(),
|
|
||||||
m_OuputFile.c_str());
|
|
||||||
cmSystemTools::RemoveFile(tempOutputFile.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user