[Cmake-commits] [cmake-commits] king committed cmCTestCoverageHandler.cxx 1.63 1.64 cmCTestCoverageHandler.h 1.17 1.18

cmake-commits at cmake.org cmake-commits at cmake.org
Fri Feb 13 15:17:08 EST 2009


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

Modified Files:
	cmCTestCoverageHandler.cxx cmCTestCoverageHandler.h 
Log Message:
ENH: Teach CTest to put labels in coverage results

This teaches CTest to include source file labels in coverage dashboard
submissions.  The labels for each source are the union of the LABELS
property from the source file and all the targets in which it is built.


Index: cmCTestCoverageHandler.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestCoverageHandler.cxx,v
retrieving revision 1.63
retrieving revision 1.64
diff -C 2 -d -r1.63 -r1.64
*** cmCTestCoverageHandler.cxx	13 Feb 2009 20:16:58 -0000	1.63
--- cmCTestCoverageHandler.cxx	13 Feb 2009 20:17:06 -0000	1.64
***************
*** 320,323 ****
--- 320,325 ----
      = this->CTest->GetCTestConfiguration("BuildDirectory");
  
+   this->LoadLabels();
+ 
    cmGeneratedFileStream ofs;
    double elapsed_time_start = cmSystemTools::GetTime();
***************
*** 465,475 ****
        }
  
      const cmCTestCoverageHandlerContainer::SingleFileCoverageVector& fcov
        = fileIterator->second;
!     covLogFile << "\t<File Name=\""
!       << cmXMLSafe(fileName)
!       << "\" FullPath=\"" << cmXMLSafe(
!         this->CTest->GetShortPathToFile(
!           fileIterator->first.c_str())) << "\">" << std::endl
        << "\t\t<Report>" << std::endl;
  
--- 467,476 ----
        }
  
+     std::string shortFileName =
+       this->CTest->GetShortPathToFile(fullFileName.c_str());
      const cmCTestCoverageHandlerContainer::SingleFileCoverageVector& fcov
        = fileIterator->second;
!     covLogFile << "\t<File Name=\"" << cmXMLSafe(fileName)
!       << "\" FullPath=\"" << cmXMLSafe(shortFileName) << "\">\n"
        << "\t\t<Report>" << std::endl;
  
***************
*** 547,552 ****
      covSumFile.setf(std::ios::fixed, std::ios::floatfield);
      covSumFile.precision(2);
!     covSumFile << (cmet) << "</CoverageMetric>\n"
!       << "\t</File>" << std::endl;
      cnt ++;
      }
--- 548,554 ----
      covSumFile.setf(std::ios::fixed, std::ios::floatfield);
      covSumFile.precision(2);
!     covSumFile << (cmet) << "</CoverageMetric>\n";
!     this->WriteXMLLabels(covSumFile, shortFileName);
!     covSumFile << "\t</File>" << std::endl;
      cnt ++;
      }
***************
*** 1714,1715 ****
--- 1716,1814 ----
    return true;
  }
+ 
+ //----------------------------------------------------------------------
+ int cmCTestCoverageHandler::GetLabelId(std::string const& label)
+ {
+   LabelIdMapType::iterator i = this->LabelIdMap.find(label);
+   if(i == this->LabelIdMap.end())
+     {
+     int n = int(this->Labels.size());
+     this->Labels.push_back(label);
+     LabelIdMapType::value_type entry(label, n);
+     i = this->LabelIdMap.insert(entry).first;
+     }
+   return i->second;
+ }
+ 
+ //----------------------------------------------------------------------
+ void cmCTestCoverageHandler::LoadLabels()
+ {
+   std::string fileList = this->CTest->GetBinaryDir();
+   fileList += cmake::GetCMakeFilesDirectory();
+   fileList += "/LabelFiles.txt";
+   cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+              " label file list [" << fileList << "]\n");
+   std::ifstream finList(fileList.c_str());
+   std::string line;
+   while(cmSystemTools::GetLineFromStream(finList, line))
+     {
+     this->LoadLabels(line.c_str());
+     }
+ }
+ 
+ //----------------------------------------------------------------------
+ void cmCTestCoverageHandler::LoadLabels(const char* fname)
+ {
+   cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+              " loading labels from [" << fname << "]\n");
+   std::ifstream fin(fname);
+   bool inTarget = true;
+   std::string source;
+   std::string line;
+   std::vector<int> targetLabels;
+   while(cmSystemTools::GetLineFromStream(fin, line))
+     {
+     if(line.empty() || line[0] == '#')
+       {
+       // Ignore blank and comment lines.
+       continue;
+       }
+     else if(line[0] == ' ')
+       {
+       // Label lines appear indented by one space.
+       std::string label = line.substr(1);
+       int id = this->GetLabelId(label);
+       if(inTarget)
+         {
+         targetLabels.push_back(id);
+         }
+       else
+         {
+         this->SourceLabels[source].insert(id);
+         }
+       }
+     else
+       {
+       // Non-indented lines specify a source file name.  The first one
+       // is the end of the target-wide labels.
+       inTarget = false;
+ 
+       source = this->CTest->GetShortPathToFile(line.c_str());
+ 
+       // Label the source with the target labels.
+       LabelSet& labelSet = this->SourceLabels[source];
+       for(std::vector<int>::const_iterator li = targetLabels.begin();
+           li != targetLabels.end(); ++li)
+         {
+         labelSet.insert(*li);
+         }
+       }
+     }
+ }
+ 
+ //----------------------------------------------------------------------
+ void cmCTestCoverageHandler::WriteXMLLabels(std::ofstream& os,
+                                             std::string const& source)
+ {
+   LabelMapType::const_iterator li = this->SourceLabels.find(source);
+   if(li != this->SourceLabels.end() && !li->second.empty())
+     {
+     os << "\t\t<Labels>\n";
+     for(LabelSet::const_iterator lsi = li->second.begin();
+         lsi != li->second.end(); ++lsi)
+       {
+       os << "\t\t\t<Label>" << cmXMLSafe(this->Labels[*lsi]) << "</Label>\n";
+       }
+     os << "\t\t</Labels>\n";
+     }
+ }

Index: cmCTestCoverageHandler.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestCoverageHandler.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -C 2 -d -r1.17 -r1.18
*** cmCTestCoverageHandler.h	8 Jun 2007 16:29:40 -0000	1.17
--- cmCTestCoverageHandler.h	13 Feb 2009 20:17:06 -0000	1.18
***************
*** 138,141 ****
--- 138,157 ----
  
    typedef std::map<std::string, cmCTestCoverage> CoverageMap;
+ 
+   // Map from source file to label ids.
+   class LabelSet: public std::set<int> {};
+   typedef std::map<cmStdString, LabelSet> LabelMapType;
+   LabelMapType SourceLabels;
+ 
+   // Map from label name to label id.
+   typedef std::map<cmStdString, int> LabelIdMapType;
+   LabelIdMapType LabelIdMap;
+   std::vector<std::string> Labels;
+   int GetLabelId(std::string const& label);
+ 
+   // Load reading and writing methods.
+   void LoadLabels();
+   void LoadLabels(const char* fname);
+   void WriteXMLLabels(std::ofstream& os, std::string const& source);
  };
  



More information about the Cmake-commits mailing list