cmCTestGenericHandler.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 <map>
  6. #include <string>
  7. #include <vector>
  8. #include <stddef.h>
  9. #include "cmCTest.h"
  10. #include "cmSystemTools.h"
  11. class cmCTestCommand;
  12. class cmGeneratedFileStream;
  13. class cmMakefile;
  14. /** \class cmCTestGenericHandler
  15. * \brief A superclass of all CTest Handlers
  16. *
  17. */
  18. class cmCTestGenericHandler
  19. {
  20. public:
  21. /**
  22. * If verbose then more information is printed out
  23. */
  24. void SetVerbose(bool val)
  25. {
  26. this->HandlerVerbose =
  27. val ? cmSystemTools::OUTPUT_MERGE : cmSystemTools::OUTPUT_NONE;
  28. }
  29. /**
  30. * Populate internals from CTest custom scripts
  31. */
  32. virtual void PopulateCustomVectors(cmMakefile*) {}
  33. /**
  34. * Do the actual processing. Subclass has to override it.
  35. * Return < 0 if error.
  36. */
  37. virtual int ProcessHandler() = 0;
  38. /**
  39. * Process command line arguments that are applicable for the handler
  40. */
  41. virtual int ProcessCommandLineArguments(
  42. const std::string& /*currentArg*/, size_t& /*idx*/,
  43. const std::vector<std::string>& /*allArgs*/)
  44. {
  45. return 1;
  46. }
  47. /**
  48. * Initialize handler
  49. */
  50. virtual void Initialize();
  51. /**
  52. * Set the CTest instance
  53. */
  54. void SetCTestInstance(cmCTest* ctest) { this->CTest = ctest; }
  55. cmCTest* GetCTestInstance() { return this->CTest; }
  56. /**
  57. * Construct handler
  58. */
  59. cmCTestGenericHandler();
  60. virtual ~cmCTestGenericHandler();
  61. using t_StringToString = std::map<std::string, std::string>;
  62. using t_StringToMultiString =
  63. std::map<std::string, std::vector<std::string>>;
  64. /**
  65. * Options collect a single value from flags; passing the
  66. * flag multiple times on the command-line *overwrites* values,
  67. * and only the last one specified counts. Set an option to
  68. * nullptr to "unset" it.
  69. *
  70. * The value is stored as a string. The values set for single
  71. * and multi-options (see below) live in different spaces,
  72. * so calling a single-getter for a key that has only been set
  73. * as a multi-value will return nullptr.
  74. */
  75. void SetPersistentOption(const std::string& op, const char* value);
  76. void SetOption(const std::string& op, const char* value);
  77. const char* GetOption(const std::string& op);
  78. /**
  79. * Multi-Options collect one or more values from flags; passing
  80. * the flag multiple times on the command-line *adds* values,
  81. * rather than overwriting the previous values.
  82. *
  83. * Adding an empty value does nothing.
  84. *
  85. * The value is stored as a vector of strings. The values set for single
  86. * (see above) and multi-options live in different spaces,
  87. * so calling a multi-getter for a key that has only been set
  88. * as a single-value will return an empty vector.
  89. */
  90. void AddPersistentMultiOption(const std::string& optionName,
  91. const std::string& value);
  92. void AddMultiOption(const std::string& optionName, const std::string& value);
  93. std::vector<std::string> GetMultiOption(const std::string& op) const;
  94. void SetCommand(cmCTestCommand* command) { this->Command = command; }
  95. void SetSubmitIndex(int idx) { this->SubmitIndex = idx; }
  96. int GetSubmitIndex() { return this->SubmitIndex; }
  97. void SetAppendXML(bool b) { this->AppendXML = b; }
  98. void SetQuiet(bool b) { this->Quiet = b; }
  99. bool GetQuiet() { return this->Quiet; }
  100. void SetTestLoad(unsigned long load) { this->TestLoad = load; }
  101. unsigned long GetTestLoad() const { return this->TestLoad; }
  102. protected:
  103. bool StartResultingXML(cmCTest::Part part, const char* name,
  104. cmGeneratedFileStream& xofs);
  105. bool StartLogFile(const char* name, cmGeneratedFileStream& xofs);
  106. bool AppendXML;
  107. bool Quiet;
  108. unsigned long TestLoad;
  109. cmSystemTools::OutputOption HandlerVerbose;
  110. cmCTest* CTest;
  111. t_StringToString Options;
  112. t_StringToString PersistentOptions;
  113. t_StringToMultiString MultiOptions;
  114. t_StringToMultiString PersistentMultiOptions;
  115. t_StringToString LogFileNames;
  116. cmCTestCommand* Command;
  117. int SubmitIndex;
  118. };