cmCTestConfigureHandler.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestConfigureHandler.h"
  14. #include "cmCTest.h"
  15. #include "cmGeneratedFileStream.h"
  16. #include "cmake.h"
  17. #include "cmXMLSafe.h"
  18. #include <cmsys/Process.h>
  19. //----------------------------------------------------------------------
  20. cmCTestConfigureHandler::cmCTestConfigureHandler()
  21. {
  22. }
  23. //----------------------------------------------------------------------
  24. void cmCTestConfigureHandler::Initialize()
  25. {
  26. this->Superclass::Initialize();
  27. }
  28. //----------------------------------------------------------------------
  29. //clearly it would be nice if this were broken up into a few smaller
  30. //functions and commented...
  31. int cmCTestConfigureHandler::ProcessHandler()
  32. {
  33. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Configure project" << std::endl);
  34. std::string cCommand
  35. = this->CTest->GetCTestConfiguration("ConfigureCommand");
  36. if ( cCommand.size() == 0 )
  37. {
  38. cmCTestLog(this->CTest, ERROR_MESSAGE,
  39. "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  40. << std::endl);
  41. return -1;
  42. }
  43. std::string buildDirectory
  44. = this->CTest->GetCTestConfiguration("BuildDirectory");
  45. if ( buildDirectory.size() == 0 )
  46. {
  47. cmCTestLog(this->CTest, ERROR_MESSAGE,
  48. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  49. << std::endl);
  50. return -1;
  51. }
  52. double elapsed_time_start = cmSystemTools::GetTime();
  53. std::string output;
  54. int retVal = 0;
  55. int res = 0;
  56. if ( !this->CTest->GetShowOnly() )
  57. {
  58. cmGeneratedFileStream os;
  59. if(!this->StartResultingXML(cmCTest::PartConfigure, "Configure", os))
  60. {
  61. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open configure file"
  62. << std::endl);
  63. return 1;
  64. }
  65. std::string start_time = this->CTest->CurrentTime();
  66. unsigned int start_time_time = static_cast<unsigned int>(
  67. cmSystemTools::GetTime());
  68. cmGeneratedFileStream ofs;
  69. this->StartLogFile("Configure", ofs);
  70. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Configure with command: "
  71. << cCommand.c_str() << std::endl);
  72. res = this->CTest->RunMakeCommand(cCommand.c_str(), &output,
  73. &retVal, buildDirectory.c_str(),
  74. 0, ofs);
  75. if ( ofs )
  76. {
  77. ofs.close();
  78. }
  79. if ( os )
  80. {
  81. this->CTest->StartXML(os, this->AppendXML);
  82. os << "<Configure>\n"
  83. << "\t<StartDateTime>" << start_time << "</StartDateTime>"
  84. << std::endl
  85. << "\t<StartConfigureTime>" << start_time_time
  86. << "</StartConfigureTime>\n";
  87. if ( res == cmsysProcess_State_Exited && retVal )
  88. {
  89. os << retVal;
  90. }
  91. os << "<ConfigureCommand>" << cCommand.c_str() << "</ConfigureCommand>"
  92. << std::endl;
  93. cmCTestLog(this->CTest, DEBUG, "End" << std::endl);
  94. os << "<Log>" << cmXMLSafe(output) << "</Log>" << std::endl;
  95. std::string end_time = this->CTest->CurrentTime();
  96. os << "\t<ConfigureStatus>" << retVal << "</ConfigureStatus>\n"
  97. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  98. << "\t<EndConfigureTime>" <<
  99. static_cast<unsigned int>(cmSystemTools::GetTime())
  100. << "</EndConfigureTime>\n"
  101. << "<ElapsedMinutes>"
  102. << static_cast<int>(
  103. (cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  104. << "</ElapsedMinutes>"
  105. << "</Configure>" << std::endl;
  106. this->CTest->EndXML(os);
  107. }
  108. }
  109. else
  110. {
  111. cmCTestLog(this->CTest, DEBUG, "Configure with command: " << cCommand
  112. << std::endl);
  113. }
  114. if (! res || retVal )
  115. {
  116. cmCTestLog(this->CTest, ERROR_MESSAGE,
  117. "Error(s) when configuring the project" << std::endl);
  118. return -1;
  119. }
  120. return 0;
  121. }