cmCTestConfigureHandler.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCTestConfigureHandler.h"
  4. #include "cmCTest.h"
  5. #include "cmGeneratedFileStream.h"
  6. #include "cmSystemTools.h"
  7. #include "cmXMLWriter.h"
  8. #include <ostream>
  9. #include <string>
  10. cmCTestConfigureHandler::cmCTestConfigureHandler()
  11. {
  12. }
  13. void cmCTestConfigureHandler::Initialize()
  14. {
  15. this->Superclass::Initialize();
  16. }
  17. // clearly it would be nice if this were broken up into a few smaller
  18. // functions and commented...
  19. int cmCTestConfigureHandler::ProcessHandler()
  20. {
  21. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  22. "Configure project" << std::endl, this->Quiet);
  23. std::string cCommand =
  24. this->CTest->GetCTestConfiguration("ConfigureCommand");
  25. if (cCommand.empty()) {
  26. cmCTestLog(this->CTest, ERROR_MESSAGE,
  27. "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  28. << std::endl);
  29. return -1;
  30. }
  31. std::string buildDirectory =
  32. this->CTest->GetCTestConfiguration("BuildDirectory");
  33. if (buildDirectory.empty()) {
  34. cmCTestLog(this->CTest, ERROR_MESSAGE,
  35. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  36. << std::endl);
  37. return -1;
  38. }
  39. double elapsed_time_start = cmSystemTools::GetTime();
  40. std::string output;
  41. int retVal = 0;
  42. int res = 0;
  43. if (!this->CTest->GetShowOnly()) {
  44. cmGeneratedFileStream os;
  45. if (!this->StartResultingXML(cmCTest::PartConfigure, "Configure", os)) {
  46. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open configure file"
  47. << std::endl);
  48. return 1;
  49. }
  50. std::string start_time = this->CTest->CurrentTime();
  51. unsigned int start_time_time =
  52. static_cast<unsigned int>(cmSystemTools::GetTime());
  53. cmGeneratedFileStream ofs;
  54. this->StartLogFile("Configure", ofs);
  55. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  56. "Configure with command: " << cCommand << std::endl,
  57. this->Quiet);
  58. res = this->CTest->RunMakeCommand(cCommand.c_str(), output, &retVal,
  59. buildDirectory.c_str(), 0, ofs);
  60. if (ofs) {
  61. ofs.close();
  62. }
  63. if (os) {
  64. cmXMLWriter xml(os);
  65. this->CTest->StartXML(xml, this->AppendXML);
  66. this->CTest->GenerateSubprojectsOutput(xml);
  67. xml.StartElement("Configure");
  68. xml.Element("StartDateTime", start_time);
  69. xml.Element("StartConfigureTime", start_time_time);
  70. xml.Element("ConfigureCommand", cCommand);
  71. cmCTestOptionalLog(this->CTest, DEBUG, "End" << std::endl, this->Quiet);
  72. xml.Element("Log", output);
  73. xml.Element("ConfigureStatus", retVal);
  74. xml.Element("EndDateTime", this->CTest->CurrentTime());
  75. xml.Element("EndConfigureTime",
  76. static_cast<unsigned int>(cmSystemTools::GetTime()));
  77. xml.Element(
  78. "ElapsedMinutes",
  79. static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start) / 6) /
  80. 10.0);
  81. xml.EndElement(); // Configure
  82. this->CTest->EndXML(xml);
  83. }
  84. } else {
  85. cmCTestOptionalLog(this->CTest, DEBUG,
  86. "Configure with command: " << cCommand << std::endl,
  87. this->Quiet);
  88. }
  89. if (!res || retVal) {
  90. cmCTestLog(this->CTest, ERROR_MESSAGE,
  91. "Error(s) when configuring the project" << std::endl);
  92. return -1;
  93. }
  94. return 0;
  95. }