From 18825bafd99c6a9c8ec1fb4e7b22a8059c680572 Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Sun, 24 May 2015 00:00:16 +0200 Subject: [PATCH] cmCTest: Port to cmXMLWriter Re-implement StartXML, EndXML, and AddSiteProperties using cmXMLWriter. Leave the old overloads behind for use by CTest/* until they are ported. --- Source/cmCTest.cxx | 117 +++++++++++++++++++++++++++++++++++++++++++++ Source/cmCTest.h | 4 ++ 2 files changed, 121 insertions(+) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 211c83c53..48a7ec741 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -28,6 +28,7 @@ #include "cmCTestStartCommand.h" #include "cmAlgorithms.h" #include "cmState.h" +#include "cmXMLWriter.h" #include "cmCTestBuildHandler.h" #include "cmCTestBuildAndTestHandler.h" @@ -1547,6 +1548,67 @@ void cmCTest::StartXML(std::ostream& ostr, bool append) this->AddSiteProperties(ostr); } +//---------------------------------------------------------------------- +void cmCTest::StartXML(cmXMLWriter& xml, bool append) +{ + if(this->CurrentTag.empty()) + { + cmCTestLog(this, ERROR_MESSAGE, + "Current Tag empty, this may mean" + " NightlStartTime was not set correctly." << std::endl); + cmSystemTools::SetFatalErrorOccured(); + } + + // find out about the system + cmsys::SystemInformation info; + info.RunCPUCheck(); + info.RunOSCheck(); + info.RunMemoryCheck(); + + std::string buildname = cmCTest::SafeBuildIdField( + this->GetCTestConfiguration("BuildName")); + std::string stamp = cmCTest::SafeBuildIdField( + this->CurrentTag + "-" + this->GetTestModelString()); + std::string site = cmCTest::SafeBuildIdField( + this->GetCTestConfiguration("Site")); + + xml.StartDocument(); + xml.StartElement("Site"); + xml.Attribute("BuildName", buildname); + xml.BreakAttributes(); + xml.Attribute("BuildStamp", stamp); + xml.Attribute("Name", site); + xml.Attribute("Generator", + std::string("ctest-") + cmVersion::GetCMakeVersion()); + if(append) + { + xml.Attribute("Append", "true"); + } + xml.Attribute("CompilerName", this->GetCTestConfiguration("Compiler")); +#ifdef _COMPILER_VERSION + xml.Attribute("CompilerVersion", _COMPILER_VERSION); +#endif + xml.Attribute("OSName", info.GetOSName()); + xml.Attribute("Hostname", info.GetHostname()); + xml.Attribute("OSRelease", info.GetOSRelease()); + xml.Attribute("OSVersion", info.GetOSVersion()); + xml.Attribute("OSPlatform", info.GetOSPlatform()); + xml.Attribute("Is64Bits", info.Is64Bits()); + xml.Attribute("VendorString", info.GetVendorString()); + xml.Attribute("VendorID", info.GetVendorID()); + xml.Attribute("FamilyID", info.GetFamilyID()); + xml.Attribute("ModelID", info.GetModelID()); + xml.Attribute("ProcessorCacheSize", info.GetProcessorCacheSize()); + xml.Attribute("NumberOfLogicalCPU", info.GetNumberOfLogicalCPU()); + xml.Attribute("NumberOfPhysicalCPU", info.GetNumberOfPhysicalCPU()); + xml.Attribute("TotalVirtualMemory", info.GetTotalVirtualMemory()); + xml.Attribute("TotalPhysicalMemory", info.GetTotalPhysicalMemory()); + xml.Attribute("LogicalProcessorsPerPhysical", + info.GetLogicalProcessorsPerPhysical()); + xml.Attribute("ProcessorClockFrequency", info.GetProcessorClockFrequency()); + this->AddSiteProperties(xml); +} + //---------------------------------------------------------------------- void cmCTest::AddSiteProperties(std::ostream& ostr) { @@ -1594,6 +1656,54 @@ void cmCTest::AddSiteProperties(std::ostream& ostr) } } +//---------------------------------------------------------------------- +void cmCTest::AddSiteProperties(cmXMLWriter& xml) +{ + cmCTestScriptHandler* ch = + static_cast(this->GetHandler("script")); + cmake* cm = ch->GetCMake(); + // if no CMake then this is the old style script and props like + // this will not work anyway. + if(!cm) + { + return; + } + // This code should go when cdash is changed to use labels only + const char* subproject = cm->GetState() + ->GetGlobalProperty("SubProject"); + if(subproject) + { + xml.StartElement("Subproject"); + xml.Attribute("name", subproject); + const char* labels = + ch->GetCMake()->GetState() + ->GetGlobalProperty("SubProjectLabels"); + if(labels) + { + xml.StartElement("Labels"); + std::string l = labels; + std::vector args; + cmSystemTools::ExpandListArgument(l, args); + for(std::vector::iterator i = args.begin(); + i != args.end(); ++i) + { + xml.Element("Label", *i); + } + xml.EndElement(); + } + xml.EndElement(); + } + + // This code should stay when cdash only does label based sub-projects + const char* label = cm->GetState()->GetGlobalProperty("Label"); + if(label) + { + xml.StartElement("Labels"); + xml.Element("Label", label); + xml.EndElement(); + } +} + //---------------------------------------------------------------------- void cmCTest::EndXML(std::ostream& ostr) @@ -1601,6 +1711,13 @@ void cmCTest::EndXML(std::ostream& ostr) ostr << "" << std::endl; } +//---------------------------------------------------------------------- +void cmCTest::EndXML(cmXMLWriter& xml) +{ + xml.EndElement(); // Site + xml.EndDocument(); +} + //---------------------------------------------------------------------- int cmCTest::GenerateCTestNotesOutput(std::ostream& os, const cmCTest::VectorOfStrings& files) diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 3f033d9e3..47c337a73 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -24,6 +24,7 @@ class cmGeneratedFileStream; class cmCTestCommand; class cmCTestScriptHandler; class cmCTestStartCommand; +class cmXMLWriter; #define cmCTestLog(ctSelf, logType, msg) \ do { \ @@ -274,9 +275,11 @@ public: //! Start CTest XML output file void StartXML(std::ostream& ostr, bool append); + void StartXML(cmXMLWriter& xml, bool append); //! End CTest XML output file void EndXML(std::ostream& ostr); + void EndXML(cmXMLWriter& xml); //! Run command specialized for make and configure. Returns process status // and retVal is return value or exception. @@ -421,6 +424,7 @@ public: void SetStreams(std::ostream* out, std::ostream* err) { this->StreamOut = out; this->StreamErr = err; } void AddSiteProperties(std::ostream& ); + void AddSiteProperties(cmXMLWriter& xml); bool GetLabelSummary() { return this->LabelSummary;} std::string GetCostDataFile();