cmCTestConfigureHandler.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "cmXMLWriter.h"
  7. #include <chrono>
  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. auto elapsed_time_start = std::chrono::steady_clock::now();
  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. auto start_time_time = std::chrono::system_clock::now();
  52. cmGeneratedFileStream ofs;
  53. this->StartLogFile("Configure", ofs);
  54. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  55. "Configure with command: " << cCommand << std::endl,
  56. this->Quiet);
  57. res = this->CTest->RunMakeCommand(
  58. cCommand.c_str(), output, &retVal, buildDirectory.c_str(),
  59. std::chrono::duration<double>::zero(), 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", std::chrono::system_clock::now());
  76. xml.Element("ElapsedMinutes",
  77. std::chrono::duration_cast<std::chrono::minutes>(
  78. std::chrono::steady_clock::now() - elapsed_time_start)
  79. .count());
  80. xml.EndElement(); // Configure
  81. this->CTest->EndXML(xml);
  82. }
  83. } else {
  84. cmCTestOptionalLog(this->CTest, DEBUG,
  85. "Configure with command: " << cCommand << std::endl,
  86. this->Quiet);
  87. }
  88. if (!res || retVal) {
  89. cmCTestLog(this->CTest, ERROR_MESSAGE,
  90. "Error(s) when configuring the project" << std::endl);
  91. return -1;
  92. }
  93. return 0;
  94. }