cmCTestConfigureHandler.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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() = default;
  12. void cmCTestConfigureHandler::Initialize()
  13. {
  14. this->Superclass::Initialize();
  15. }
  16. // clearly it would be nice if this were broken up into a few smaller
  17. // functions and commented...
  18. int cmCTestConfigureHandler::ProcessHandler()
  19. {
  20. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  21. "Configure project" << std::endl, this->Quiet);
  22. std::string cCommand =
  23. this->CTest->GetCTestConfiguration("ConfigureCommand");
  24. if (cCommand.empty()) {
  25. cmCTestLog(this->CTest, ERROR_MESSAGE,
  26. "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  27. << std::endl);
  28. return -1;
  29. }
  30. std::string buildDirectory =
  31. this->CTest->GetCTestConfiguration("BuildDirectory");
  32. if (buildDirectory.empty()) {
  33. cmCTestLog(this->CTest, ERROR_MESSAGE,
  34. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  35. << std::endl);
  36. return -1;
  37. }
  38. auto elapsed_time_start = std::chrono::steady_clock::now();
  39. std::string output;
  40. int retVal = 0;
  41. int res = 0;
  42. if (!this->CTest->GetShowOnly()) {
  43. cmGeneratedFileStream os;
  44. if (!this->StartResultingXML(cmCTest::PartConfigure, "Configure", os)) {
  45. cmCTestLog(this->CTest, ERROR_MESSAGE,
  46. "Cannot open configure file" << std::endl);
  47. return 1;
  48. }
  49. std::string start_time = this->CTest->CurrentTime();
  50. auto start_time_time = std::chrono::system_clock::now();
  51. cmGeneratedFileStream ofs;
  52. this->StartLogFile("Configure", ofs);
  53. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  54. "Configure with command: " << cCommand << std::endl,
  55. this->Quiet);
  56. res = this->CTest->RunMakeCommand(cCommand, output, &retVal,
  57. buildDirectory.c_str(),
  58. cmDuration::zero(), ofs);
  59. if (ofs) {
  60. ofs.close();
  61. }
  62. if (os) {
  63. cmXMLWriter xml(os);
  64. this->CTest->StartXML(xml, this->AppendXML);
  65. this->CTest->GenerateSubprojectsOutput(xml);
  66. xml.StartElement("Configure");
  67. xml.Element("StartDateTime", start_time);
  68. xml.Element("StartConfigureTime", start_time_time);
  69. xml.Element("ConfigureCommand", cCommand);
  70. cmCTestOptionalLog(this->CTest, DEBUG, "End" << std::endl, this->Quiet);
  71. xml.Element("Log", output);
  72. xml.Element("ConfigureStatus", retVal);
  73. xml.Element("EndDateTime", this->CTest->CurrentTime());
  74. xml.Element("EndConfigureTime", std::chrono::system_clock::now());
  75. xml.Element("ElapsedMinutes",
  76. std::chrono::duration_cast<std::chrono::minutes>(
  77. std::chrono::steady_clock::now() - elapsed_time_start)
  78. .count());
  79. xml.EndElement(); // Configure
  80. this->CTest->EndXML(xml);
  81. }
  82. } else {
  83. cmCTestOptionalLog(this->CTest, DEBUG,
  84. "Configure with command: " << cCommand << std::endl,
  85. this->Quiet);
  86. }
  87. if (!res || retVal) {
  88. cmCTestLog(this->CTest, ERROR_MESSAGE,
  89. "Error(s) when configuring the project" << std::endl);
  90. return -1;
  91. }
  92. return 0;
  93. }