cmCTestConfigureHandler.cxx 3.8 KB

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