cmCTestScriptHandler.h 4.3 KB

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