Fix rule hash persistence file generation
We store custom command rule hashes in CMakeFiles/CMakeRuleHashes.txt persistently across CMake runs. When the rule hash changes we delete the custom command output file and write a new hash into the persistence file. This functionality was first added by the commit 'Introduce "rule hashes" to help rebuild files when rules change.' (2008-06-02). However, the implementation in cmGlobalGenerator::CheckRuleHashes kept the file open for read when attempting to rewrite a new file. On Windows filesystems this prevented the new version of the file from being written! This caused the first set of rule hashes to be used forever within a build tree, meaning that all custom commands whose rules changed would be rebuilt every time CMake regenerated the build tree. In this commit we address the problem by splitting the read and write operations into separate methods. This ensures that the input stream is closed before the output stream opens the file.
This commit is contained in:
parent
41273582a5
commit
41a608a75d
|
@ -2068,20 +2068,27 @@ void cmGlobalGenerator::CheckRuleHashes()
|
||||||
std::string pfile = home;
|
std::string pfile = home;
|
||||||
pfile += this->GetCMakeInstance()->GetCMakeFilesDirectory();
|
pfile += this->GetCMakeInstance()->GetCMakeFilesDirectory();
|
||||||
pfile += "/CMakeRuleHashes.txt";
|
pfile += "/CMakeRuleHashes.txt";
|
||||||
|
this->CheckRuleHashes(pfile, home);
|
||||||
|
this->WriteRuleHashes(pfile);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void cmGlobalGenerator::CheckRuleHashes(std::string const& pfile,
|
||||||
|
std::string const& home)
|
||||||
|
{
|
||||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||||
std::ifstream fin(pfile.c_str(), std::ios::in | std::ios::binary);
|
std::ifstream fin(pfile.c_str(), std::ios::in | std::ios::binary);
|
||||||
#else
|
#else
|
||||||
std::ifstream fin(pfile.c_str(), std::ios::in);
|
std::ifstream fin(pfile.c_str(), std::ios::in);
|
||||||
#endif
|
#endif
|
||||||
bool goodStream = true;
|
|
||||||
if(!fin)
|
if(!fin)
|
||||||
{
|
{
|
||||||
goodStream = false;
|
return;
|
||||||
}
|
}
|
||||||
std::string line;
|
std::string line;
|
||||||
std::string fname;
|
std::string fname;
|
||||||
while(goodStream && cmSystemTools::GetLineFromStream(fin, line))
|
while(cmSystemTools::GetLineFromStream(fin, line))
|
||||||
{
|
{
|
||||||
// Line format is a 32-byte hex string followed by a space
|
// Line format is a 32-byte hex string followed by a space
|
||||||
// followed by a file name (with no escaping).
|
// followed by a file name (with no escaping).
|
||||||
|
@ -2127,7 +2134,11 @@ void cmGlobalGenerator::CheckRuleHashes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void cmGlobalGenerator::WriteRuleHashes(std::string const& pfile)
|
||||||
|
{
|
||||||
// Now generate a new persistence file with the current hashes.
|
// Now generate a new persistence file with the current hashes.
|
||||||
if(this->RuleHashes.empty())
|
if(this->RuleHashes.empty())
|
||||||
{
|
{
|
||||||
|
@ -2144,7 +2155,6 @@ void cmGlobalGenerator::CheckRuleHashes()
|
||||||
fout << " " << rhi->first << "\n";
|
fout << " " << rhi->first << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
|
@ -335,6 +335,8 @@ private:
|
||||||
struct RuleHash { char Data[32]; };
|
struct RuleHash { char Data[32]; };
|
||||||
std::map<cmStdString, RuleHash> RuleHashes;
|
std::map<cmStdString, RuleHash> RuleHashes;
|
||||||
void CheckRuleHashes();
|
void CheckRuleHashes();
|
||||||
|
void CheckRuleHashes(std::string const& pfile, std::string const& home);
|
||||||
|
void WriteRuleHashes(std::string const& pfile);
|
||||||
|
|
||||||
void WriteSummary();
|
void WriteSummary();
|
||||||
void WriteSummary(cmTarget* target);
|
void WriteSummary(cmTarget* target);
|
||||||
|
|
Loading…
Reference in New Issue