cmCTestScriptHandler.h 4.6 KB

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