cmCTestConfigureHandler.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 <cmsys/Process.h>
  18. //----------------------------------------------------------------------
  19. cmCTestConfigureHandler::cmCTestConfigureHandler()
  20. {
  21. }
  22. //----------------------------------------------------------------------
  23. void cmCTestConfigureHandler::Initialize()
  24. {
  25. this->Superclass::Initialize();
  26. }
  27. //----------------------------------------------------------------------
  28. //clearly it would be nice if this were broken up into a few smaller
  29. //functions and commented...
  30. int cmCTestConfigureHandler::ProcessHandler()
  31. {
  32. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Configure project" << std::endl);
  33. std::string cCommand
  34. = this->CTest->GetCTestConfiguration("ConfigureCommand");
  35. if ( cCommand.size() == 0 )
  36. {
  37. cmCTestLog(this->CTest, ERROR_MESSAGE,
  38. "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  39. << std::endl);
  40. return -1;
  41. }
  42. std::string buildDirectory
  43. = this->CTest->GetCTestConfiguration("BuildDirectory");
  44. if ( buildDirectory.size() == 0 )
  45. {
  46. cmCTestLog(this->CTest, ERROR_MESSAGE,
  47. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  48. << std::endl);
  49. return -1;
  50. }
  51. double elapsed_time_start = cmSystemTools::GetTime();
  52. std::string output;
  53. int retVal = 0;
  54. int res = 0;
  55. if ( !this->CTest->GetShowOnly() )
  56. {
  57. cmGeneratedFileStream os;
  58. if ( !this->StartResultingXML("Configure", os) )
  59. {
  60. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open configure file"
  61. << std::endl);
  62. return 1;
  63. }
  64. std::string start_time = this->CTest->CurrentTime();
  65. cmGeneratedFileStream ofs;
  66. this->StartLogFile("Configure", ofs);
  67. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Configure with command: "
  68. << cCommand.c_str() << 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);
  79. os << "<Configure>\n"
  80. << "\t<StartDateTime>" << start_time << "</StartDateTime>"
  81. << std::endl;
  82. if ( res == cmsysProcess_State_Exited && retVal )
  83. {
  84. os << retVal;
  85. }
  86. os << "<ConfigureCommand>" << cCommand.c_str() << "</ConfigureCommand>"
  87. << std::endl;
  88. cmCTestLog(this->CTest, DEBUG, "End" << std::endl);
  89. os << "<Log>" << cmCTest::MakeXMLSafe(output) << "</Log>" << std::endl;
  90. std::string end_time = this->CTest->CurrentTime();
  91. os << "\t<ConfigureStatus>" << retVal << "</ConfigureStatus>\n"
  92. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  93. << "<ElapsedMinutes>"
  94. << static_cast<int>(
  95. (cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  96. << "</ElapsedMinutes>"
  97. << "</Configure>" << std::endl;
  98. this->CTest->EndXML(os);
  99. }
  100. }
  101. else
  102. {
  103. cmCTestLog(this->CTest, DEBUG, "Configure with command: " << cCommand
  104. << std::endl);
  105. }
  106. if (! res || retVal )
  107. {
  108. cmCTestLog(this->CTest, ERROR_MESSAGE,
  109. "Error(s) when updating the project" << std::endl);
  110. return -1;
  111. }
  112. return 0;
  113. }