fileapi: Re-organize backtrace infrastructure

Make it available to more parts of the codemodel object.
This commit is contained in:
Brad King
2021-01-11 09:17:05 -05:00
parent 415ead8153
commit fd30bd93e6
3 changed files with 121 additions and 114 deletions

View File

@@ -964,40 +964,48 @@ with members:
with forward slashes.
``backtraceGraph``
A JSON object describing the graph of backtraces whose nodes are
referenced from ``backtrace`` members elsewhere. The members are:
A `"codemodel" version 2 "backtrace graph"`_ whose nodes are referenced
from ``backtrace`` members elsewhere in this "target" object.
``nodes``
A JSON array listing nodes in the backtrace graph. Each entry
is a JSON object with members:
"codemodel" version 2 "backtrace graph"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``file``
An unsigned integer 0-based index into the backtrace ``files`` array.
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:
``line``
An optional member present when the node represents a line within
the file. The value is an unsigned integer 1-based line number.
``nodes``
A JSON array listing nodes in the backtrace graph. Each entry
is a JSON object with members:
``command``
An optional member present when the node represents a command
invocation within the file. The value is an unsigned integer
0-based index into the backtrace ``commands`` array.
``file``
An unsigned integer 0-based index into the backtrace ``files`` array.
``parent``
An optional member present when the node is not the bottom of
the call stack. The value is an unsigned integer 0-based index
of another entry in the backtrace ``nodes`` array.
``line``
An optional member present when the node represents a line within
the file. The value is an unsigned integer 1-based line number.
``commands``
A JSON array listing command names referenced by backtrace nodes.
Each entry is a string specifying a command name.
``command``
An optional member present when the node represents a command
invocation within the file. The value is an unsigned integer
0-based index into the backtrace ``commands`` array.
``files``
A JSON array listing CMake language files referenced by backtrace nodes.
Each entry is a string specifying the path to a file, represented
with forward slashes. If the file is inside the top-level source
directory then the path is specified relative to that directory.
Otherwise the path is absolute.
``parent``
An optional member present when the node is not the bottom of
the call stack. The value is an unsigned integer 0-based index
of another entry in the backtrace ``nodes`` array.
``commands``
A JSON array listing command names referenced by backtrace nodes.
Each entry is a string specifying a command name.
``files``
A JSON array listing CMake language files referenced by backtrace nodes.
Each entry is a string specifying the path to a file, represented
with forward slashes. If the file is inside the top-level source
directory then the path is specified relative to that directory.
Otherwise the path is absolute.
Object Kind "cache"
-------------------

View File

@@ -49,80 +49,6 @@ namespace {
using TargetIndexMapType =
std::unordered_map<cmGeneratorTarget const*, Json::ArrayIndex>;
class Codemodel
{
cmFileAPI& FileAPI;
unsigned long Version;
Json::Value DumpPaths();
Json::Value DumpConfigurations();
Json::Value DumpConfiguration(std::string const& config);
public:
Codemodel(cmFileAPI& fileAPI, unsigned long version);
Json::Value Dump();
};
class CodemodelConfig
{
cmFileAPI& FileAPI;
unsigned long Version;
std::string const& Config;
std::string TopSource;
std::string TopBuild;
struct Directory
{
cmStateSnapshot Snapshot;
cmLocalGenerator const* LocalGenerator = nullptr;
Json::Value TargetIndexes = Json::arrayValue;
Json::ArrayIndex ProjectIndex;
bool HasInstallRule = false;
};
std::map<cmStateSnapshot, Json::ArrayIndex, cmStateSnapshot::StrictWeakOrder>
DirectoryMap;
std::vector<Directory> Directories;
struct Project
{
cmStateSnapshot Snapshot;
static const Json::ArrayIndex NoParentIndex =
static_cast<Json::ArrayIndex>(-1);
Json::ArrayIndex ParentIndex = NoParentIndex;
Json::Value ChildIndexes = Json::arrayValue;
Json::Value DirectoryIndexes = Json::arrayValue;
Json::Value TargetIndexes = Json::arrayValue;
};
std::map<cmStateSnapshot, Json::ArrayIndex, cmStateSnapshot::StrictWeakOrder>
ProjectMap;
std::vector<Project> Projects;
TargetIndexMapType TargetIndexMap;
void ProcessDirectories();
Json::ArrayIndex GetDirectoryIndex(cmLocalGenerator const* lg);
Json::ArrayIndex GetDirectoryIndex(cmStateSnapshot s);
Json::ArrayIndex AddProject(cmStateSnapshot s);
Json::Value DumpTargets();
Json::Value DumpTarget(cmGeneratorTarget* gt, Json::ArrayIndex ti);
Json::Value DumpDirectories();
Json::Value DumpDirectory(Directory& d);
Json::Value DumpProjects();
Json::Value DumpProject(Project& p);
Json::Value DumpMinimumCMakeVersion(cmStateSnapshot s);
public:
CodemodelConfig(cmFileAPI& fileAPI, unsigned long version,
std::string const& config);
Json::Value Dump();
};
std::string RelativeIfUnder(std::string const& top, std::string const& in)
{
std::string out;
@@ -136,16 +62,6 @@ std::string RelativeIfUnder(std::string const& top, std::string const& in)
return out;
}
std::string TargetId(cmGeneratorTarget const* gt, std::string const& topBuild)
{
cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_256);
std::string path = RelativeIfUnder(
topBuild, gt->GetLocalGenerator()->GetCurrentBinaryDirectory());
std::string hash = hasher.HashString(path);
hash.resize(20, '0');
return gt->GetName() + CMAKE_DIRECTORY_ID_SEP + hash;
}
class JBTIndex
{
public:
@@ -295,6 +211,90 @@ Json::Value BacktraceData::Dump()
return backtraceGraph;
}
class Codemodel
{
cmFileAPI& FileAPI;
unsigned long Version;
Json::Value DumpPaths();
Json::Value DumpConfigurations();
Json::Value DumpConfiguration(std::string const& config);
public:
Codemodel(cmFileAPI& fileAPI, unsigned long version);
Json::Value Dump();
};
class CodemodelConfig
{
cmFileAPI& FileAPI;
unsigned long Version;
std::string const& Config;
std::string TopSource;
std::string TopBuild;
struct Directory
{
cmStateSnapshot Snapshot;
cmLocalGenerator const* LocalGenerator = nullptr;
Json::Value TargetIndexes = Json::arrayValue;
Json::ArrayIndex ProjectIndex;
bool HasInstallRule = false;
};
std::map<cmStateSnapshot, Json::ArrayIndex, cmStateSnapshot::StrictWeakOrder>
DirectoryMap;
std::vector<Directory> Directories;
struct Project
{
cmStateSnapshot Snapshot;
static const Json::ArrayIndex NoParentIndex =
static_cast<Json::ArrayIndex>(-1);
Json::ArrayIndex ParentIndex = NoParentIndex;
Json::Value ChildIndexes = Json::arrayValue;
Json::Value DirectoryIndexes = Json::arrayValue;
Json::Value TargetIndexes = Json::arrayValue;
};
std::map<cmStateSnapshot, Json::ArrayIndex, cmStateSnapshot::StrictWeakOrder>
ProjectMap;
std::vector<Project> Projects;
TargetIndexMapType TargetIndexMap;
void ProcessDirectories();
Json::ArrayIndex GetDirectoryIndex(cmLocalGenerator const* lg);
Json::ArrayIndex GetDirectoryIndex(cmStateSnapshot s);
Json::ArrayIndex AddProject(cmStateSnapshot s);
Json::Value DumpTargets();
Json::Value DumpTarget(cmGeneratorTarget* gt, Json::ArrayIndex ti);
Json::Value DumpDirectories();
Json::Value DumpDirectory(Directory& d);
Json::Value DumpProjects();
Json::Value DumpProject(Project& p);
Json::Value DumpMinimumCMakeVersion(cmStateSnapshot s);
public:
CodemodelConfig(cmFileAPI& fileAPI, unsigned long version,
std::string const& config);
Json::Value Dump();
};
std::string TargetId(cmGeneratorTarget const* gt, std::string const& topBuild)
{
cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_256);
std::string path = RelativeIfUnder(
topBuild, gt->GetLocalGenerator()->GetCurrentBinaryDirectory());
std::string hash = hasher.HashString(path);
hash.resize(20, '0');
return gt->GetName() + CMAKE_DIRECTORY_ID_SEP + hash;
}
struct CompileData
{
struct IncludeEntry

View File

@@ -94,8 +94,7 @@ def check_directory(c):
return _check
def check_target_backtrace_graph(t):
btg = t["backtraceGraph"]
def check_backtrace_graph(btg):
assert is_dict(btg)
assert sorted(btg.keys()) == ["commands", "files", "nodes"]
assert is_list(btg["commands"])
@@ -148,7 +147,7 @@ def check_target(c):
assert is_string(obj["name"], expected["name"])
assert matches(obj["id"], expected["id"])
assert is_string(obj["type"], expected["type"])
check_target_backtrace_graph(obj)
check_backtrace_graph(obj["backtraceGraph"])
assert is_dict(obj["paths"])
assert sorted(obj["paths"].keys()) == ["build", "source"]