cmCTestLaunch: Port to cmXMLWriter

This commit is contained in:
Daniel Pfeifer 2015-05-24 20:32:33 +02:00 committed by Brad King
parent a53bd63e0c
commit 1dbd86fd6d
2 changed files with 61 additions and 74 deletions

View File

@ -13,7 +13,7 @@
#include "cmGeneratedFileStream.h" #include "cmGeneratedFileStream.h"
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include "cmXMLSafe.h" #include "cmXMLWriter.h"
#include "cmake.h" #include "cmake.h"
#include <cmsys/MD5.h> #include <cmsys/MD5.h>
@ -407,35 +407,32 @@ void cmCTestLaunch::WriteXML()
// Use cmGeneratedFileStream to atomically create the report file. // Use cmGeneratedFileStream to atomically create the report file.
cmGeneratedFileStream fxml(logXML.c_str()); cmGeneratedFileStream fxml(logXML.c_str());
fxml << "\t<Failure type=\"" cmXMLWriter xml(fxml, 2);
<< (this->IsError()? "Error" : "Warning") << "\">\n"; xml.StartElement("Failure");
this->WriteXMLAction(fxml); xml.Attribute("type", this->IsError() ? "Error" : "Warning");
this->WriteXMLCommand(fxml); this->WriteXMLAction(xml);
this->WriteXMLResult(fxml); this->WriteXMLCommand(xml);
this->WriteXMLLabels(fxml); this->WriteXMLResult(xml);
fxml << "\t</Failure>\n"; this->WriteXMLLabels(xml);
xml.EndElement(); // Failure
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCTestLaunch::WriteXMLAction(std::ostream& fxml) void cmCTestLaunch::WriteXMLAction(cmXMLWriter& xml)
{ {
fxml << "\t\t<!-- Meta-information about the build action -->\n"; xml.Comment("Meta-information about the build action");
fxml << "\t\t<Action>\n"; xml.StartElement("Action");
// TargetName // TargetName
if(!this->OptionTargetName.empty()) if(!this->OptionTargetName.empty())
{ {
fxml << "\t\t\t<TargetName>" xml.Element("TargetName", this->OptionTargetName);
<< cmXMLSafe(this->OptionTargetName)
<< "</TargetName>\n";
} }
// Language // Language
if(!this->OptionLanguage.empty()) if(!this->OptionLanguage.empty())
{ {
fxml << "\t\t\t<Language>" xml.Element("Language", this->OptionLanguage);
<< cmXMLSafe(this->OptionLanguage)
<< "</Language>\n";
} }
// SourceFile // SourceFile
@ -454,17 +451,13 @@ void cmCTestLaunch::WriteXMLAction(std::ostream& fxml)
source.c_str()); source.c_str());
} }
fxml << "\t\t\t<SourceFile>" xml.Element("SourceFile", source);
<< cmXMLSafe(source)
<< "</SourceFile>\n";
} }
// OutputFile // OutputFile
if(!this->OptionOutput.empty()) if(!this->OptionOutput.empty())
{ {
fxml << "\t\t\t<OutputFile>" xml.Element("OutputFile", this->OptionOutput);
<< cmXMLSafe(this->OptionOutput)
<< "</OutputFile>\n";
} }
// OutputType // OutputType
@ -494,103 +487,94 @@ void cmCTestLaunch::WriteXMLAction(std::ostream& fxml)
} }
if(outputType) if(outputType)
{ {
fxml << "\t\t\t<OutputType>" xml.Element("OutputType", outputType);
<< cmXMLSafe(outputType)
<< "</OutputType>\n";
} }
fxml << "\t\t</Action>\n"; xml.EndElement(); // Action
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCTestLaunch::WriteXMLCommand(std::ostream& fxml) void cmCTestLaunch::WriteXMLCommand(cmXMLWriter& xml)
{ {
fxml << "\n"; xml.Comment("Details of command");
fxml << "\t\t<!-- Details of command -->\n"; xml.StartElement("Command");
fxml << "\t\t<Command>\n";
if(!this->CWD.empty()) if(!this->CWD.empty())
{ {
fxml << "\t\t\t<WorkingDirectory>" xml.Element("WorkingDirectory", this->CWD);
<< cmXMLSafe(this->CWD)
<< "</WorkingDirectory>\n";
} }
for(std::vector<std::string>::const_iterator ai = this->RealArgs.begin(); for(std::vector<std::string>::const_iterator ai = this->RealArgs.begin();
ai != this->RealArgs.end(); ++ai) ai != this->RealArgs.end(); ++ai)
{ {
fxml << "\t\t\t<Argument>" xml.Element("Argument", *ai);
<< cmXMLSafe(ai->c_str())
<< "</Argument>\n";
} }
fxml << "\t\t</Command>\n"; xml.EndElement(); // Command
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCTestLaunch::WriteXMLResult(std::ostream& fxml) void cmCTestLaunch::WriteXMLResult(cmXMLWriter& xml)
{ {
fxml << "\n"; xml.Comment("Result of command");
fxml << "\t\t<!-- Result of command -->\n"; xml.StartElement("Result");
fxml << "\t\t<Result>\n";
// StdOut // StdOut
fxml << "\t\t\t<StdOut>"; xml.StartElement("StdOut");
this->DumpFileToXML(fxml, this->LogOut); this->DumpFileToXML(xml, this->LogOut);
fxml << "</StdOut>\n"; xml.EndElement(); // StdOut
// StdErr // StdErr
fxml << "\t\t\t<StdErr>"; xml.StartElement("StdErr");
this->DumpFileToXML(fxml, this->LogErr); this->DumpFileToXML(xml, this->LogErr);
fxml << "</StdErr>\n"; xml.EndElement(); // StdErr
// ExitCondition // ExitCondition
fxml << "\t\t\t<ExitCondition>"; xml.StartElement("ExitCondition");
cmsysProcess* cp = this->Process; cmsysProcess* cp = this->Process;
switch (cmsysProcess_GetState(cp)) switch (cmsysProcess_GetState(cp))
{ {
case cmsysProcess_State_Starting: case cmsysProcess_State_Starting:
fxml << "No process has been executed"; break; xml.Content("No process has been executed"); break;
case cmsysProcess_State_Executing: case cmsysProcess_State_Executing:
fxml << "The process is still executing"; break; xml.Content("The process is still executing"); break;
case cmsysProcess_State_Disowned: case cmsysProcess_State_Disowned:
fxml << "Disowned"; break; xml.Content("Disowned"); break;
case cmsysProcess_State_Killed: case cmsysProcess_State_Killed:
fxml << "Killed by parent"; break; xml.Content("Killed by parent"); break;
case cmsysProcess_State_Expired: case cmsysProcess_State_Expired:
fxml << "Killed when timeout expired"; break; xml.Content("Killed when timeout expired"); break;
case cmsysProcess_State_Exited: case cmsysProcess_State_Exited:
fxml << this->ExitCode; break; xml.Content(this->ExitCode); break;
case cmsysProcess_State_Exception: case cmsysProcess_State_Exception:
fxml << "Terminated abnormally: " xml.Content("Terminated abnormally: ");
<< cmXMLSafe(cmsysProcess_GetExceptionString(cp)); break; xml.Content(cmsysProcess_GetExceptionString(cp)); break;
case cmsysProcess_State_Error: case cmsysProcess_State_Error:
fxml << "Error administrating child process: " xml.Content("Error administrating child process: ");
<< cmXMLSafe(cmsysProcess_GetErrorString(cp)); break; xml.Content(cmsysProcess_GetErrorString(cp)); break;
}; };
fxml << "</ExitCondition>\n"; xml.EndElement(); // ExitCondition
fxml << "\t\t</Result>\n"; xml.EndElement(); // Result
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCTestLaunch::WriteXMLLabels(std::ostream& fxml) void cmCTestLaunch::WriteXMLLabels(cmXMLWriter& xml)
{ {
this->LoadLabels(); this->LoadLabels();
if(!this->Labels.empty()) if(!this->Labels.empty())
{ {
fxml << "\n"; xml.Comment("Interested parties");
fxml << "\t\t<!-- Interested parties -->\n"; xml.StartElement("Labels");
fxml << "\t\t<Labels>\n";
for(std::set<std::string>::const_iterator li = this->Labels.begin(); for(std::set<std::string>::const_iterator li = this->Labels.begin();
li != this->Labels.end(); ++li) li != this->Labels.end(); ++li)
{ {
fxml << "\t\t\t<Label>" << cmXMLSafe(*li) << "</Label>\n"; xml.Element("Label", *li);
} }
fxml << "\t\t</Labels>\n"; xml.EndElement(); // Labels
} }
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmCTestLaunch::DumpFileToXML(std::ostream& fxml, void cmCTestLaunch::DumpFileToXML(cmXMLWriter& xml,
std::string const& fname) std::string const& fname)
{ {
cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary); cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
@ -605,7 +589,8 @@ void cmCTestLaunch::DumpFileToXML(std::ostream& fxml,
continue; continue;
} }
fxml << sep << cmXMLSafe(line).Quotes(false); xml.Content(sep);
xml.Content(line);
sep = "\n"; sep = "\n";
} }
} }

View File

@ -15,6 +15,8 @@
#include "cmStandardIncludes.h" #include "cmStandardIncludes.h"
#include <cmsys/RegularExpression.hxx> #include <cmsys/RegularExpression.hxx>
class cmXMLWriter;
/** \class cmCTestLaunch /** \class cmCTestLaunch
* \brief Launcher for make rules to report results for ctest * \brief Launcher for make rules to report results for ctest
* *
@ -92,11 +94,11 @@ private:
// Methods to generate the xml fragment. // Methods to generate the xml fragment.
void WriteXML(); void WriteXML();
void WriteXMLAction(std::ostream& fxml); void WriteXMLAction(cmXMLWriter& xml);
void WriteXMLCommand(std::ostream& fxml); void WriteXMLCommand(cmXMLWriter& xml);
void WriteXMLResult(std::ostream& fxml); void WriteXMLResult(cmXMLWriter& xml);
void WriteXMLLabels(std::ostream& fxml); void WriteXMLLabels(cmXMLWriter& xml);
void DumpFileToXML(std::ostream& fxml, std::string const& fname); void DumpFileToXML(cmXMLWriter& xml, std::string const& fname);
// Configuration // Configuration
void LoadConfig(); void LoadConfig();