cmCTestScriptHandler.h 4.5 KB

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