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:
parent
7d6a5e097f
commit
ac9b7ec155
|
@ -2004,8 +2004,7 @@ cmGlobalGenerator::GetDirectoryContent(std::string const& dir, bool needDisk)
|
|||
//----------------------------------------------------------------------------
|
||||
void
|
||||
cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
|
||||
std::vector<std::string>::const_iterator first,
|
||||
std::vector<std::string>::const_iterator last)
|
||||
std::string const& content)
|
||||
{
|
||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||
// Ignore if there are no outputs.
|
||||
|
@ -2017,16 +2016,12 @@ cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
|
|||
// Compute a hash of the rule.
|
||||
RuleHash hash;
|
||||
{
|
||||
unsigned char const* data;
|
||||
int length;
|
||||
unsigned char const* data =
|
||||
reinterpret_cast<unsigned char const*>(content.c_str());
|
||||
int length = static_cast<int>(content.length());
|
||||
cmsysMD5* sum = cmsysMD5_New();
|
||||
cmsysMD5_Initialize(sum);
|
||||
for(std::vector<std::string>::const_iterator i = first; i != last; ++i)
|
||||
{
|
||||
data = reinterpret_cast<unsigned char const*>(i->c_str());
|
||||
length = static_cast<int>(i->length());
|
||||
cmsysMD5_Append(sum, data, length);
|
||||
}
|
||||
cmsysMD5_Append(sum, data, length);
|
||||
cmsysMD5_FinalizeHex(sum, hash.Data);
|
||||
cmsysMD5_Delete(sum);
|
||||
}
|
||||
|
|
|
@ -251,8 +251,7 @@ public:
|
|||
void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames);
|
||||
|
||||
void AddRuleHash(const std::vector<std::string>& outputs,
|
||||
std::vector<std::string>::const_iterator first,
|
||||
std::vector<std::string>::const_iterator last);
|
||||
std::string const& content);
|
||||
|
||||
protected:
|
||||
// for a project collect all its targets by following depend
|
||||
|
|
|
@ -968,7 +968,8 @@ void
|
|||
cmLocalUnixMakefileGenerator3
|
||||
::AppendCustomCommand(std::vector<std::string>& commands,
|
||||
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
|
||||
// comment text. This is used for pre-build, pre-link, and
|
||||
|
@ -991,6 +992,10 @@ cmLocalUnixMakefileGenerator3
|
|||
{
|
||||
dir = workingDir;
|
||||
}
|
||||
if(content)
|
||||
{
|
||||
*content << dir;
|
||||
}
|
||||
bool escapeOldStyle = cc.GetEscapeOldStyle();
|
||||
bool escapeAllowMakeVars = cc.GetEscapeAllowMakeVars();
|
||||
|
||||
|
@ -1048,6 +1053,10 @@ cmLocalUnixMakefileGenerator3
|
|||
escapeAllowMakeVars);
|
||||
}
|
||||
}
|
||||
if(content)
|
||||
{
|
||||
*content << cmd;
|
||||
}
|
||||
if(this->BorlandMakeCurlyHack)
|
||||
{
|
||||
// Borland Make has a very strange bug. If the first curly
|
||||
|
|
|
@ -332,7 +332,8 @@ protected:
|
|||
const cmCustomCommand& cc,
|
||||
bool echo_comment=false,
|
||||
cmLocalGenerator::RelativeRoot relative =
|
||||
cmLocalGenerator::HOME_OUTPUT);
|
||||
cmLocalGenerator::HOME_OUTPUT,
|
||||
std::ostream* content = 0);
|
||||
void AppendCleanCommand(std::vector<std::string>& commands,
|
||||
const std::vector<std::string>& files,
|
||||
cmTarget& target, const char* filename =0);
|
||||
|
|
|
@ -1119,11 +1119,12 @@ void cmMakefileTargetGenerator
|
|||
->AppendEcho(commands, comment.c_str(),
|
||||
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.
|
||||
this->LocalGenerator->AppendCustomCommand(commands, cc);
|
||||
cmOStringStream content;
|
||||
this->LocalGenerator->AppendCustomCommand(commands, cc, false,
|
||||
cmLocalGenerator::HOME_OUTPUT,
|
||||
&content);
|
||||
|
||||
// Collect the dependencies.
|
||||
std::vector<std::string> depends;
|
||||
|
@ -1151,9 +1152,7 @@ void cmMakefileTargetGenerator
|
|||
// If the rule has changed make sure the output is rebuilt.
|
||||
if(!symbolic)
|
||||
{
|
||||
this->GlobalGenerator->AddRuleHash(cc.GetOutputs(),
|
||||
commands.begin()+skip,
|
||||
commands.end());
|
||||
this->GlobalGenerator->AddRuleHash(cc.GetOutputs(), content.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue