[Cmake-commits] [cmake-commits] king committed cmGlobalUnixMakefileGenerator3.cxx 1.135 1.136 cmGlobalUnixMakefileGenerator3.h 1.57 1.58 cmLocalUnixMakefileGenerator3.cxx 1.265 1.266 cmLocalUnixMakefileGenerator3.h 1.88 1.89 cmMakefileTargetGenerator.cxx 1.118 1.119 cmMakefileTargetGenerator.h 1.29 1.30

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Jun 25 09:58:53 EDT 2009


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv15965/Source

Modified Files:
	cmGlobalUnixMakefileGenerator3.cxx 
	cmGlobalUnixMakefileGenerator3.h 
	cmLocalUnixMakefileGenerator3.cxx 
	cmLocalUnixMakefileGenerator3.h cmMakefileTargetGenerator.cxx 
	cmMakefileTargetGenerator.h 
Log Message:
ENH: Cleanup make progress rule generation code

This cleans up the Makefile generator's progress rule code.  Instead of
keeping every cmMakefileTargetGenerator instance alive to generate
progress, we keep only the information necessary in a single table.
This approach keeps most of the code in cmGlobalUnixMakefileGenerator3,
thus simplifying its public interface.


Index: cmLocalUnixMakefileGenerator3.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalUnixMakefileGenerator3.h,v
retrieving revision 1.88
retrieving revision 1.89
diff -C 2 -d -r1.88 -r1.89
*** cmLocalUnixMakefileGenerator3.h	10 Feb 2009 13:51:13 -0000	1.88
--- cmLocalUnixMakefileGenerator3.h	25 Jun 2009 13:58:51 -0000	1.89
***************
*** 67,74 ****
    void WriteMakeVariables(std::ostream& makefileStream);
  
-   // write the progress variables used by the makefiles
-   void WriteProgressVariables(unsigned long total, unsigned long &current);
-   void WriteAllProgressVariable();
- 
    /**
     * If true, then explicitly pass MAKEFLAGS on the make all target for makes
--- 67,70 ----
***************
*** 257,264 ****
    std::vector<cmStdString> const& GetLocalHelp() { return this->LocalHelp; }
  
-   // return info about progress actions
-   unsigned long GetNumberOfProgressActions();
-   unsigned long GetNumberOfProgressActionsForTarget(const char *);
- 
    /** Get whether to create rules to generate preprocessed and
        assembly sources.  This could be converted to a variable lookup
--- 253,256 ----
***************
*** 341,346 ****
                            cmTarget& target, const char* filename =0);
  
-   std::map<cmStdString, std::vector<int> > ProgressFiles;
- 
    // Helper methods for dependeny updates.
    bool ScanDependencies(const char* targetDir);
--- 333,336 ----
***************
*** 391,395 ****
  
    /* does the work for each target */
-   std::vector<cmMakefileTargetGenerator *> TargetGenerators;
    std::map<cmStdString, cmStdString> MakeVariableMap;
    std::map<cmStdString, cmStdString> ShortMakeVariableMap;
--- 381,384 ----

Index: cmGlobalUnixMakefileGenerator3.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalUnixMakefileGenerator3.h,v
retrieving revision 1.57
retrieving revision 1.58
diff -C 2 -d -r1.57 -r1.58
*** cmGlobalUnixMakefileGenerator3.h	9 Feb 2009 21:45:18 -0000	1.57
--- cmGlobalUnixMakefileGenerator3.h	25 Jun 2009 13:58:50 -0000	1.58
***************
*** 21,24 ****
--- 21,25 ----
  
  class cmGeneratedFileStream;
+ class cmMakefileTargetGenerator;
  class cmLocalUnixMakefileGenerator3;
  
***************
*** 114,122 ****
     const char* config, bool ignoreErrors, bool fast);
  
!   // returns some progress informaiton
!   int GetTargetTotalNumberOfActions(cmTarget & target,
!                                     std::set<cmTarget *> &emitted);
!   unsigned long GetNumberOfProgressActionsInAll
!   (cmLocalUnixMakefileGenerator3 *lg);
  
    /**
--- 115,120 ----
     const char* config, bool ignoreErrors, bool fast);
  
!   /** Record per-target progress information.  */
!   void RecordTargetProgress(cmMakefileTargetGenerator* tg);
  
    /**
***************
*** 178,181 ****
--- 176,195 ----
  
    bool ForceVerboseMakefiles;
+ 
+   // Store per-target progress counters.
+   struct TargetProgress
+   {
+     TargetProgress(): NumberOfActions(0) {}
+     unsigned long NumberOfActions;
+     std::string VariableFile;
+     std::vector<int> Marks;
+     void WriteProgressVariables(unsigned long total, unsigned long& current);
+   };
+   typedef std::map<cmStdString, TargetProgress> ProgressMapType;
+   ProgressMapType ProgressMap;
+ 
+   size_t CountProgressMarksInTarget(cmTarget* target,
+                                     std::set<cmTarget*>& emitted);
+   size_t CountProgressMarksInAll(cmLocalUnixMakefileGenerator3* lg);
  };
  

Index: cmGlobalUnixMakefileGenerator3.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalUnixMakefileGenerator3.cxx,v
retrieving revision 1.135
retrieving revision 1.136
diff -C 2 -d -r1.135 -r1.136
*** cmGlobalUnixMakefileGenerator3.cxx	10 Jun 2009 17:04:04 -0000	1.135
--- cmGlobalUnixMakefileGenerator3.cxx	25 Jun 2009 13:58:50 -0000	1.136
***************
*** 18,21 ****
--- 18,22 ----
  #include "cmGlobalUnixMakefileGenerator3.h"
  #include "cmLocalUnixMakefileGenerator3.h"
+ #include "cmMakefileTargetGenerator.h"
  #include "cmMakefile.h"
  #include "cmake.h"
***************
*** 151,161 ****
  
    // initialize progress
-   unsigned int i;
    unsigned long total = 0;
!   for (i = 0; i < this->LocalGenerators.size(); ++i)
      {
!     cmLocalUnixMakefileGenerator3 *lg = 
!       static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
!     total += lg->GetNumberOfProgressActions();
      }
  
--- 152,160 ----
  
    // initialize progress
    unsigned long total = 0;
!   for(ProgressMapType::const_iterator pmi = this->ProgressMap.begin();
!       pmi != this->ProgressMap.end(); ++pmi)
      {
!     total += pmi->second.NumberOfActions;
      }
  
***************
*** 168,182 ****
    // computed in the first loop.
    unsigned long current = 0;
!   for (i = 0; i < this->LocalGenerators.size(); ++i)
      {
!     cmLocalUnixMakefileGenerator3 *lg = 
!       static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
!     lg->WriteProgressVariables(total,current);
      }
!   for (i = 0; i < this->LocalGenerators.size(); ++i)
      {
      cmLocalUnixMakefileGenerator3 *lg = 
        static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
!     lg->WriteAllProgressVariable();
      }
    
--- 167,185 ----
    // computed in the first loop.
    unsigned long current = 0;
!   for(ProgressMapType::iterator pmi = this->ProgressMap.begin();
!       pmi != this->ProgressMap.end(); ++pmi)
      {
!     pmi->second.WriteProgressVariables(total, current);
      }
!   for(unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
      {
      cmLocalUnixMakefileGenerator3 *lg = 
        static_cast<cmLocalUnixMakefileGenerator3 *>(this->LocalGenerators[i]);
!     std::string markFileName = lg->GetMakefile()->GetStartOutputDirectory();
!     markFileName += "/";
!     markFileName += cmake::GetCMakeFilesDirectory();
!     markFileName += "/progress.marks";
!     cmGeneratedFileStream markFile(markFileName.c_str());
!     markFile << this->CountProgressMarksInAll(lg) << "\n";
      }
    
***************
*** 753,757 ****
                                  cmLocalGenerator::SHELL);
          progCmd << " ";
!         std::vector<int> &progFiles = lg->ProgressFiles[t->first];
          for (std::vector<int>::iterator i = progFiles.begin();
                i != progFiles.end(); ++i)
--- 756,760 ----
                                  cmLocalGenerator::SHELL);
          progCmd << " ";
!         std::vector<int> &progFiles = this->ProgressMap[t->first].Marks;
          for (std::vector<int>::iterator i = progFiles.begin();
                i != progFiles.end(); ++i)
***************
*** 795,800 ****
        std::set<cmTarget *> emitted;
        progCmd << " " 
!               << this->GetTargetTotalNumberOfActions(t->second,
!                                                       emitted);
        commands.push_back(progCmd.str());
        }
--- 798,802 ----
        std::set<cmTarget *> emitted;
        progCmd << " " 
!               << this->CountProgressMarksInTarget(&t->second, emitted);
        commands.push_back(progCmd.str());
        }
***************
*** 869,912 ****
  
  //----------------------------------------------------------------------------
! int cmGlobalUnixMakefileGenerator3
! ::GetTargetTotalNumberOfActions(cmTarget &target,
!                                 std::set<cmTarget *> &emitted)
  {
!   // do not double count
!   int result = 0;
! 
!   if(emitted.insert(&target).second)
      {
!     cmLocalUnixMakefileGenerator3 *lg = 
!       static_cast<cmLocalUnixMakefileGenerator3 *>
!       (target.GetMakefile()->GetLocalGenerator());
!     result = static_cast<int>(lg->ProgressFiles[target.GetName()].size());
!     
!     TargetDependSet & depends = this->GetTargetDirectDepends(target);
!     
!     TargetDependSet::iterator i;
!     for (i = depends.begin(); i != depends.end(); ++i)
        {
!       result += this->GetTargetTotalNumberOfActions(**i, emitted);
        }
      }
!   
!   return result;
  }
  
! unsigned long cmGlobalUnixMakefileGenerator3
! ::GetNumberOfProgressActionsInAll(cmLocalUnixMakefileGenerator3 *lg)
  {
!   unsigned long result = 0;
!   std::set<cmTarget *> emitted;
!   std::set<cmTarget *>& targets = this->LocalGeneratorToTargetMap[lg];
!   for(std::set<cmTarget *>::iterator t = targets.begin();
        t != targets.end(); ++t)
      {
!     result += this->GetTargetTotalNumberOfActions(**t,emitted);
      }
!   return result;
  }
  
  
  //----------------------------------------------------------------------------
--- 871,945 ----
  
  //----------------------------------------------------------------------------
! size_t
! cmGlobalUnixMakefileGenerator3
! ::CountProgressMarksInTarget(cmTarget* target,
!                              std::set<cmTarget*>& emitted)
  {
!   size_t count = 0;
!   if(emitted.insert(target).second)
      {
!     count = this->ProgressMap[target->GetName()].Marks.size();
!     TargetDependSet const& depends = this->GetTargetDirectDepends(*target);
!     for(TargetDependSet::const_iterator di = depends.begin();
!         di != depends.end(); ++di)
        {
!       count += this->CountProgressMarksInTarget(*di, emitted);
        }
      }
!   return count;
  }
  
! //----------------------------------------------------------------------------
! size_t
! cmGlobalUnixMakefileGenerator3
! ::CountProgressMarksInAll(cmLocalUnixMakefileGenerator3* lg)
  {
!   size_t count = 0;
!   std::set<cmTarget*> emitted;
!   std::set<cmTarget*> const& targets = this->LocalGeneratorToTargetMap[lg];
!   for(std::set<cmTarget*>::const_iterator t = targets.begin();
        t != targets.end(); ++t)
      {
!     count += this->CountProgressMarksInTarget(*t, emitted);
      }
!   return count;
  }
  
+ //----------------------------------------------------------------------------
+ void
+ cmGlobalUnixMakefileGenerator3::RecordTargetProgress(
+   cmMakefileTargetGenerator* tg)
+ {
+   TargetProgress& tp = this->ProgressMap[tg->GetTarget()->GetName()];
+   tp.NumberOfActions = tg->GetNumberOfProgressActions();
+   tp.VariableFile = tg->GetProgressFileNameFull();
+ }
+ 
+ //----------------------------------------------------------------------------
+ void
+ cmGlobalUnixMakefileGenerator3::TargetProgress
+ ::WriteProgressVariables(unsigned long total, unsigned long &current)
+ {
+   cmGeneratedFileStream fout(this->VariableFile.c_str());
+   for(unsigned long i = 1; i <= this->NumberOfActions; ++i)
+     {
+     fout << "CMAKE_PROGRESS_" << i << " = ";
+     if (total <= 100)
+       {
+       unsigned long num = i + current;
+       fout << num;
+       this->Marks.push_back(num);
+       }
+     else if (((i+current)*100)/total > ((i-1+current)*100)/total)
+       {
+       unsigned long num = ((i+current)*100)/total;
+       fout << num;
+       this->Marks.push_back(num);
+       }
+     fout << "\n";
+     }
+   fout << "\n";
+   current += this->NumberOfActions;
+ }
  
  //----------------------------------------------------------------------------

Index: cmMakefileTargetGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefileTargetGenerator.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -C 2 -d -r1.29 -r1.30
*** cmMakefileTargetGenerator.h	16 Mar 2009 20:55:58 -0000	1.29
--- cmMakefileTargetGenerator.h	25 Jun 2009 13:58:51 -0000	1.30
***************
*** 48,59 ****
    virtual void WriteRuleFiles() = 0;
  
-   /* the main entry point for this class. Writes the Makefiles associated
-      with this target */
-   virtual void WriteProgressVariables(unsigned long total, 
-                                       unsigned long &current);
-   
    /* return the number of actions that have progress reporting on them */
    virtual unsigned long GetNumberOfProgressActions() {
      return this->NumberOfProgressActions;}
  
    cmTarget* GetTarget() { return this->Target;}
--- 48,56 ----
    virtual void WriteRuleFiles() = 0;
  
    /* return the number of actions that have progress reporting on them */
    virtual unsigned long GetNumberOfProgressActions() {
      return this->NumberOfProgressActions;}
+   std::string GetProgressFileNameFull()
+     { return this->ProgressFileNameFull; }
  
    cmTarget* GetTarget() { return this->Target;}
***************
*** 168,172 ****
  
    // the full path to the progress file
-   std::string ProgressFileName;
    std::string ProgressFileNameFull;
    unsigned long NumberOfProgressActions;
--- 165,168 ----

Index: cmLocalUnixMakefileGenerator3.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalUnixMakefileGenerator3.cxx,v
retrieving revision 1.265
retrieving revision 1.266
diff -C 2 -d -r1.265 -r1.266
*** cmLocalUnixMakefileGenerator3.cxx	25 Jun 2009 13:43:19 -0000	1.265
--- cmLocalUnixMakefileGenerator3.cxx	25 Jun 2009 13:58:51 -0000	1.266
***************
*** 36,39 ****
--- 36,41 ----
  #endif
  
+ #include <cmsys/auto_ptr.hxx>
+ 
  #include <memory> // auto_ptr
  #include <queue>
***************
*** 127,138 ****
    // Generate the rule files for each target.
    cmTargets& targets = this->Makefile->GetTargets();
    for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
      {
!     cmMakefileTargetGenerator *tg =
!       cmMakefileTargetGenerator::New(&(t->second));
!     if (tg)
        {
-       this->TargetGenerators.push_back(tg);
        tg->WriteRuleFiles();
        }
      }
--- 129,142 ----
    // Generate the rule files for each target.
    cmTargets& targets = this->Makefile->GetTargets();
+   cmGlobalUnixMakefileGenerator3* gg =
+     static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
    for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
      {
!     cmsys::auto_ptr<cmMakefileTargetGenerator> tg(
!       cmMakefileTargetGenerator::New(&(t->second)));
!     if (tg.get())
        {
        tg->WriteRuleFiles();
+       gg->RecordTargetProgress(tg.get());
        }
      }
***************
*** 146,218 ****
  
  //----------------------------------------------------------------------------
- // return info about progress actions
- unsigned long cmLocalUnixMakefileGenerator3::GetNumberOfProgressActions()
- {
-   unsigned long result = 0;
- 
-   for (std::vector<cmMakefileTargetGenerator *>::iterator mtgIter = 
-          this->TargetGenerators.begin();
-        mtgIter != this->TargetGenerators.end(); ++mtgIter)
-     {
-     result += (*mtgIter)->GetNumberOfProgressActions();
-     }  
-   return result;
- }
- 
- //----------------------------------------------------------------------------
- // return info about progress actions
- unsigned long cmLocalUnixMakefileGenerator3
- ::GetNumberOfProgressActionsForTarget(const char *name)
- {
-   for (std::vector<cmMakefileTargetGenerator *>::iterator mtgIter = 
-          this->TargetGenerators.begin();
-        mtgIter != this->TargetGenerators.end(); ++mtgIter)
-     {
-     if (!strcmp(name,(*mtgIter)->GetTarget()->GetName()))
-       {
-       return (*mtgIter)->GetNumberOfProgressActions();
-       }
-     }  
-   return 0;
- }
- 
- 
- //----------------------------------------------------------------------------
- // writes the progreess variables and also closes out the targets
- void cmLocalUnixMakefileGenerator3
- ::WriteProgressVariables(unsigned long total,
-                          unsigned long &current)
- {
-   // delete the makefile target generator objects
-   for (std::vector<cmMakefileTargetGenerator *>::iterator mtgIter = 
-          this->TargetGenerators.begin();
-        mtgIter != this->TargetGenerators.end(); ++mtgIter)
-     {
-     (*mtgIter)->WriteProgressVariables(total,current);
-     delete *mtgIter;
-     }  
-   this->TargetGenerators.clear();
- }
- 
- void cmLocalUnixMakefileGenerator3::WriteAllProgressVariable()
- {
-   // write the top level progress for the all target
-   std::string progressFile = cmake::GetCMakeFilesDirectory();
-   progressFile += "/progress.make";
-   std::string progressFileNameFull = 
-     this->ConvertToFullPath(progressFile.c_str());
-   cmGeneratedFileStream ruleFileStream(progressFileNameFull.c_str());
-   if(!ruleFileStream)
-     {
-     return;
-     }
- 
-   cmGlobalUnixMakefileGenerator3 *gg = 
-     static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
- 
-   ruleFileStream << gg->GetNumberOfProgressActionsInAll(this) << "\n";
- }
- 
- //----------------------------------------------------------------------------
  void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
  {
--- 150,153 ----
***************
*** 1718,1722 ****
  
      std::string progressFile = cmake::GetCMakeFilesDirectory();
!     progressFile += "/progress.make";
      std::string progressFileNameFull =
        this->ConvertToFullPath(progressFile.c_str());
--- 1653,1657 ----
  
      std::string progressFile = cmake::GetCMakeFilesDirectory();
!     progressFile += "/progress.marks";
      std::string progressFileNameFull =
        this->ConvertToFullPath(progressFile.c_str());

Index: cmMakefileTargetGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefileTargetGenerator.cxx,v
retrieving revision 1.118
retrieving revision 1.119
diff -C 2 -d -r1.118 -r1.119
*** cmMakefileTargetGenerator.cxx	16 Mar 2009 20:55:58 -0000	1.118
--- cmMakefileTargetGenerator.cxx	25 Jun 2009 13:58:51 -0000	1.119
***************
*** 97,102 ****
  
    // Construct the rule file name.
-   this->ProgressFileName = this->TargetBuildDirectory;
-   this->ProgressFileName += "/progress.make";
    this->ProgressFileNameFull = this->TargetBuildDirectoryFull;
    this->ProgressFileNameFull += "/progress.make";
--- 97,100 ----
***************
*** 1536,1576 ****
  }
  
- void cmMakefileTargetGenerator::WriteProgressVariables(unsigned long total,
-                                                        unsigned long &current)
- {
-   cmGeneratedFileStream *progressFileStream = 
-     new cmGeneratedFileStream(this->ProgressFileNameFull.c_str());
-   if(!progressFileStream)
-     {
-     return;
-     }
- 
-   unsigned long num;
-   unsigned long i;
-   for (i = 1; i <= this->NumberOfProgressActions; ++i)
-     {
-     *progressFileStream
-       << "CMAKE_PROGRESS_" << i << " = ";
-     if (total <= 100)
-       {
-       num = i + current;
-       *progressFileStream << num;
-       this->LocalGenerator->ProgressFiles[this->Target->GetName()]
-         .push_back(num);
-       }
-     else if (((i+current)*100)/total > ((i-1+current)*100)/total)
-       {
-       num = ((i+current)*100)/total;
-       *progressFileStream << num;
-       this->LocalGenerator->ProgressFiles[this->Target->GetName()]
-         .push_back(num);
-       }
-     *progressFileStream << "\n";
-     }
-   *progressFileStream << "\n";
-   current += this->NumberOfProgressActions;
-   delete progressFileStream;
- }
- 
  //----------------------------------------------------------------------------
  void
--- 1534,1537 ----



More information about the Cmake-commits mailing list