cmConfigureLog.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include <cstddef>
  5. #include <map>
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include <cm/string_view>
  10. #include "cmsys/FStream.hxx"
  11. namespace Json {
  12. class StreamWriter;
  13. }
  14. class cmMakefile;
  15. class cmConfigureLog
  16. {
  17. public:
  18. /** Construct with the log directory and a sorted list of enabled log
  19. versions. The latest log version will be enabled regardless. */
  20. cmConfigureLog(std::string logDir, std::vector<unsigned int> logVersions);
  21. ~cmConfigureLog();
  22. /** Return true if at least one of the log versions in the given sorted
  23. list is enabled. */
  24. bool IsAnyLogVersionEnabled(std::vector<unsigned int> const& v) const;
  25. void EnsureInit();
  26. void BeginEvent(std::string const& kind, cmMakefile const& mf);
  27. void EndEvent();
  28. void BeginArray();
  29. void NextArrayElement();
  30. void EndArray();
  31. void BeginObject(cm::string_view key);
  32. void EndObject();
  33. // TODO other value types
  34. void WriteValue(cm::string_view key, std::nullptr_t);
  35. void WriteValue(cm::string_view key, bool value);
  36. void WriteValue(cm::string_view key, int value);
  37. void WriteValue(cm::string_view key, std::string const& value);
  38. void WriteValue(cm::string_view key, std::vector<std::string> const& list);
  39. void WriteValue(cm::string_view key,
  40. std::map<std::string, std::string> const& map);
  41. void WriteTextBlock(cm::string_view key, cm::string_view text);
  42. void WriteLiteralTextBlock(cm::string_view key, cm::string_view text);
  43. void WriteLiteralTextBlock(cm::string_view key, std::string const& text)
  44. {
  45. this->WriteLiteralTextBlock(key, cm::string_view{ text });
  46. }
  47. private:
  48. std::string LogDir;
  49. std::vector<unsigned int> LogVersions;
  50. cmsys::ofstream Stream;
  51. unsigned Indent = 0;
  52. bool Opened = false;
  53. std::unique_ptr<Json::StreamWriter> Encoder;
  54. void WriteBacktrace(cmMakefile const& mf);
  55. void WriteChecks(cmMakefile const& mf);
  56. cmsys::ofstream& BeginLine();
  57. void EndLine();
  58. void WriteEscape(unsigned char c);
  59. };