cmCTestConfigureHandler.cxx 3.5 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 "cmDuration.h"
  6. #include "cmGeneratedFileStream.h"
  7. #include "cmXMLWriter.h"
  8. #include <chrono>
  9. #include <ostream>
  10. #include <string>
  11. cmCTestConfigureHandler::cmCTestConfigureHandler()
  12. {
  13. }
  14. void cmCTestConfigureHandler::Initialize()
  15. {
  16. this->Superclass::Initialize();
  17. }
  18. // clearly it would be nice if this were broken up into a few smaller
  19. // functions and commented...
  20. int cmCTestConfigureHandler::ProcessHandler()
  21. {
  22. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  23. "Configure project" << std::endl, this->Quiet);
  24. std::string cCommand =
  25. this->CTest->GetCTestConfiguration("ConfigureCommand");
  26. if (cCommand.empty()) {
  27. cmCTestLog(this->CTest, ERROR_MESSAGE,
  28. "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  29. << std::endl);
  30. return -1;
  31. }
  32. std::string buildDirectory =
  33. this->CTest->GetCTestConfiguration("BuildDirectory");
  34. if (buildDirectory.empty()) {
  35. cmCTestLog(this->CTest, ERROR_MESSAGE,
  36. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  37. << std::endl);
  38. return -1;
  39. }
  40. auto elapsed_time_start = std::chrono::steady_clock::now();
  41. std::string output;
  42. int retVal = 0;
  43. int res = 0;
  44. if (!this->CTest->GetShowOnly()) {
  45. cmGeneratedFileStream os;
  46. if (!this->StartResultingXML(cmCTest::PartConfigure, "Configure", os)) {
  47. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open configure file"
  48. << std::endl);
  49. return 1;
  50. }
  51. std::string start_time = this->CTest->CurrentTime();
  52. auto start_time_time = std::chrono::system_clock::now();
  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(),
  60. cmDuration::zero(), ofs);
  61. if (ofs) {
  62. ofs.close();
  63. }
  64. if (os) {
  65. cmXMLWriter xml(os);
  66. this->CTest->StartXML(xml, this->AppendXML);
  67. this->CTest->GenerateSubprojectsOutput(xml);
  68. xml.StartElement("Configure");
  69. xml.Element("StartDateTime", start_time);
  70. xml.Element("StartConfigureTime", start_time_time);
  71. xml.Element("ConfigureCommand", cCommand);
  72. cmCTestOptionalLog(this->CTest, DEBUG, "End" << std::endl, this->Quiet);
  73. xml.Element("Log", output);
  74. xml.Element("ConfigureStatus", retVal);
  75. xml.Element("EndDateTime", this->CTest->CurrentTime());
  76. xml.Element("EndConfigureTime", std::chrono::system_clock::now());
  77. xml.Element("ElapsedMinutes",
  78. std::chrono::duration_cast<std::chrono::minutes>(
  79. std::chrono::steady_clock::now() - elapsed_time_start)
  80. .count());
  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. }