cmCTestConfigureHandler.cxx 3.8 KB

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