cmCTestConfigureHandler.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. }
  26. //----------------------------------------------------------------------
  27. //clearly it would be nice if this were broken up into a few smaller
  28. //functions and commented...
  29. int cmCTestConfigureHandler::ProcessHandler()
  30. {
  31. cmCTestLog(m_CTest, HANDLER_OUTPUT, "Configure project" << std::endl);
  32. std::string cCommand = m_CTest->GetCTestConfiguration("ConfigureCommand");
  33. if ( cCommand.size() == 0 )
  34. {
  35. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  36. << std::endl);
  37. return -1;
  38. }
  39. std::string buildDirectory = m_CTest->GetCTestConfiguration("BuildDirectory");
  40. if ( buildDirectory.size() == 0 )
  41. {
  42. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl);
  43. return -1;
  44. }
  45. double elapsed_time_start = cmSystemTools::GetTime();
  46. std::string output;
  47. int retVal = 0;
  48. int res = 0;
  49. if ( !m_CTest->GetShowOnly() )
  50. {
  51. cmGeneratedFileStream os;
  52. if ( !m_CTest->OpenOutputFile(m_CTest->GetCurrentTag(), "Configure.xml", os, true) )
  53. {
  54. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot open configure file" << std::endl);
  55. return 1;
  56. }
  57. std::string start_time = m_CTest->CurrentTime();
  58. cmGeneratedFileStream ofs;
  59. m_CTest->OpenOutputFile("Temporary", "LastConfigure.log", ofs);
  60. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Configure with command: " << cCommand.c_str() << std::endl);
  61. res = m_CTest->RunMakeCommand(cCommand.c_str(), &output,
  62. &retVal, buildDirectory.c_str(),
  63. 0, ofs);
  64. if ( ofs )
  65. {
  66. ofs.close();
  67. }
  68. if ( os )
  69. {
  70. m_CTest->StartXML(os);
  71. os << "<Configure>\n"
  72. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  73. if ( res == cmsysProcess_State_Exited && retVal )
  74. {
  75. os << retVal;
  76. }
  77. os << "<ConfigureCommand>" << cCommand.c_str() << "</ConfigureCommand>" << std::endl;
  78. cmCTestLog(m_CTest, DEBUG, "End" << std::endl);
  79. os << "<Log>" << cmCTest::MakeXMLSafe(output) << "</Log>" << std::endl;
  80. std::string end_time = m_CTest->CurrentTime();
  81. os << "\t<ConfigureStatus>" << retVal << "</ConfigureStatus>\n"
  82. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  83. << "<ElapsedMinutes>"
  84. << static_cast<int>(
  85. (cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  86. << "</ElapsedMinutes>"
  87. << "</Configure>" << std::endl;
  88. m_CTest->EndXML(os);
  89. }
  90. }
  91. else
  92. {
  93. cmCTestLog(m_CTest, DEBUG, "Configure with command: " << cCommand << std::endl);
  94. }
  95. if (! res || retVal )
  96. {
  97. cmCTestLog(m_CTest, ERROR_MESSAGE, "Error(s) when updating the project" << std::endl);
  98. return -1;
  99. }
  100. return 0;
  101. }