ENH: Refactor custom command rule hashing

This simplifies computation of custom command rule hashes to hash
content exactly chosen as the custom commands are generated.
Unfortunately this will change the hashes of existing build trees from
earlier CMake versions, but this is not a big deal.  The change is
necessary so that in the future we can make optional adjustments to
custom command lines at generate time without changing the hashes every
time the option is changed.
This commit is contained in:
Brad King 2009-02-02 13:28:12 -05:00
parent 7d6a5e097f
commit ac9b7ec155
5 changed files with 23 additions and 20 deletions

View File

@ -2004,8 +2004,7 @@ cmGlobalGenerator::GetDirectoryContent(std::string const& dir, bool needDisk)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void void
cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs, cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
std::vector<std::string>::const_iterator first, std::string const& content)
std::vector<std::string>::const_iterator last)
{ {
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
// Ignore if there are no outputs. // Ignore if there are no outputs.
@ -2017,16 +2016,12 @@ cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
// Compute a hash of the rule. // Compute a hash of the rule.
RuleHash hash; RuleHash hash;
{ {
unsigned char const* data; unsigned char const* data =
int length; reinterpret_cast<unsigned char const*>(content.c_str());
int length = static_cast<int>(content.length());
cmsysMD5* sum = cmsysMD5_New(); cmsysMD5* sum = cmsysMD5_New();
cmsysMD5_Initialize(sum); cmsysMD5_Initialize(sum);
for(std::vector<std::string>::const_iterator i = first; i != last; ++i) cmsysMD5_Append(sum, data, length);
{
data = reinterpret_cast<unsigned char const*>(i->c_str());
length = static_cast<int>(i->length());
cmsysMD5_Append(sum, data, length);
}
cmsysMD5_FinalizeHex(sum, hash.Data); cmsysMD5_FinalizeHex(sum, hash.Data);
cmsysMD5_Delete(sum); cmsysMD5_Delete(sum);
} }

View File

@ -251,8 +251,7 @@ public:
void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames); void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames);
void AddRuleHash(const std::vector<std::string>& outputs, void AddRuleHash(const std::vector<std::string>& outputs,
std::vector<std::string>::const_iterator first, std::string const& content);
std::vector<std::string>::const_iterator last);
protected: protected:
// for a project collect all its targets by following depend // for a project collect all its targets by following depend

View File

@ -968,7 +968,8 @@ void
cmLocalUnixMakefileGenerator3 cmLocalUnixMakefileGenerator3
::AppendCustomCommand(std::vector<std::string>& commands, ::AppendCustomCommand(std::vector<std::string>& commands,
const cmCustomCommand& cc, bool echo_comment, const cmCustomCommand& cc, bool echo_comment,
cmLocalGenerator::RelativeRoot relative) cmLocalGenerator::RelativeRoot relative,
std::ostream* content)
{ {
// Optionally create a command to display the custom command's // Optionally create a command to display the custom command's
// comment text. This is used for pre-build, pre-link, and // comment text. This is used for pre-build, pre-link, and
@ -991,6 +992,10 @@ cmLocalUnixMakefileGenerator3
{ {
dir = workingDir; dir = workingDir;
} }
if(content)
{
*content << dir;
}
bool escapeOldStyle = cc.GetEscapeOldStyle(); bool escapeOldStyle = cc.GetEscapeOldStyle();
bool escapeAllowMakeVars = cc.GetEscapeAllowMakeVars(); bool escapeAllowMakeVars = cc.GetEscapeAllowMakeVars();
@ -1048,6 +1053,10 @@ cmLocalUnixMakefileGenerator3
escapeAllowMakeVars); escapeAllowMakeVars);
} }
} }
if(content)
{
*content << cmd;
}
if(this->BorlandMakeCurlyHack) if(this->BorlandMakeCurlyHack)
{ {
// Borland Make has a very strange bug. If the first curly // Borland Make has a very strange bug. If the first curly

View File

@ -332,7 +332,8 @@ protected:
const cmCustomCommand& cc, const cmCustomCommand& cc,
bool echo_comment=false, bool echo_comment=false,
cmLocalGenerator::RelativeRoot relative = cmLocalGenerator::RelativeRoot relative =
cmLocalGenerator::HOME_OUTPUT); cmLocalGenerator::HOME_OUTPUT,
std::ostream* content = 0);
void AppendCleanCommand(std::vector<std::string>& commands, void AppendCleanCommand(std::vector<std::string>& commands,
const std::vector<std::string>& files, const std::vector<std::string>& files,
cmTarget& target, const char* filename =0); cmTarget& target, const char* filename =0);

View File

@ -1119,11 +1119,12 @@ void cmMakefileTargetGenerator
->AppendEcho(commands, comment.c_str(), ->AppendEcho(commands, comment.c_str(),
cmLocalUnixMakefileGenerator3::EchoGenerate); cmLocalUnixMakefileGenerator3::EchoGenerate);
} }
// Below we need to skip over the echo and progress commands.
unsigned int skip = static_cast<unsigned int>(commands.size());
// Now append the actual user-specified commands. // Now append the actual user-specified commands.
this->LocalGenerator->AppendCustomCommand(commands, cc); cmOStringStream content;
this->LocalGenerator->AppendCustomCommand(commands, cc, false,
cmLocalGenerator::HOME_OUTPUT,
&content);
// Collect the dependencies. // Collect the dependencies.
std::vector<std::string> depends; std::vector<std::string> depends;
@ -1151,9 +1152,7 @@ void cmMakefileTargetGenerator
// If the rule has changed make sure the output is rebuilt. // If the rule has changed make sure the output is rebuilt.
if(!symbolic) if(!symbolic)
{ {
this->GlobalGenerator->AddRuleHash(cc.GetOutputs(), this->GlobalGenerator->AddRuleHash(cc.GetOutputs(), content.str());
commands.begin()+skip,
commands.end());
} }
} }