cmCTestConfigureHandler.cxx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 "cmXMLSafe.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. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Configure project" << std::endl);
  31. std::string cCommand
  32. = this->CTest->GetCTestConfiguration("ConfigureCommand");
  33. if (cCommand.empty())
  34. {
  35. cmCTestLog(this->CTest, ERROR_MESSAGE,
  36. "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  37. << std::endl);
  38. return -1;
  39. }
  40. std::string buildDirectory
  41. = this->CTest->GetCTestConfiguration("BuildDirectory");
  42. if (buildDirectory.empty())
  43. {
  44. cmCTestLog(this->CTest, ERROR_MESSAGE,
  45. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  46. << std::endl);
  47. return -1;
  48. }
  49. double elapsed_time_start = cmSystemTools::GetTime();
  50. std::string output;
  51. int retVal = 0;
  52. int res = 0;
  53. if ( !this->CTest->GetShowOnly() )
  54. {
  55. cmGeneratedFileStream os;
  56. if(!this->StartResultingXML(cmCTest::PartConfigure, "Configure", os))
  57. {
  58. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open configure file"
  59. << std::endl);
  60. return 1;
  61. }
  62. std::string start_time = this->CTest->CurrentTime();
  63. unsigned int start_time_time = static_cast<unsigned int>(
  64. cmSystemTools::GetTime());
  65. cmGeneratedFileStream ofs;
  66. this->StartLogFile("Configure", ofs);
  67. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Configure with command: "
  68. << cCommand << std::endl);
  69. res = this->CTest->RunMakeCommand(cCommand.c_str(), output,
  70. &retVal, buildDirectory.c_str(),
  71. 0, ofs);
  72. if ( ofs )
  73. {
  74. ofs.close();
  75. }
  76. if ( os )
  77. {
  78. this->CTest->StartXML(os, this->AppendXML);
  79. os << "<Configure>\n"
  80. << "\t<StartDateTime>" << start_time << "</StartDateTime>"
  81. << std::endl
  82. << "\t<StartConfigureTime>" << start_time_time
  83. << "</StartConfigureTime>\n";
  84. if ( res == cmsysProcess_State_Exited && retVal )
  85. {
  86. os << retVal;
  87. }
  88. os << "<ConfigureCommand>" << cCommand << "</ConfigureCommand>"
  89. << std::endl;
  90. cmCTestLog(this->CTest, DEBUG, "End" << std::endl);
  91. os << "<Log>" << cmXMLSafe(output) << "</Log>" << std::endl;
  92. std::string end_time = this->CTest->CurrentTime();
  93. os << "\t<ConfigureStatus>" << retVal << "</ConfigureStatus>\n"
  94. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  95. << "\t<EndConfigureTime>" <<
  96. static_cast<unsigned int>(cmSystemTools::GetTime())
  97. << "</EndConfigureTime>\n"
  98. << "<ElapsedMinutes>"
  99. << static_cast<int>(
  100. (cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  101. << "</ElapsedMinutes>"
  102. << "</Configure>" << std::endl;
  103. this->CTest->EndXML(os);
  104. }
  105. }
  106. else
  107. {
  108. cmCTestLog(this->CTest, DEBUG, "Configure with command: " << cCommand
  109. << std::endl);
  110. }
  111. if (! res || retVal )
  112. {
  113. cmCTestLog(this->CTest, ERROR_MESSAGE,
  114. "Error(s) when configuring the project" << std::endl);
  115. return -1;
  116. }
  117. return 0;
  118. }