cmCTestGenericHandler.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #include "cmValue.h"
  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 SetPersistentOption(const std::string& op, const std::string& value)
  77. {
  78. this->SetPersistentOption(op, cmValue(value));
  79. }
  80. void SetPersistentOption(const std::string& op, cmValue value);
  81. void SetOption(const std::string& op, const char* value);
  82. void SetOption(const std::string& op, const std::string& value)
  83. {
  84. this->SetOption(op, cmValue(value));
  85. }
  86. void SetOption(const std::string& op, cmValue value);
  87. cmValue GetOption(const std::string& op);
  88. /**
  89. * Multi-Options collect one or more values from flags; passing
  90. * the flag multiple times on the command-line *adds* values,
  91. * rather than overwriting the previous values.
  92. *
  93. * Adding an empty value does nothing.
  94. *
  95. * The value is stored as a vector of strings. The values set for single
  96. * (see above) and multi-options live in different spaces,
  97. * so calling a multi-getter for a key that has only been set
  98. * as a single-value will return an empty vector.
  99. */
  100. void AddPersistentMultiOption(const std::string& optionName,
  101. const std::string& value);
  102. void AddMultiOption(const std::string& optionName, const std::string& value);
  103. std::vector<std::string> GetMultiOption(const std::string& op) const;
  104. void SetSubmitIndex(int idx) { this->SubmitIndex = idx; }
  105. int GetSubmitIndex() { return this->SubmitIndex; }
  106. void SetAppendXML(bool b) { this->AppendXML = b; }
  107. void SetQuiet(bool b) { this->Quiet = b; }
  108. bool GetQuiet() { return this->Quiet; }
  109. void SetTestLoad(unsigned long load) { this->TestLoad = load; }
  110. unsigned long GetTestLoad() const { return this->TestLoad; }
  111. protected:
  112. bool StartResultingXML(cmCTest::Part part, const char* name,
  113. cmGeneratedFileStream& xofs);
  114. bool StartLogFile(const char* name, cmGeneratedFileStream& xofs);
  115. bool AppendXML;
  116. bool Quiet;
  117. unsigned long TestLoad;
  118. cmSystemTools::OutputOption HandlerVerbose;
  119. cmCTest* CTest;
  120. t_StringToString Options;
  121. t_StringToString PersistentOptions;
  122. t_StringToMultiString MultiOptions;
  123. t_StringToMultiString PersistentMultiOptions;
  124. t_StringToString LogFileNames;
  125. int SubmitIndex;
  126. };