ENH: try to better handle control-c during make Makefiles
This commit is contained in:
parent
a3cfcd9894
commit
b6d823a7c1
|
@ -63,7 +63,8 @@ public:
|
|||
m_Name(name),
|
||||
m_TempName(m_Name+".tmp"),
|
||||
m_Stream(m_TempName.c_str()),
|
||||
m_Copied(false)
|
||||
m_Copied(false),
|
||||
m_AlwaysCopy(false)
|
||||
{}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +88,11 @@ public:
|
|||
* real file name to occur.
|
||||
*/
|
||||
void close() { this->DoCopy(); }
|
||||
|
||||
/**
|
||||
* If always copy is true, then copy the file all the time without
|
||||
* checking for differences. The default is false.
|
||||
*/
|
||||
bool SetAlwaysCopy(bool v) { m_AlwaysCopy = v; return v;}
|
||||
private:
|
||||
/**
|
||||
* The name of the real file where output will be copied if it has changed.
|
||||
|
@ -110,14 +115,29 @@ private:
|
|||
bool m_Copied;
|
||||
|
||||
/**
|
||||
* Closes the temporary file and does the copy-if-different to the real file.
|
||||
* If always copy is true, then copy the file all the time without
|
||||
* checking for differences. The default is false.
|
||||
*/
|
||||
bool m_AlwaysCopy;
|
||||
|
||||
/**
|
||||
* Closes the temporary file and does the copy-if-different to the
|
||||
* real file.
|
||||
*/
|
||||
void DoCopy()
|
||||
{
|
||||
if(!m_Copied)
|
||||
{
|
||||
m_Stream.close();
|
||||
cmSystemTools::CopyFileIfDifferent(m_TempName.c_str(), m_Name.c_str());
|
||||
if(m_AlwaysCopy)
|
||||
{
|
||||
cmSystemTools::cmCopyFile(m_TempName.c_str(), m_Name.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
cmSystemTools::CopyFileIfDifferent(m_TempName.c_str(),
|
||||
m_Name.c_str());
|
||||
}
|
||||
cmSystemTools::RemoveFile(m_TempName.c_str());
|
||||
m_Copied = true;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "cmSourceFile.h"
|
||||
#include "cmMakeDepend.h"
|
||||
#include "cmCacheManager.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
|
||||
cmUnixMakefileGenerator::cmUnixMakefileGenerator()
|
||||
{
|
||||
|
@ -93,7 +94,12 @@ void cmUnixMakefileGenerator::OutputMakefile(const char* file)
|
|||
cmSystemTools::MakeDirectory(i->c_str());
|
||||
}
|
||||
}
|
||||
std::ofstream fout(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 tempFile(file);
|
||||
tempFile.SetAlwaysCopy(true);
|
||||
std::ostream& fout = tempFile.GetStream();
|
||||
if(!fout)
|
||||
{
|
||||
cmSystemTools::Error("Error can not open for write: ", file);
|
||||
|
@ -950,6 +956,12 @@ void cmUnixMakefileGenerator::OutputMakeRules(std::ostream& fout)
|
|||
"${CMAKE_COMMAND}",
|
||||
0,
|
||||
"echo \"cmake might be out of date\"");
|
||||
this->OutputMakeRule(fout,
|
||||
"Rule to keep make from removing Makefiles "
|
||||
"if control-C is hit during a run of cmake.",
|
||||
".PRECIOUS",
|
||||
"Makefile cmake.depends",
|
||||
0);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue