فهرست منبع

fileapi: Add backtraceGraph to codemodel-v2 "directory" object

Co-Authored-by: Kyle Edwards <[email protected]>
Brad King 4 سال پیش
والد
کامیت
eae2256a52
3فایلهای تغییر یافته به همراه24 افزوده شده و 5 حذف شده
  1. 8 4
      Help/manual/cmake-file-api.7.rst
  2. 13 0
      Source/cmFileAPICodemodel.cxx
  3. 3 1
      Tests/RunCMake/FileAPI/codemodel-v2-check.py

+ 8 - 4
Help/manual/cmake-file-api.7.rst

@@ -666,6 +666,10 @@ with members:
     directory (with ``.`` for the top-level build directory itself).
     directory (with ``.`` for the top-level build directory itself).
     Otherwise the path is absolute.
     Otherwise the path is absolute.
 
 
+``backtraceGraph``
+  A `"codemodel" version 2 "backtrace graph"`_ whose nodes are referenced
+  from ``backtrace`` members elsewhere in this "directory" object.
+
 "codemodel" version 2 "target" object
 "codemodel" version 2 "target" object
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 
@@ -1003,10 +1007,10 @@ with members:
 "codemodel" version 2 "backtrace graph"
 "codemodel" version 2 "backtrace graph"
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 
-The ``backtraceGraph`` member of a `"codemodel" version 2 "target" object`_
-is a JSON object describing a graph of backtraces.  Its nodes are referenced
-from ``backtrace`` members elsewhere in the containing object.
-The backtrace graph object members are:
+The ``backtraceGraph`` member of a `"codemodel" version 2 "directory" object`_,
+or `"codemodel" version 2 "target" object`_ is a JSON object describing a
+graph of backtraces.  Its nodes are referenced from ``backtrace`` members
+elsewhere in the containing object.  The backtrace graph object members are:
 
 
 ``nodes``
 ``nodes``
   A JSON array listing nodes in the backtrace graph.  Each entry
   A JSON array listing nodes in the backtrace graph.  Each entry

+ 13 - 0
Source/cmFileAPICodemodel.cxx

@@ -379,6 +379,9 @@ class DirectoryObject
   std::string const& Config;
   std::string const& Config;
   std::string TopSource;
   std::string TopSource;
   std::string TopBuild;
   std::string TopBuild;
+  BacktraceData Backtraces;
+
+  void AddBacktrace(Json::Value& object, cmListFileBacktrace const& bt);
 
 
   Json::Value DumpPaths();
   Json::Value DumpPaths();
 
 
@@ -814,6 +817,7 @@ DirectoryObject::DirectoryObject(cmLocalGenerator const* lg,
   , TopSource(lg->GetGlobalGenerator()->GetCMakeInstance()->GetHomeDirectory())
   , TopSource(lg->GetGlobalGenerator()->GetCMakeInstance()->GetHomeDirectory())
   , TopBuild(
   , TopBuild(
       lg->GetGlobalGenerator()->GetCMakeInstance()->GetHomeOutputDirectory())
       lg->GetGlobalGenerator()->GetCMakeInstance()->GetHomeOutputDirectory())
+  , Backtraces(this->TopSource)
 {
 {
 }
 }
 
 
@@ -821,9 +825,18 @@ Json::Value DirectoryObject::Dump()
 {
 {
   Json::Value directoryObject = Json::objectValue;
   Json::Value directoryObject = Json::objectValue;
   directoryObject["paths"] = this->DumpPaths();
   directoryObject["paths"] = this->DumpPaths();
+  directoryObject["backtraceGraph"] = this->Backtraces.Dump();
   return directoryObject;
   return directoryObject;
 }
 }
 
 
+void DirectoryObject::AddBacktrace(Json::Value& object,
+                                   cmListFileBacktrace const& bt)
+{
+  if (JBTIndex backtrace = this->Backtraces.Add(bt)) {
+    object["backtrace"] = backtrace.Index;
+  }
+}
+
 Json::Value DirectoryObject::DumpPaths()
 Json::Value DirectoryObject::DumpPaths()
 {
 {
   Json::Value paths = Json::objectValue;
   Json::Value paths = Json::objectValue;

+ 3 - 1
Tests/RunCMake/FileAPI/codemodel-v2-check.py

@@ -98,11 +98,13 @@ def check_directory(c):
             d = json.load(f)
             d = json.load(f)
 
 
         assert is_dict(d)
         assert is_dict(d)
-        assert sorted(d.keys()) == ["paths"]
+        assert sorted(d.keys()) == ["backtraceGraph", "paths"]
 
 
         assert is_string(d["paths"]["source"], actual["source"])
         assert is_string(d["paths"]["source"], actual["source"])
         assert is_string(d["paths"]["build"], actual["build"])
         assert is_string(d["paths"]["build"], actual["build"])
 
 
+        check_backtrace_graph(d["backtraceGraph"])
+
     return _check
     return _check
 
 
 def check_backtrace_graph(btg):
 def check_backtrace_graph(btg):