mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-07 07:39:32 -06:00
cmCTestLaunch: use cmXMLElement for XML generation
class `cmXMLElement` enhanced with more members; its use demonstrated
This commit is contained in:
committed by
Brad King
parent
d44441a365
commit
ff13b0cdc2
@@ -347,28 +347,27 @@ 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());
|
||||||
cmXMLWriter xml(fxml, 2);
|
cmXMLWriter xml(fxml, 2);
|
||||||
xml.StartElement("Failure");
|
cmXMLElement e2(xml, "Failure");
|
||||||
xml.Attribute("type", this->IsError() ? "Error" : "Warning");
|
e2.Attribute("type", this->IsError() ? "Error" : "Warning");
|
||||||
this->WriteXMLAction(xml);
|
this->WriteXMLAction(e2);
|
||||||
this->WriteXMLCommand(xml);
|
this->WriteXMLCommand(e2);
|
||||||
this->WriteXMLResult(xml);
|
this->WriteXMLResult(e2);
|
||||||
this->WriteXMLLabels(xml);
|
this->WriteXMLLabels(e2);
|
||||||
xml.EndElement(); // Failure
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmCTestLaunch::WriteXMLAction(cmXMLWriter& xml)
|
void cmCTestLaunch::WriteXMLAction(cmXMLElement& e2)
|
||||||
{
|
{
|
||||||
xml.Comment("Meta-information about the build action");
|
e2.Comment("Meta-information about the build action");
|
||||||
xml.StartElement("Action");
|
cmXMLElement e3(e2, "Action");
|
||||||
|
|
||||||
// TargetName
|
// TargetName
|
||||||
if (!this->OptionTargetName.empty()) {
|
if (!this->OptionTargetName.empty()) {
|
||||||
xml.Element("TargetName", this->OptionTargetName);
|
e3.Element("TargetName", this->OptionTargetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Language
|
// Language
|
||||||
if (!this->OptionLanguage.empty()) {
|
if (!this->OptionLanguage.empty()) {
|
||||||
xml.Element("Language", this->OptionLanguage);
|
e3.Element("Language", this->OptionLanguage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SourceFile
|
// SourceFile
|
||||||
@@ -383,12 +382,12 @@ void cmCTestLaunch::WriteXMLAction(cmXMLWriter& xml)
|
|||||||
source = cmSystemTools::RelativePath(this->SourceDir, source);
|
source = cmSystemTools::RelativePath(this->SourceDir, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
xml.Element("SourceFile", source);
|
e3.Element("SourceFile", source);
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutputFile
|
// OutputFile
|
||||||
if (!this->OptionOutput.empty()) {
|
if (!this->OptionOutput.empty()) {
|
||||||
xml.Element("OutputFile", this->OptionOutput);
|
e3.Element("OutputFile", this->OptionOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutputType
|
// OutputType
|
||||||
@@ -407,97 +406,88 @@ void cmCTestLaunch::WriteXMLAction(cmXMLWriter& xml)
|
|||||||
outputType = "object file";
|
outputType = "object file";
|
||||||
}
|
}
|
||||||
if (outputType) {
|
if (outputType) {
|
||||||
xml.Element("OutputType", outputType);
|
e3.Element("OutputType", outputType);
|
||||||
}
|
}
|
||||||
|
|
||||||
xml.EndElement(); // Action
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmCTestLaunch::WriteXMLCommand(cmXMLWriter& xml)
|
void cmCTestLaunch::WriteXMLCommand(cmXMLElement& e2)
|
||||||
{
|
{
|
||||||
xml.Comment("Details of command");
|
e2.Comment("Details of command");
|
||||||
xml.StartElement("Command");
|
cmXMLElement e3(e2, "Command");
|
||||||
if (!this->CWD.empty()) {
|
if (!this->CWD.empty()) {
|
||||||
xml.Element("WorkingDirectory", this->CWD);
|
e3.Element("WorkingDirectory", this->CWD);
|
||||||
}
|
}
|
||||||
for (std::string const& realArg : this->RealArgs) {
|
for (std::string const& realArg : this->RealArgs) {
|
||||||
xml.Element("Argument", realArg);
|
e3.Element("Argument", realArg);
|
||||||
}
|
}
|
||||||
xml.EndElement(); // Command
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmCTestLaunch::WriteXMLResult(cmXMLWriter& xml)
|
void cmCTestLaunch::WriteXMLResult(cmXMLElement& e2)
|
||||||
{
|
{
|
||||||
xml.Comment("Result of command");
|
e2.Comment("Result of command");
|
||||||
xml.StartElement("Result");
|
cmXMLElement e3(e2, "Result");
|
||||||
|
|
||||||
// StdOut
|
// StdOut
|
||||||
xml.StartElement("StdOut");
|
this->DumpFileToXML(e3, "StdOut", this->LogOut);
|
||||||
this->DumpFileToXML(xml, this->LogOut);
|
|
||||||
xml.EndElement(); // StdOut
|
|
||||||
|
|
||||||
// StdErr
|
// StdErr
|
||||||
xml.StartElement("StdErr");
|
this->DumpFileToXML(e3, "StdErr", this->LogErr);
|
||||||
this->DumpFileToXML(xml, this->LogErr);
|
|
||||||
xml.EndElement(); // StdErr
|
|
||||||
|
|
||||||
// ExitCondition
|
// ExitCondition
|
||||||
xml.StartElement("ExitCondition");
|
cmXMLElement e4(e3, "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:
|
||||||
xml.Content("No process has been executed");
|
e4.Content("No process has been executed");
|
||||||
break;
|
break;
|
||||||
case cmsysProcess_State_Executing:
|
case cmsysProcess_State_Executing:
|
||||||
xml.Content("The process is still executing");
|
e4.Content("The process is still executing");
|
||||||
break;
|
break;
|
||||||
case cmsysProcess_State_Disowned:
|
case cmsysProcess_State_Disowned:
|
||||||
xml.Content("Disowned");
|
e4.Content("Disowned");
|
||||||
break;
|
break;
|
||||||
case cmsysProcess_State_Killed:
|
case cmsysProcess_State_Killed:
|
||||||
xml.Content("Killed by parent");
|
e4.Content("Killed by parent");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case cmsysProcess_State_Expired:
|
case cmsysProcess_State_Expired:
|
||||||
xml.Content("Killed when timeout expired");
|
e4.Content("Killed when timeout expired");
|
||||||
break;
|
break;
|
||||||
case cmsysProcess_State_Exited:
|
case cmsysProcess_State_Exited:
|
||||||
xml.Content(this->ExitCode);
|
e4.Content(this->ExitCode);
|
||||||
break;
|
break;
|
||||||
case cmsysProcess_State_Exception:
|
case cmsysProcess_State_Exception:
|
||||||
xml.Content("Terminated abnormally: ");
|
e4.Content("Terminated abnormally: ");
|
||||||
xml.Content(cmsysProcess_GetExceptionString(cp));
|
e4.Content(cmsysProcess_GetExceptionString(cp));
|
||||||
break;
|
break;
|
||||||
case cmsysProcess_State_Error:
|
case cmsysProcess_State_Error:
|
||||||
xml.Content("Error administrating child process: ");
|
e4.Content("Error administrating child process: ");
|
||||||
xml.Content(cmsysProcess_GetErrorString(cp));
|
e4.Content(cmsysProcess_GetErrorString(cp));
|
||||||
break;
|
break;
|
||||||
};
|
|
||||||
xml.EndElement(); // ExitCondition
|
|
||||||
|
|
||||||
xml.EndElement(); // Result
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmCTestLaunch::WriteXMLLabels(cmXMLWriter& xml)
|
|
||||||
{
|
|
||||||
this->LoadLabels();
|
|
||||||
if (!this->Labels.empty()) {
|
|
||||||
xml.Comment("Interested parties");
|
|
||||||
xml.StartElement("Labels");
|
|
||||||
for (std::string const& label : this->Labels) {
|
|
||||||
xml.Element("Label", label);
|
|
||||||
}
|
|
||||||
xml.EndElement(); // Labels
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmCTestLaunch::DumpFileToXML(cmXMLWriter& xml, std::string const& fname)
|
void cmCTestLaunch::WriteXMLLabels(cmXMLElement& e2)
|
||||||
|
{
|
||||||
|
this->LoadLabels();
|
||||||
|
if (!this->Labels.empty()) {
|
||||||
|
e2.Comment("Interested parties");
|
||||||
|
cmXMLElement e3(e2, "Labels");
|
||||||
|
for (std::string const& label : this->Labels) {
|
||||||
|
e3.Element("Label", label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmCTestLaunch::DumpFileToXML(cmXMLElement& e3, const char* tag,
|
||||||
|
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);
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
const char* sep = "";
|
const char* sep = "";
|
||||||
|
|
||||||
|
cmXMLElement e4(e3, tag);
|
||||||
while (cmSystemTools::GetLineFromStream(fin, line)) {
|
while (cmSystemTools::GetLineFromStream(fin, line)) {
|
||||||
if (MatchesFilterPrefix(line)) {
|
if (MatchesFilterPrefix(line)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -507,8 +497,8 @@ void cmCTestLaunch::DumpFileToXML(cmXMLWriter& xml, std::string const& fname)
|
|||||||
} else if (this->Match(line, this->RegexWarning)) {
|
} else if (this->Match(line, this->RegexWarning)) {
|
||||||
line = "[CTest: warning matched] " + line;
|
line = "[CTest: warning matched] " + line;
|
||||||
}
|
}
|
||||||
xml.Content(sep);
|
e4.Content(sep);
|
||||||
xml.Content(line);
|
e4.Content(line);
|
||||||
sep = "\n";
|
sep = "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class cmXMLWriter;
|
class cmXMLElement;
|
||||||
|
|
||||||
/** \class cmCTestLaunch
|
/** \class cmCTestLaunch
|
||||||
* \brief Launcher for make rules to report results for ctest
|
* \brief Launcher for make rules to report results for ctest
|
||||||
@@ -89,11 +89,11 @@ private:
|
|||||||
|
|
||||||
// Methods to generate the xml fragment.
|
// Methods to generate the xml fragment.
|
||||||
void WriteXML();
|
void WriteXML();
|
||||||
void WriteXMLAction(cmXMLWriter& xml);
|
void WriteXMLAction(cmXMLElement&);
|
||||||
void WriteXMLCommand(cmXMLWriter& xml);
|
void WriteXMLCommand(cmXMLElement&);
|
||||||
void WriteXMLResult(cmXMLWriter& xml);
|
void WriteXMLResult(cmXMLElement&);
|
||||||
void WriteXMLLabels(cmXMLWriter& xml);
|
void WriteXMLLabels(cmXMLElement&);
|
||||||
void DumpFileToXML(cmXMLWriter& xml, std::string const& fname);
|
void DumpFileToXML(cmXMLElement&, const char* tag, std::string const& fname);
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
void LoadConfig();
|
void LoadConfig();
|
||||||
|
|||||||
@@ -181,6 +181,12 @@ public:
|
|||||||
{
|
{
|
||||||
xmlwr.Content(content);
|
xmlwr.Content(content);
|
||||||
}
|
}
|
||||||
|
template <typename T>
|
||||||
|
void Element(std::string const& name, T const& value)
|
||||||
|
{
|
||||||
|
xmlwr.Element(name, value);
|
||||||
|
}
|
||||||
|
void Comment(const char* comment) { xmlwr.Comment(comment); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cmXMLWriter& xmlwr;
|
cmXMLWriter& xmlwr;
|
||||||
|
|||||||
Reference in New Issue
Block a user