cmCTestScriptHandler.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmCTestScriptHandler_h
  4. #define cmCTestScriptHandler_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <chrono>
  7. #include <memory>
  8. #include <string>
  9. #include <vector>
  10. #include "cmCTestGenericHandler.h"
  11. #include "cmDuration.h"
  12. class cmCTest;
  13. class cmCTestCommand;
  14. class cmGlobalGenerator;
  15. class cmMakefile;
  16. class cmake;
  17. /** \class cmCTestScriptHandler
  18. * \brief A class that handles ctest -S invocations
  19. *
  20. * CTest script is controlled using several variables that script has to
  21. * specify and some optional ones. Required ones are:
  22. * CTEST_SOURCE_DIRECTORY - Source directory of the project
  23. * CTEST_BINARY_DIRECTORY - Binary directory of the project
  24. * CTEST_COMMAND - Testing commands
  25. *
  26. * Optional variables are:
  27. * CTEST_BACKUP_AND_RESTORE
  28. * CTEST_CMAKE_COMMAND
  29. * CTEST_CMAKE_OUTPUT_FILE_NAME
  30. * CTEST_CONTINUOUS_DURATION
  31. * CTEST_CONTINUOUS_MINIMUM_INTERVAL
  32. * CTEST_CVS_CHECKOUT
  33. * CTEST_CVS_COMMAND
  34. * CTEST_UPDATE_COMMAND
  35. * CTEST_DASHBOARD_ROOT
  36. * CTEST_ENVIRONMENT
  37. * CTEST_INITIAL_CACHE
  38. * CTEST_START_WITH_EMPTY_BINARY_DIRECTORY
  39. * CTEST_START_WITH_EMPTY_BINARY_DIRECTORY_ONCE
  40. *
  41. * In addition the following variables can be used. The number can be 1-10.
  42. * CTEST_EXTRA_UPDATES_1
  43. * CTEST_EXTRA_UPDATES_2
  44. * ...
  45. * CTEST_EXTRA_UPDATES_10
  46. *
  47. * CTest script can use the following arguments CTest provides:
  48. * CTEST_SCRIPT_ARG
  49. * CTEST_SCRIPT_DIRECTORY
  50. * CTEST_SCRIPT_NAME
  51. *
  52. */
  53. class cmCTestScriptHandler : public cmCTestGenericHandler
  54. {
  55. public:
  56. using Superclass = cmCTestGenericHandler;
  57. /**
  58. * Add a script to run, and if is should run in the current process
  59. */
  60. void AddConfigurationScript(const char*, bool pscope);
  61. /**
  62. * Run a dashboard using a specified confiuration script
  63. */
  64. int ProcessHandler() override;
  65. /*
  66. * Run a script
  67. */
  68. static bool RunScript(cmCTest* ctest, cmMakefile* mf, const char* script,
  69. bool InProcess, int* returnValue);
  70. int RunCurrentScript();
  71. /*
  72. * Empty Binary Directory
  73. */
  74. static bool EmptyBinaryDirectory(const char* dir);
  75. /*
  76. * Write an initial CMakeCache.txt from the given contents.
  77. */
  78. static bool WriteInitialCache(const char* directory, const char* text);
  79. /*
  80. * Some elapsed time handling functions
  81. */
  82. static void SleepInSeconds(unsigned int secondsToWait);
  83. void UpdateElapsedTime();
  84. /**
  85. * Return the time remaianing that the script is allowed to run in
  86. * seconds if the user has set the variable CTEST_TIME_LIMIT. If that has
  87. * not been set it returns a very large value.
  88. */
  89. cmDuration GetRemainingTimeAllowed();
  90. cmCTestScriptHandler();
  91. cmCTestScriptHandler(const cmCTestScriptHandler&) = delete;
  92. const cmCTestScriptHandler& operator=(const cmCTestScriptHandler&) = delete;
  93. ~cmCTestScriptHandler() override;
  94. void Initialize() override;
  95. void CreateCMake();
  96. cmake* GetCMake() { return this->CMake.get(); }
  97. void SetRunCurrentScript(bool value);
  98. private:
  99. // reads in a script
  100. int ReadInScript(const std::string& total_script_arg);
  101. int ExecuteScript(const std::string& total_script_arg);
  102. // extract vars from the script to set ivars
  103. int ExtractVariables();
  104. // perform a CVS checkout of the source dir
  105. int CheckOutSourceDir();
  106. // perform any extra cvs updates that were requested
  107. int PerformExtraUpdates();
  108. // backup and restore dirs
  109. int BackupDirectories();
  110. void RestoreBackupDirectories();
  111. int RunConfigurationScript(const std::string& script, bool pscope);
  112. int RunConfigurationDashboard();
  113. // Add ctest command
  114. void AddCTestCommand(std::string const& name,
  115. std::unique_ptr<cmCTestCommand> command);
  116. // Try to remove the binary directory once
  117. static bool TryToRemoveBinaryDirectoryOnce(const std::string& directoryPath);
  118. std::vector<std::string> ConfigurationScripts;
  119. std::vector<bool> ScriptProcessScope;
  120. bool ShouldRunCurrentScript;
  121. bool Backup = false;
  122. bool EmptyBinDir = false;
  123. bool EmptyBinDirOnce = false;
  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. // the *60 is because the settings are in minutes but GetTime is seconds
  138. double MinimumInterval = 30 * 60;
  139. double ContinuousDuration = -1;
  140. // what time in seconds did this script start running
  141. std::chrono::steady_clock::time_point ScriptStartTime =
  142. std::chrono::steady_clock::time_point();
  143. std::unique_ptr<cmMakefile> Makefile;
  144. cmMakefile* ParentMakefile = nullptr;
  145. std::unique_ptr<cmGlobalGenerator> GlobalGenerator;
  146. std::unique_ptr<cmake> CMake;
  147. };
  148. #endif