STYLE: Adjusted signature of cmGeneratedFileStream to make copy-if-different more explicity.

This commit is contained in:
Brad King 2004-11-03 07:51:51 -05:00
parent e34207c1f0
commit a5ae290a5b
9 changed files with 49 additions and 40 deletions

View File

@ -73,7 +73,8 @@ void cmExportLibraryDependenciesCommand::FinalPass()
else
{
std::auto_ptr<cmGeneratedFileStream> ap(
new cmGeneratedFileStream(fname.c_str(), true, true));
new cmGeneratedFileStream(fname.c_str(), true));
ap->SetCopyIfDifferent(true);
foutNew = ap;
foutPtr = foutNew.get();
}

View File

@ -27,10 +27,8 @@
#endif
//----------------------------------------------------------------------------
cmGeneratedFileStream::cmGeneratedFileStream(const char* name,
bool copy_if_different,
bool quiet):
cmGeneratedFileStreamBase(name, copy_if_different),
cmGeneratedFileStream::cmGeneratedFileStream(const char* name, bool quiet):
cmGeneratedFileStreamBase(name),
Stream(m_TempName.c_str())
{
// Check if the file opened.
@ -53,11 +51,16 @@ cmGeneratedFileStream::~cmGeneratedFileStream()
}
//----------------------------------------------------------------------------
cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name,
bool copy_if_different):
void cmGeneratedFileStream::SetCopyIfDifferent(bool copy_if_different)
{
m_CopyIfDifferent = copy_if_different;
}
//----------------------------------------------------------------------------
cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name):
m_Name(name),
m_TempName(name),
m_CopyIfDifferent(copy_if_different),
m_CopyIfDifferent(false),
m_Okay(false)
{
// Create the name of the temporary file.

View File

@ -26,7 +26,7 @@ class cmGeneratedFileStreamBase
{
protected:
// The constructor prepares the temporary output file.
cmGeneratedFileStreamBase(const char* name, bool copy_if_different);
cmGeneratedFileStreamBase(const char* name);
// The destructor renames the temporary output file to the real name.
~cmGeneratedFileStreamBase();
@ -65,13 +65,11 @@ public:
/**
* The constructor takes the name of the file to be generated. It
* automatically generates a name for the temporary file. The
* second argument specifies whether the copy-if-different check
* should be done. If the file cannot be opened an error message is
* produced unless the third argument is set to true.
* automatically generates a name for the temporary file. If the
* file cannot be opened an error message is produced unless the
* second argument is set to true.
*/
cmGeneratedFileStream(const char* name, bool copy_if_different,
bool quiet = false);
cmGeneratedFileStream(const char* name, bool quiet=false);
/**
* The destructor checks the stream status to be sure the temporary
@ -79,6 +77,11 @@ public:
* replaced.
*/
~cmGeneratedFileStream();
/**
* Set whether copy-if-different is done.
*/
void SetCopyIfDifferent(bool copy_if_different);
};
#endif

View File

@ -289,7 +289,8 @@ void cmGlobalVisualStudio7Generator::OutputSLNFile(cmLocalGenerator* root,
fname += "/";
fname += root->GetMakefile()->GetProjectName();
fname += ".sln";
cmGeneratedFileStream fout(fname.c_str(), true);
cmGeneratedFileStream fout(fname.c_str());
fout.SetCopyIfDifferent(true);
if(!fout)
{
return;

View File

@ -92,7 +92,8 @@ void cmLocalGenerator::GenerateInstallRules()
toplevel_install = 1;
}
file += "/cmake_install.cmake";
cmGeneratedFileStream fout(file.c_str(), true);
cmGeneratedFileStream fout(file.c_str());
fout.SetCopyIfDifferent(true);
fout << "# Install script for directory: " << m_Makefile->GetCurrentDirectory()
<< std::endl << std::endl;

View File

@ -120,7 +120,7 @@ void cmLocalKdevelopGenerator::MergeProjectFiles(const std::string& outputDir,
}
oldProjectFile.close();
cmGeneratedFileStream fout(filename.c_str(), false);
cmGeneratedFileStream fout(filename.c_str());
if(!fout)
{
return;
@ -171,7 +171,7 @@ void cmLocalKdevelopGenerator::CreateNewProjectFile(const std::string& outputDir
const std::string& cmakeFilePattern)
{
cmGeneratedFileStream fout(filename.c_str(), false);
cmGeneratedFileStream fout(filename.c_str());
if(!fout)
{
return;
@ -364,7 +364,7 @@ bool cmLocalKdevelopGenerator::CreateFilelistFile(const std::string& outputDir,
}
//now write the new filename
cmGeneratedFileStream fout(filename.c_str(), false);
cmGeneratedFileStream fout(filename.c_str());
if(!fout)
{
return false;

View File

@ -186,7 +186,7 @@ void cmLocalUnixMakefileGenerator::OutputMakefile(const char* file,
// Create a stream that writes to a temporary file
// then does a copy at the end. This is to allow users
// to hit control-c during the make of the makefile
cmGeneratedFileStream fout(file, false);
cmGeneratedFileStream fout(file);
if(!fout)
{
return;

View File

@ -46,8 +46,6 @@ void cmLocalUnixMakefileGenerator2::SetEmptyCommand(const char* cmd)
//----------------------------------------------------------------------------
void cmLocalUnixMakefileGenerator2::Generate(bool fromTheTop)
{
// TODO: Account for control-c during Makefile generation.
// TODO: Think about unifying generation of "@" for silent commands.
// Generate old style for now.
@ -88,15 +86,14 @@ void cmLocalUnixMakefileGenerator2::Generate(bool fromTheTop)
//----------------------------------------------------------------------------
void cmLocalUnixMakefileGenerator2::GenerateMakefile()
{
// Open the output file.
// Open the output file. This should not be copy-if-different
// because the check-build-system step compares the makefile time to
// see if the build system must be regenerated.
std::string makefileName = m_Makefile->GetStartOutputDirectory();
makefileName += "/Makefile2";
std::ofstream makefileStream(makefileName.c_str());
cmGeneratedFileStream makefileStream(makefileName.c_str());
if(!makefileStream)
{
cmSystemTools::Error("Error can not open for write: ",
makefileName.c_str());
cmSystemTools::ReportLastSystemError("");
return;
}
@ -134,12 +131,9 @@ void cmLocalUnixMakefileGenerator2::GenerateCMakefile()
cmakefileName += ".cmake";
// Open the output file.
std::ofstream cmakefileStream(cmakefileName.c_str());
cmGeneratedFileStream cmakefileStream(cmakefileName.c_str());
if(!cmakefileStream)
{
cmSystemTools::Error("Error can not open for write: ",
cmakefileName.c_str());
cmSystemTools::ReportLastSystemError("");
return;
}
@ -237,7 +231,8 @@ cmLocalUnixMakefileGenerator2
// Open the rule file. This should be copy-if-different because the
// rules may depend on this file itself.
std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str(), true);
cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
ruleFileStream.SetCopyIfDifferent(true);
if(!ruleFileStream)
{
return;
@ -351,7 +346,8 @@ cmLocalUnixMakefileGenerator2
std::string ruleFileName = obj;
ruleFileName += ".make";
std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str(), true);
cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
ruleFileStream.SetCopyIfDifferent(true);
if(!ruleFileStream)
{
return;
@ -526,7 +522,8 @@ cmLocalUnixMakefileGenerator2
// Open the rule file. This should be copy-if-different because the
// rules may depend on this file itself.
std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str(), true);
cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
ruleFileStream.SetCopyIfDifferent(true);
if(!ruleFileStream)
{
return;
@ -2228,7 +2225,7 @@ cmLocalUnixMakefileGenerator2
std::string depMakeFile = objFile;
depMarkFile += ".depends";
depMakeFile += ".depends.make";
std::ofstream fout(depMakeFile.c_str());
cmGeneratedFileStream fout(depMakeFile.c_str());
fout << "# Dependencies for " << objFile << std::endl;
for(std::set<cmStdString>::iterator i=dependencies.begin();
i != dependencies.end(); ++i)
@ -2406,7 +2403,7 @@ cmLocalUnixMakefileGenerator2
cmSystemTools::RemoveFile(depMarkFileFull);
// Write an empty dependency file.
std::ofstream depFileStream(depMakeFileFull);
cmGeneratedFileStream depFileStream(depMakeFileFull);
depFileStream
<< "# Empty dependencies file for " << file << ".\n"
<< "# This may be replaced when dependencies are built.\n";

View File

@ -127,7 +127,8 @@ cmVTKMakeInstantiatorCommand
std::string fullName = headerPath+"/"+fileName;
// Generate the output file with copy-if-different.
cmGeneratedFileStream fout(fullName.c_str(), true);
cmGeneratedFileStream fout(fullName.c_str());
fout.SetCopyIfDifferent(true);
// Actually generate the code in the file.
if(!oldVersion)
@ -147,7 +148,8 @@ cmVTKMakeInstantiatorCommand
// Generate the output file with copy-if-different.
{
cmGeneratedFileStream fout(fullName.c_str(), true);
cmGeneratedFileStream fout(fullName.c_str());
fout.SetCopyIfDifferent(true);
// Actually generate the code in the file.
if(!oldVersion)
@ -188,7 +190,8 @@ cmVTKMakeInstantiatorCommand
// Generate the output file with copy-if-different.
{
cmGeneratedFileStream fout(fullName.c_str(), true);
cmGeneratedFileStream fout(fullName.c_str());
fout.SetCopyIfDifferent(true);
size_t thisBlockSize =
(block < numFullBlocks)? groupSize:lastBlockSize;