cmCTestScriptHandler.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. private:
  95. // reads in a script
  96. int ReadInScript(const std::string& total_script_arg);
  97. int ExecuteScript(const std::string& total_script_arg);
  98. // extract vars from the script to set ivars
  99. int ExtractVariables();
  100. // perform a CVS checkout of the source dir
  101. int CheckOutSourceDir();
  102. // perform any extra cvs updates that were requested
  103. int PerformExtraUpdates();
  104. // backup and restore dirs
  105. int BackupDirectories();
  106. void RestoreBackupDirectories();
  107. int RunConfigurationScript(const std::string& script, bool pscope);
  108. int RunConfigurationDashboard();
  109. // Add ctest command
  110. void AddCTestCommand(std::string const& name, cmCTestCommand* command);
  111. // Try to remove the binary directory once
  112. static bool TryToRemoveBinaryDirectoryOnce(const std::string& directoryPath);
  113. std::vector<std::string> ConfigurationScripts;
  114. std::vector<bool> ScriptProcessScope;
  115. bool Backup;
  116. bool EmptyBinDir;
  117. bool EmptyBinDirOnce;
  118. std::string SourceDir;
  119. std::string BinaryDir;
  120. std::string BackupSourceDir;
  121. std::string BackupBinaryDir;
  122. std::string CTestRoot;
  123. std::string CVSCheckOut;
  124. std::string CTestCmd;
  125. std::string UpdateCmd;
  126. std::string CTestEnv;
  127. std::string InitialCache;
  128. std::string CMakeCmd;
  129. std::string CMOutFile;
  130. std::vector<std::string> ExtraUpdates;
  131. double MinimumInterval;
  132. double ContinuousDuration;
  133. // what time in seconds did this script start running
  134. std::chrono::steady_clock::time_point ScriptStartTime;
  135. cmMakefile* Makefile;
  136. cmGlobalGenerator* GlobalGenerator;
  137. cmake* CMake;
  138. };
  139. #endif