From 368a18b83c1a0885f477b4911d3f5224b4fd534e Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 4 Sep 2009 12:39:18 -0400 Subject: Cleanup source file dependency tracing logic In cmTarget we trace the dependencies of source files in the target to bring in all custom commands needed to generate them. We clean up the implementation to use simpler logic and better method names. The new approach is based on the observation that a source file is actually an input (dependency) of the rule that it runs (compiler or custom) even in the case that it is generated (another .rule file has the rule to generate it). --- Source/cmTarget.cxx | 108 +++++++++++++++++++++++++++------------------------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 26c0e39..22b49ef 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1087,12 +1087,14 @@ private: cmTarget* Target; cmMakefile* Makefile; cmGlobalGenerator* GlobalGenerator; - std::queue DependencyQueue; - std::set DependenciesQueued; - - void QueueOnce(std::string const& name); - void QueueOnce(std::vector const& names); - void QueueDependencies(cmSourceFile* sf); + std::queue SourceQueue; + std::set SourcesQueued; + typedef std::map NameMapType; + NameMapType NameMap; + + void QueueSource(cmSourceFile* sf); + void FollowName(std::string const& name); + void FollowNames(std::vector const& names); bool IsUtility(std::string const& dep); void CheckCustomCommand(cmCustomCommand const& cc); void CheckCustomCommands(const std::vector& commands); @@ -1113,19 +1115,14 @@ cmTargetTraceDependencies for(std::vector::const_iterator si = sources.begin(); si != sources.end(); ++si) { - // Queue the source file itself in case it is generated. - this->QueueOnce((*si)->GetFullPath()); - - // Queue the dependencies of the source file in case they are - // generated. - this->QueueDependencies(*si); + this->QueueSource(*si); } // Queue the VS project file to check dependencies on the rule to // generate it. if(vsProjectFile) { - this->QueueOnce(vsProjectFile); + this->FollowName(vsProjectFile); } // Queue pre-build, pre-link, and post-build rule dependencies. @@ -1138,42 +1135,71 @@ cmTargetTraceDependencies void cmTargetTraceDependencies::Trace() { // Process one dependency at a time until the queue is empty. - while(!this->DependencyQueue.empty()) + while(!this->SourceQueue.empty()) { - // Get the next dependency in from queue. - std::string dep = this->DependencyQueue.front(); - this->DependencyQueue.pop(); + // Get the next source from the queue. + cmSourceFile* sf = this->SourceQueue.front(); + this->SourceQueue.pop(); - // Check if we know how to generate this dependency. - if(cmSourceFile* sf = - this->Makefile->GetSourceFileWithOutput(dep.c_str())) + // Queue dependencies added explicitly by the user. + if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS")) { - // Queue dependencies needed to generate this file. - this->QueueDependencies(sf); + std::vector objDeps; + cmSystemTools::ExpandListArgument(additionalDeps, objDeps); + this->FollowNames(objDeps); + } + + // Queue the source needed to generate this file, if any. + this->FollowName(sf->GetFullPath()); - // Make sure this file is in the target. - this->Target->AddSourceFile(sf); + // Queue dependencies added programatically by commands. + this->FollowNames(sf->GetDepends()); + + // Queue custom command dependencies. + if(cmCustomCommand const* cc = sf->GetCustomCommand()) + { + this->CheckCustomCommand(*cc); } } } //---------------------------------------------------------------------------- -void cmTargetTraceDependencies::QueueOnce(std::string const& name) +void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf) +{ + if(this->SourcesQueued.insert(sf).second) + { + this->SourceQueue.push(sf); + + // Make sure this file is in the target. + this->Target->AddSourceFile(sf); + } +} + +//---------------------------------------------------------------------------- +void cmTargetTraceDependencies::FollowName(std::string const& name) { - if(this->DependenciesQueued.insert(name).second) + NameMapType::iterator i = this->NameMap.find(name); + if(i == this->NameMap.end()) { - this->DependencyQueue.push(name); + // Check if we know how to generate this file. + cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name.c_str()); + NameMapType::value_type entry(name, sf); + i = this->NameMap.insert(entry).first; + } + if(cmSourceFile* sf = i->second) + { + this->QueueSource(sf); } } //---------------------------------------------------------------------------- void -cmTargetTraceDependencies::QueueOnce(std::vector const& names) +cmTargetTraceDependencies::FollowNames(std::vector const& names) { for(std::vector::const_iterator i = names.begin(); i != names.end(); ++i) { - this->QueueOnce(*i); + this->FollowName(*i); } } @@ -1227,28 +1253,6 @@ bool cmTargetTraceDependencies::IsUtility(std::string const& dep) } //---------------------------------------------------------------------------- -void cmTargetTraceDependencies::QueueDependencies(cmSourceFile* sf) -{ - // Queue dependency added explicitly by the user. - if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS")) - { - std::vector objDeps; - cmSystemTools::ExpandListArgument(additionalDeps, objDeps); - this->QueueOnce(objDeps); - } - - // Queue dependencies added programatically by commands. - this->QueueOnce(sf->GetDepends()); - - // Queue custom command dependencies. - if(cmCustomCommand const* cc = sf->GetCustomCommand()) - { - this->CheckCustomCommand(*cc); - } - -} - -//---------------------------------------------------------------------------- void cmTargetTraceDependencies ::CheckCustomCommand(cmCustomCommand const& cc) @@ -1283,7 +1287,7 @@ cmTargetTraceDependencies { // The dependency does not name a target and may be a file we // know how to generate. Queue it. - this->QueueOnce(dep); + this->FollowName(dep); } } } -- cgit v0.12