summaryrefslogtreecommitdiffstats
path: root/Source/cmFileAPICodemodel.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-01-14 20:10:49 (GMT)
committerBrad King <brad.king@kitware.com>2021-03-16 20:47:43 (GMT)
commita12d7f70b1b97f74293d9861a1827c88ef46ec39 (patch)
treecc6e798f5ad63468679ef7a3abcb21438173d12a /Source/cmFileAPICodemodel.cxx
parentfd30bd93e6f4334a9cd317a1e5eb8181fffa7a42 (diff)
downloadCMake-a12d7f70b1b97f74293d9861a1827c88ef46ec39.zip
CMake-a12d7f70b1b97f74293d9861a1827c88ef46ec39.tar.gz
CMake-a12d7f70b1b97f74293d9861a1827c88ef46ec39.tar.bz2
fileapi: Add a "directory" object to codemodel-v2
This object will contain more detailed directory-level information. Co-Authored-by: Kyle Edwards <kyle.edwards@kitware.com>
Diffstat (limited to 'Source/cmFileAPICodemodel.cxx')
-rw-r--r--Source/cmFileAPICodemodel.cxx72
1 files changed, 71 insertions, 1 deletions
diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx
index ed6ac8e..2f36db2 100644
--- a/Source/cmFileAPICodemodel.cxx
+++ b/Source/cmFileAPICodemodel.cxx
@@ -273,6 +273,7 @@ class CodemodelConfig
Json::Value DumpDirectories();
Json::Value DumpDirectory(Directory& d);
+ Json::Value DumpDirectoryObject(Directory& d);
Json::Value DumpProjects();
Json::Value DumpProject(Project& p);
@@ -372,6 +373,20 @@ struct hash<CompileData>
} // namespace std
namespace {
+class DirectoryObject
+{
+ cmLocalGenerator const* LG = nullptr;
+ std::string const& Config;
+ std::string TopSource;
+ std::string TopBuild;
+
+ Json::Value DumpPaths();
+
+public:
+ DirectoryObject(cmLocalGenerator const* lg, std::string const& config);
+ Json::Value Dump();
+};
+
class Target
{
cmGeneratorTarget* GT;
@@ -684,7 +699,7 @@ Json::Value CodemodelConfig::DumpDirectories()
Json::Value CodemodelConfig::DumpDirectory(Directory& d)
{
- Json::Value directory = Json::objectValue;
+ Json::Value directory = this->DumpDirectoryObject(d);
std::string sourceDir = d.Snapshot.GetDirectory().GetCurrentSource();
directory["source"] = RelativeIfUnder(this->TopSource, sourceDir);
@@ -724,6 +739,31 @@ Json::Value CodemodelConfig::DumpDirectory(Directory& d)
return directory;
}
+Json::Value CodemodelConfig::DumpDirectoryObject(Directory& d)
+{
+ std::string prefix = "directory";
+ std::string sourceDirRel = RelativeIfUnder(
+ this->TopSource, d.Snapshot.GetDirectory().GetCurrentSource());
+ std::string buildDirRel = RelativeIfUnder(
+ this->TopBuild, d.Snapshot.GetDirectory().GetCurrentBinary());
+ if (!cmSystemTools::FileIsFullPath(buildDirRel)) {
+ prefix = cmStrCat(prefix, '-', buildDirRel);
+ } else if (!cmSystemTools::FileIsFullPath(sourceDirRel)) {
+ prefix = cmStrCat(prefix, '-', sourceDirRel);
+ }
+ for (char& c : prefix) {
+ if (c == '/' || c == '\\') {
+ c = '.';
+ }
+ }
+ if (!this->Config.empty()) {
+ prefix += "-" + this->Config;
+ }
+
+ DirectoryObject dir(d.LocalGenerator, this->Config);
+ return this->FileAPI.MaybeJsonFile(dir.Dump(), prefix);
+}
+
Json::Value CodemodelConfig::DumpProjects()
{
Json::Value projects = Json::arrayValue;
@@ -767,6 +807,36 @@ Json::Value CodemodelConfig::DumpMinimumCMakeVersion(cmStateSnapshot s)
return minimumCMakeVersion;
}
+DirectoryObject::DirectoryObject(cmLocalGenerator const* lg,
+ std::string const& config)
+ : LG(lg)
+ , Config(config)
+ , TopSource(lg->GetGlobalGenerator()->GetCMakeInstance()->GetHomeDirectory())
+ , TopBuild(
+ lg->GetGlobalGenerator()->GetCMakeInstance()->GetHomeOutputDirectory())
+{
+}
+
+Json::Value DirectoryObject::Dump()
+{
+ Json::Value directoryObject = Json::objectValue;
+ directoryObject["paths"] = this->DumpPaths();
+ return directoryObject;
+}
+
+Json::Value DirectoryObject::DumpPaths()
+{
+ Json::Value paths = Json::objectValue;
+
+ std::string const& sourceDir = this->LG->GetCurrentSourceDirectory();
+ paths["source"] = RelativeIfUnder(this->TopSource, sourceDir);
+
+ std::string const& buildDir = this->LG->GetCurrentBinaryDirectory();
+ paths["build"] = RelativeIfUnder(this->TopBuild, buildDir);
+
+ return paths;
+}
+
Target::Target(cmGeneratorTarget* gt, std::string const& config)
: GT(gt)
, Config(config)