cmCTestConfigureHandler.cxx 3.5 KB

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