cmCTestScriptHandler.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "cmCTestGenericHandler.h"
  10. #include "cmDuration.h"
  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. class cmCTestScriptHandler : public cmCTestGenericHandler
  20. {
  21. public:
  22. using Superclass = cmCTestGenericHandler;
  23. /**
  24. * Add a script to run, and if is should run in the current process
  25. */
  26. void AddConfigurationScript(const std::string&, bool pscope);
  27. /**
  28. * Run a dashboard using a specified confiuration script
  29. */
  30. int ProcessHandler() override;
  31. /*
  32. * Run a script
  33. */
  34. static bool RunScript(cmCTest* ctest, cmMakefile* mf,
  35. const std::string& script, bool InProcess,
  36. int* returnValue);
  37. /*
  38. * Some elapsed time handling functions
  39. */
  40. void UpdateElapsedTime();
  41. /**
  42. * Return the time remaianing that the script is allowed to run in
  43. * seconds if the user has set the variable CTEST_TIME_LIMIT. If that has
  44. * not been set it returns a very large value.
  45. */
  46. cmDuration GetRemainingTimeAllowed();
  47. cmCTestScriptHandler();
  48. cmCTestScriptHandler(const cmCTestScriptHandler&) = delete;
  49. const cmCTestScriptHandler& operator=(const cmCTestScriptHandler&) = delete;
  50. ~cmCTestScriptHandler() override;
  51. void Initialize(cmCTest* ctest) override;
  52. void CreateCMake();
  53. cmake* GetCMake() { return this->CMake.get(); }
  54. cmMakefile* GetMakefile() { return this->Makefile.get(); }
  55. private:
  56. // reads in a script
  57. int ReadInScript(const std::string& total_script_arg);
  58. int ExecuteScript(const std::string& total_script_arg);
  59. int RunConfigurationScript(const std::string& script, bool pscope);
  60. // Add ctest command
  61. void AddCTestCommand(std::string const& name,
  62. std::unique_ptr<cmCTestCommand> command);
  63. std::vector<std::string> ConfigurationScripts;
  64. std::vector<bool> ScriptProcessScope;
  65. // what time in seconds did this script start running
  66. std::chrono::steady_clock::time_point ScriptStartTime =
  67. std::chrono::steady_clock::time_point();
  68. std::unique_ptr<cmMakefile> Makefile;
  69. cmMakefile* ParentMakefile = nullptr;
  70. std::unique_ptr<cmGlobalGenerator> GlobalGenerator;
  71. std::unique_ptr<cmake> CMake;
  72. };