cmCTestScriptHandler.h 4.7 KB

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