cmFileAPIConfigureLog.cxx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmFileAPIConfigureLog.h"
  4. #include <cm3p/json/value.h>
  5. #include "cmFileAPI.h"
  6. #include "cmStringAlgorithms.h"
  7. #include "cmake.h"
  8. namespace {
  9. class ConfigureLog
  10. {
  11. cmFileAPI& FileAPI;
  12. unsigned long Version;
  13. Json::Value DumpPath();
  14. Json::Value DumpEventKindNames();
  15. public:
  16. ConfigureLog(cmFileAPI& fileAPI, unsigned long version);
  17. Json::Value Dump();
  18. };
  19. ConfigureLog::ConfigureLog(cmFileAPI& fileAPI, unsigned long version)
  20. : FileAPI(fileAPI)
  21. , Version(version)
  22. {
  23. static_cast<void>(this->Version);
  24. }
  25. Json::Value ConfigureLog::Dump()
  26. {
  27. Json::Value configureLog = Json::objectValue;
  28. configureLog["path"] = this->DumpPath();
  29. configureLog["eventKindNames"] = this->DumpEventKindNames();
  30. return configureLog;
  31. }
  32. Json::Value ConfigureLog::DumpPath()
  33. {
  34. return cmStrCat(this->FileAPI.GetCMakeInstance()->GetHomeOutputDirectory(),
  35. "/CMakeFiles/CMakeConfigureLog.yaml");
  36. }
  37. Json::Value ConfigureLog::DumpEventKindNames()
  38. {
  39. // Report at most one version of each event kind.
  40. // If a new event kind is added, increment ConfigureLogV1Minor.
  41. // If a new version of an existing event kind is added, a new
  42. // major version of the configureLog object kind is needed.
  43. Json::Value eventKindNames = Json::arrayValue;
  44. if (this->Version == 1) {
  45. eventKindNames.append("message-v1"); // WriteMessageEvent
  46. eventKindNames.append("try_compile-v1"); // WriteTryCompileEvent
  47. eventKindNames.append("try_run-v1"); // WriteTryRunEvent
  48. eventKindNames.append("find-v1"); // WriteFindBaseEvent
  49. }
  50. return eventKindNames;
  51. }
  52. }
  53. Json::Value cmFileAPIConfigureLogDump(cmFileAPI& fileAPI,
  54. unsigned long version)
  55. {
  56. ConfigureLog configureLog(fileAPI, version);
  57. return configureLog.Dump();
  58. }