cmCTestBuildHandler: Port to cmXMLWriter

This commit is contained in:
Daniel Pfeifer 2015-05-24 21:36:12 +02:00 committed by Brad King
parent 1dbd86fd6d
commit 82455a9d3a
2 changed files with 45 additions and 62 deletions

View File

@ -18,7 +18,7 @@
#include "cmLocalGenerator.h" #include "cmLocalGenerator.h"
#include "cmGlobalGenerator.h" #include "cmGlobalGenerator.h"
#include "cmGeneratedFileStream.h" #include "cmGeneratedFileStream.h"
#include "cmXMLSafe.h" #include "cmXMLWriter.h"
#include "cmFileTimeComparison.h" #include "cmFileTimeComparison.h"
#include "cmAlgorithms.h" #include "cmAlgorithms.h"
@ -523,16 +523,17 @@ int cmCTestBuildHandler::ProcessHandler()
<< std::endl); << std::endl);
return -1; return -1;
} }
this->GenerateXMLHeader(xofs); cmXMLWriter xml(xofs);
this->GenerateXMLHeader(xml);
if(this->UseCTestLaunch) if(this->UseCTestLaunch)
{ {
this->GenerateXMLLaunched(xofs); this->GenerateXMLLaunched(xml);
} }
else else
{ {
this->GenerateXMLLogScraped(xofs); this->GenerateXMLLogScraped(xml);
} }
this->GenerateXMLFooter(xofs, elapsed_build_time); this->GenerateXMLFooter(xml, elapsed_build_time);
if (res != cmsysProcess_State_Exited || retVal || this->TotalErrors > 0) if (res != cmsysProcess_State_Exited || retVal || this->TotalErrors > 0)
{ {
@ -552,17 +553,14 @@ int cmCTestBuildHandler::ProcessHandler()
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCTestBuildHandler::GenerateXMLHeader(std::ostream& os) void cmCTestBuildHandler::GenerateXMLHeader(cmXMLWriter& xml)
{ {
this->CTest->StartXML(os, this->AppendXML); this->CTest->StartXML(xml, this->AppendXML);
os << "<Build>\n" xml.StartElement("Build");
<< "\t<StartDateTime>" << this->StartBuild << "</StartDateTime>\n" xml.Element("StartDateTime", this->StartBuild);
<< "\t<StartBuildTime>" << xml.Element("StartBuildTime",
static_cast<unsigned int>(this->StartBuildTime) static_cast<unsigned int>(this->StartBuildTime));
<< "</StartBuildTime>\n" xml.Element("BuildCommand", this->GetMakeCommand());
<< "<BuildCommand>"
<< cmXMLSafe(this->GetMakeCommand())
<< "</BuildCommand>" << std::endl;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -591,7 +589,7 @@ private:
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCTestBuildHandler::GenerateXMLLaunched(std::ostream& os) void cmCTestBuildHandler::GenerateXMLLaunched(cmXMLWriter& xml)
{ {
if(this->CTestLaunchDir.empty()) if(this->CTestLaunchDir.empty())
{ {
@ -632,12 +630,12 @@ void cmCTestBuildHandler::GenerateXMLLaunched(std::ostream& os)
for(Fragments::const_iterator fi = fragments.begin(); for(Fragments::const_iterator fi = fragments.begin();
fi != fragments.end(); ++fi) fi != fragments.end(); ++fi)
{ {
this->GenerateXMLLaunchedFragment(os, fi->c_str()); xml.FragmentFile(fi->c_str());
} }
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCTestBuildHandler::GenerateXMLLogScraped(std::ostream& os) void cmCTestBuildHandler::GenerateXMLLogScraped(cmXMLWriter& xml)
{ {
std::vector<cmCTestBuildErrorWarning>& ew = this->ErrorsAndWarnings; std::vector<cmCTestBuildErrorWarning>& ew = this->ErrorsAndWarnings;
std::vector<cmCTestBuildErrorWarning>::iterator it; std::vector<cmCTestBuildErrorWarning>::iterator it;
@ -665,10 +663,9 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(std::ostream& os)
{ {
numWarningsAllowed--; numWarningsAllowed--;
} }
os << "\t<" << (cm->Error ? "Error" : "Warning") << ">\n" xml.StartElement(cm->Error ? "Error" : "Warning");
<< "\t\t<BuildLogLine>" << cm->LogLine << "</BuildLogLine>\n" xml.Element("BuildLogLine", cm->LogLine);
<< "\t\t<Text>" << cmXMLSafe(cm->Text).Quotes(false) xml.Element("Text", cm->Text);
<< "\n</Text>" << std::endl;
std::vector<cmCTestCompileErrorWarningRex>::iterator rit; std::vector<cmCTestCompileErrorWarningRex>::iterator rit;
for ( rit = this->ErrorWarningFileLineRegex.begin(); for ( rit = this->ErrorWarningFileLineRegex.begin();
rit != this->ErrorWarningFileLineRegex.end(); ++ rit ) rit != this->ErrorWarningFileLineRegex.end(); ++ rit )
@ -706,62 +703,48 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(std::ostream& os)
{ {
if (!cm->SourceFile.empty()) if (!cm->SourceFile.empty())
{ {
os << "\t\t<SourceFile>" << cm->SourceFile << "</SourceFile>" xml.Element("SourceFile", cm->SourceFile);
<< std::endl;
} }
if (!cm->SourceFileTail.empty()) if (!cm->SourceFileTail.empty())
{ {
os << "\t\t<SourceFileTail>" << cm->SourceFileTail xml.Element("SourceFileTail", cm->SourceFileTail);
<< "</SourceFileTail>" << std::endl;
} }
if ( cm->LineNumber >= 0 ) if ( cm->LineNumber >= 0 )
{ {
os << "\t\t<SourceLineNumber>" << cm->LineNumber xml.Element("SourceLineNumber", cm->LineNumber);
<< "</SourceLineNumber>" << std::endl;
} }
} }
os << "\t\t<PreContext>" << cmXMLSafe(cm->PreContext).Quotes(false) xml.Element("PreContext", cm->PreContext);
<< "</PreContext>\n" xml.StartElement("PostContext");
<< "\t\t<PostContext>" << cmXMLSafe(cm->PostContext).Quotes(false); xml.Content(cm->PostContext);
// is this the last warning or error, if so notify // is this the last warning or error, if so notify
if ((cm->Error && !numErrorsAllowed) || if ((cm->Error && !numErrorsAllowed) ||
(!cm->Error && !numWarningsAllowed)) (!cm->Error && !numWarningsAllowed))
{ {
os << "\nThe maximum number of reported warnings or errors has been " xml.Content("\nThe maximum number of reported warnings or errors "
"reached!!!\n"; "has been reached!!!\n");
} }
os << "</PostContext>\n" xml.EndElement(); // PostContext
<< "\t\t<RepeatCount>0</RepeatCount>\n" xml.Element("RepeatCount", "0");
<< "</" << (cm->Error ? "Error" : "Warning") << ">\n\n" xml.EndElement(); // "Error" / "Warning"
<< std::endl;
} }
} }
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCTestBuildHandler::GenerateXMLFooter(std::ostream& os, void cmCTestBuildHandler::GenerateXMLFooter(cmXMLWriter& xml,
double elapsed_build_time) double elapsed_build_time)
{ {
os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n" xml.StartElement("Log");
<< "\t<EndDateTime>" << this->EndBuild << "</EndDateTime>\n" xml.Attribute("Encoding", "base64");
<< "\t<EndBuildTime>" << static_cast<unsigned int>(this->EndBuildTime) xml.Attribute("Compression", "bin/gzip");
<< "</EndBuildTime>\n" xml.EndElement(); // Log
<< "<ElapsedMinutes>" << static_cast<int>(elapsed_build_time/6)/10.0
<< "</ElapsedMinutes>"
<< "</Build>" << std::endl;
this->CTest->EndXML(os);
}
//---------------------------------------------------------------------------- xml.Element("EndDateTime", this->EndBuild);
void cmCTestBuildHandler::GenerateXMLLaunchedFragment(std::ostream& os, xml.Element("EndBuildTime", static_cast<unsigned int>(this->EndBuildTime));
const char* fname) xml.Element("ElapsedMinutes", static_cast<int>(elapsed_build_time/6)/10.0);
{ xml.EndElement(); // Build
cmsys::ifstream fin(fname, std::ios::in | std::ios::binary); this->CTest->EndXML(xml);
std::string line;
while(cmSystemTools::GetLineFromStream(fin, line))
{
os << line << "\n";
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -22,6 +22,7 @@
#include <deque> #include <deque>
class cmMakefile; class cmMakefile;
class cmXMLWriter;
/** \class cmCTestBuildHandler /** \class cmCTestBuildHandler
* \brief A class that handles ctest -S invocations * \brief A class that handles ctest -S invocations
@ -86,11 +87,10 @@ private:
}; };
// generate the XML output // generate the XML output
void GenerateXMLHeader(std::ostream& os); void GenerateXMLHeader(cmXMLWriter& xml);
void GenerateXMLLaunched(std::ostream& os); void GenerateXMLLaunched(cmXMLWriter& xml);
void GenerateXMLLogScraped(std::ostream& os); void GenerateXMLLogScraped(cmXMLWriter& xml);
void GenerateXMLFooter(std::ostream& os, double elapsed_build_time); void GenerateXMLFooter(cmXMLWriter& xml, double elapsed_build_time);
void GenerateXMLLaunchedFragment(std::ostream& os, const char* fname);
bool IsLaunchedErrorFile(const char* fname); bool IsLaunchedErrorFile(const char* fname);
bool IsLaunchedWarningFile(const char* fname); bool IsLaunchedWarningFile(const char* fname);