CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmConfigureLog.h
blob7edc3ed657266fd7acfa552cce5dc74e193af1b9
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
5 #include <map>
6 #include <memory>
7 #include <string>
8 #include <vector>
10 #include <cm/string_view>
12 #include "cmsys/FStream.hxx"
14 namespace Json {
15 class StreamWriter;
18 class cmMakefile;
20 class cmConfigureLog
22 public:
23 /** Construct with the log directory and a sorted list of enabled log
24 versions. The latest log version will be enabled regardless. */
25 cmConfigureLog(std::string logDir, std::vector<unsigned long> logVersions);
26 ~cmConfigureLog();
28 /** Return true if at least one of the log versions in the given sorted
29 list is enabled. */
30 bool IsAnyLogVersionEnabled(std::vector<unsigned long> const& v) const;
32 void EnsureInit();
34 void BeginEvent(std::string const& kind, cmMakefile const& mf);
35 void EndEvent();
37 void BeginObject(cm::string_view key);
38 void EndObject();
40 // TODO other value types
41 void WriteValue(cm::string_view key, std::nullptr_t);
42 void WriteValue(cm::string_view key, bool value);
43 void WriteValue(cm::string_view key, int value);
44 void WriteValue(cm::string_view key, std::string const& value);
45 void WriteValue(cm::string_view key, std::vector<std::string> const& list);
46 void WriteValue(cm::string_view key,
47 std::map<std::string, std::string> const& map);
49 void WriteTextBlock(cm::string_view key, cm::string_view text);
50 void WriteLiteralTextBlock(cm::string_view key, cm::string_view text);
52 void WriteLiteralTextBlock(cm::string_view key, std::string const& text)
54 this->WriteLiteralTextBlock(key, cm::string_view{ text });
57 private:
58 std::string LogDir;
59 std::vector<unsigned long> LogVersions;
60 cmsys::ofstream Stream;
61 unsigned Indent = 0;
62 bool Opened = false;
64 std::unique_ptr<Json::StreamWriter> Encoder;
66 void WriteBacktrace(cmMakefile const& mf);
67 void WriteChecks(cmMakefile const& mf);
69 cmsys::ofstream& BeginLine();
70 void EndLine();
71 void WriteEscape(unsigned char c);