cmCTestScriptHandler.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc.
  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. #ifndef cmCTestScriptHandler_h
  11. #define cmCTestScriptHandler_h
  12. #include "cmCTestGenericHandler.h"
  13. #include "cmListFileCache.h"
  14. class cmMakefile;
  15. class cmGlobalGenerator;
  16. class cmake;
  17. class cmCTestCommand;
  18. /** \class cmCTestScriptHandler
  19. * \brief A class that handles ctest -S invocations
  20. *
  21. * CTest script is controlled using several variables that script has to
  22. * specify and some optional ones. Required ones are:
  23. * CTEST_SOURCE_DIRECTORY - Source directory of the project
  24. * CTEST_BINARY_DIRECTORY - Binary directory of the project
  25. * CTEST_COMMAND - Testing commands
  26. *
  27. * Optional variables are:
  28. * CTEST_BACKUP_AND_RESTORE
  29. * CTEST_CMAKE_COMMAND
  30. * CTEST_CMAKE_OUTPUT_FILE_NAME
  31. * CTEST_CONTINUOUS_DURATION
  32. * CTEST_CONTINUOUS_MINIMUM_INTERVAL
  33. * CTEST_CVS_CHECKOUT
  34. * CTEST_CVS_COMMAND
  35. * CTEST_UPDATE_COMMAND
  36. * CTEST_DASHBOARD_ROOT
  37. * CTEST_ENVIRONMENT
  38. * CTEST_INITIAL_CACHE
  39. * CTEST_START_WITH_EMPTY_BINARY_DIRECTORY
  40. * CTEST_START_WITH_EMPTY_BINARY_DIRECTORY_ONCE
  41. *
  42. * In addition the following variables can be used. The number can be 1-10.
  43. * CTEST_EXTRA_UPDATES_1
  44. * CTEST_EXTRA_UPDATES_2
  45. * ...
  46. * CTEST_EXTRA_UPDATES_10
  47. *
  48. * CTest script can use the following arguments CTest provides:
  49. * CTEST_SCRIPT_ARG
  50. * CTEST_SCRIPT_DIRECTORY
  51. * CTEST_SCRIPT_NAME
  52. *
  53. */
  54. class cmCTestScriptHandler : public cmCTestGenericHandler
  55. {
  56. public:
  57. cmTypeMacro(cmCTestScriptHandler, cmCTestGenericHandler);
  58. /**
  59. * Add a script to run, and if is should run in the current process
  60. */
  61. void AddConfigurationScript(const char *, bool pscope);
  62. /**
  63. * Run a dashboard using a specified confiuration script
  64. */
  65. int ProcessHandler();
  66. /*
  67. * Run a script
  68. */
  69. static bool RunScript(cmCTest* ctest, const char *script, bool InProcess,
  70. int* returnValue);
  71. int RunCurrentScript();
  72. /*
  73. * Empty Binary Directory
  74. */
  75. static bool EmptyBinaryDirectory(const char *dir);
  76. /*
  77. * Write an initial CMakeCache.txt from the given contents.
  78. */
  79. static bool WriteInitialCache(const char* directory, const char* text);
  80. /*
  81. * Some elapsed time handling functions
  82. */
  83. static void SleepInSeconds(unsigned int secondsToWait);
  84. void UpdateElapsedTime();
  85. /**
  86. * Return the time remaianing that the script is allowed to run in
  87. * seconds if the user has set the variable CTEST_TIME_LIMIT. If that has
  88. * not been set it returns 1e7 seconds
  89. */
  90. double GetRemainingTimeAllowed();
  91. cmCTestScriptHandler();
  92. ~cmCTestScriptHandler();
  93. void Initialize();
  94. void CreateCMake();
  95. cmake* GetCMake() { return this->CMake;}
  96. private:
  97. // reads in a script
  98. int ReadInScript(const std::string& total_script_arg);
  99. int ExecuteScript(const std::string& total_script_arg);
  100. // extract vars from the script to set ivars
  101. int ExtractVariables();
  102. // perform a CVS checkout of the source dir
  103. int CheckOutSourceDir();
  104. // perform any extra cvs updates that were requested
  105. int PerformExtraUpdates();
  106. // backup and restore dirs
  107. int BackupDirectories();
  108. void RestoreBackupDirectories();
  109. int RunConfigurationScript(const std::string& script, bool pscope);
  110. int RunConfigurationDashboard();
  111. // Add ctest command
  112. void AddCTestCommand(cmCTestCommand* command);
  113. // Try to remove the binary directory once
  114. static bool TryToRemoveBinaryDirectoryOnce(const std::string& directoryPath);
  115. std::vector<std::string> ConfigurationScripts;
  116. std::vector<bool> ScriptProcessScope;
  117. bool Backup;
  118. bool EmptyBinDir;
  119. bool EmptyBinDirOnce;
  120. std::string SourceDir;
  121. std::string BinaryDir;
  122. std::string BackupSourceDir;
  123. std::string BackupBinaryDir;
  124. std::string CTestRoot;
  125. std::string CVSCheckOut;
  126. std::string CTestCmd;
  127. std::string UpdateCmd;
  128. std::string CTestEnv;
  129. std::string InitialCache;
  130. std::string CMakeCmd;
  131. std::string CMOutFile;
  132. std::vector<std::string> ExtraUpdates;
  133. double MinimumInterval;
  134. double ContinuousDuration;
  135. // what time in seconds did this script start running
  136. double ScriptStartTime;
  137. cmMakefile *Makefile;
  138. cmGlobalGenerator *GlobalGenerator;
  139. cmake *CMake;
  140. };
  141. #endif