cmCTestScriptHandler.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <chrono>
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "cmsys/Status.hxx"
  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 std::string&, bool pscope);
  61. /**
  62. * Run a dashboard using a specified configuration script
  63. */
  64. int ProcessHandler() override;
  65. /*
  66. * Run a script
  67. */
  68. static bool RunScript(cmCTest* ctest, cmMakefile* mf,
  69. const std::string& script, bool InProcess,
  70. int* returnValue);
  71. int RunCurrentScript();
  72. /*
  73. * Empty Binary Directory
  74. */
  75. static bool EmptyBinaryDirectory(const std::string& dir, std::string& err);
  76. /*
  77. * Write an initial CMakeCache.txt from the given contents.
  78. */
  79. static bool WriteInitialCache(const std::string& directory,
  80. const std::string& 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 a very large value.
  90. */
  91. cmDuration GetRemainingTimeAllowed();
  92. cmCTestScriptHandler();
  93. cmCTestScriptHandler(const cmCTestScriptHandler&) = delete;
  94. const cmCTestScriptHandler& operator=(const cmCTestScriptHandler&) = delete;
  95. ~cmCTestScriptHandler() override;
  96. void Initialize() override;
  97. void CreateCMake();
  98. cmake* GetCMake() { return this->CMake.get(); }
  99. void SetRunCurrentScript(bool value);
  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(std::string const& name,
  117. std::unique_ptr<cmCTestCommand> command);
  118. // Try to remove the binary directory once
  119. static cmsys::Status TryToRemoveBinaryDirectoryOnce(
  120. const std::string& directoryPath);
  121. std::vector<std::string> ConfigurationScripts;
  122. std::vector<bool> ScriptProcessScope;
  123. bool ShouldRunCurrentScript;
  124. bool Backup = false;
  125. bool EmptyBinDir = false;
  126. bool EmptyBinDirOnce = false;
  127. std::string SourceDir;
  128. std::string BinaryDir;
  129. std::string BackupSourceDir;
  130. std::string BackupBinaryDir;
  131. std::string CTestRoot;
  132. std::string CVSCheckOut;
  133. std::string CTestCmd;
  134. std::string UpdateCmd;
  135. std::string CTestEnv;
  136. std::string InitialCache;
  137. std::string CMakeCmd;
  138. std::string CMOutFile;
  139. std::vector<std::string> ExtraUpdates;
  140. // the *60 is because the settings are in minutes but GetTime is seconds
  141. double MinimumInterval = 30 * 60;
  142. double ContinuousDuration = -1;
  143. // what time in seconds did this script start running
  144. std::chrono::steady_clock::time_point ScriptStartTime =
  145. std::chrono::steady_clock::time_point();
  146. std::unique_ptr<cmMakefile> Makefile;
  147. cmMakefile* ParentMakefile = nullptr;
  148. std::unique_ptr<cmGlobalGenerator> GlobalGenerator;
  149. std::unique_ptr<cmake> CMake;
  150. };