cmCTestScriptHandler.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 "cmCTestGenericHandler.h"
  7. #include "cmDuration.h"
  8. #include <chrono>
  9. #include <memory>
  10. #include <string>
  11. #include <vector>
  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() override;
  92. void Initialize() override;
  93. void CreateCMake();
  94. cmake* GetCMake() { return this->CMake; }
  95. void SetRunCurrentScript(bool value);
  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(std::string const& name,
  113. std::unique_ptr<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 ShouldRunCurrentScript;
  119. bool Backup;
  120. bool EmptyBinDir;
  121. bool EmptyBinDirOnce;
  122. std::string SourceDir;
  123. std::string BinaryDir;
  124. std::string BackupSourceDir;
  125. std::string BackupBinaryDir;
  126. std::string CTestRoot;
  127. std::string CVSCheckOut;
  128. std::string CTestCmd;
  129. std::string UpdateCmd;
  130. std::string CTestEnv;
  131. std::string InitialCache;
  132. std::string CMakeCmd;
  133. std::string CMOutFile;
  134. std::vector<std::string> ExtraUpdates;
  135. double MinimumInterval;
  136. double ContinuousDuration;
  137. // what time in seconds did this script start running
  138. std::chrono::steady_clock::time_point ScriptStartTime;
  139. cmMakefile* Makefile;
  140. cmMakefile* ParentMakefile;
  141. cmGlobalGenerator* GlobalGenerator;
  142. cmake* CMake;
  143. };
  144. #endif